Remove elevation tags from gpx

This commit is contained in:
max-klaus 2020-03-17 22:26:52 +03:00
parent 056468be1b
commit 5335d7c3e0
3 changed files with 32 additions and 47 deletions

View file

@ -11,7 +11,6 @@ import java.util.Map;
public class RouteDataResources {
private Map<RouteTypeRule, Integer> rules = new LinkedHashMap<>();
private Map<RouteSegmentResult, Map<RouteTypeRule, RouteTypeRule>> segmentRules = new LinkedHashMap<>();
private List<Location> locations;
private int currentLocation;
@ -28,15 +27,6 @@ public class RouteDataResources {
return rules;
}
public Map<RouteTypeRule, RouteTypeRule> getSegmentRules(RouteSegmentResult segmentResult) {
Map<RouteTypeRule, RouteTypeRule> ruleMap = segmentRules.get(segmentResult);
if (ruleMap == null) {
ruleMap = new LinkedHashMap<>();
segmentRules.put(segmentResult, ruleMap);
}
return ruleMap;
}
public List<Location> getLocations() {
return locations;
}

View file

@ -50,7 +50,11 @@ public class RouteImporter {
List<Location> locations = resources.getLocations();
if (res.tracks.size() > 0 && res.tracks.get(0).segments.size() > 0 && res.tracks.get(0).segments.get(0).points.size() > 0) {
for (WptPt point : res.tracks.get(0).segments.get(0).points) {
locations.add(new Location("", point.getLatitude(), point.getLongitude()));
Location loc = new Location("", point.getLatitude(), point.getLongitude());
if (!Double.isNaN(point.ele)) {
loc.setAltitude(point.ele);
}
locations.add(loc);
}
}
}

View file

@ -47,9 +47,8 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
void collectTypes(RouteDataResources resources) {
Map<RouteTypeRule, Integer> rules = resources.getRules();
Map<RouteTypeRule, RouteTypeRule> segmentRules = resources.getSegmentRules(this);
if (object.types != null) {
collectRules(rules, segmentRules, object.types);
collectRules(rules, object.types);
}
if (object.pointTypes != null) {
int start = Math.min(startPointIndex, endPointIndex);
@ -57,7 +56,7 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
for (int i = start; i <= end && i < object.pointTypes.length; i++) {
int[] types = object.pointTypes[i];
if (types != null) {
collectRules(rules, segmentRules, types);
collectRules(rules, types);
}
}
}
@ -90,55 +89,43 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
}
}
private void collectRules(Map<RouteTypeRule, Integer> rules, Map<RouteTypeRule, RouteTypeRule> segmentRules, int[] types) {
private void collectRules(Map<RouteTypeRule, Integer> rules, int[] types) {
RouteRegion region = object.region;
for (int type : types) {
RouteTypeRule rule = region.quickGetEncodingRule(type);
RouteTypeRule segmentRule = null;
String tag = rule.getTag();
if (tag.equals("osmand_ele_start")) {
if (object.heightDistanceArray != null && object.heightDistanceArray.length > startPointIndex * 2 + 1) {
float h = object.heightDistanceArray[startPointIndex * 2 + 1];
segmentRule = new RouteTypeRule(tag, String.valueOf(Math.round(h)));
}
} else if (tag.equals("osmand_ele_end")) {
if (object.heightDistanceArray != null && object.heightDistanceArray.length > endPointIndex * 2 + 1) {
float h = object.heightDistanceArray[endPointIndex * 2 + 1];
segmentRule = new RouteTypeRule(tag, String.valueOf(Math.round(h)));
}
if (tag.equals("osmand_ele_start") || tag.equals("osmand_ele_end")
|| tag.equals("osmand_ele_asc") || tag.equals("osmand_ele_desc"))
{
continue;
}
if (segmentRule != null) {
segmentRules.put(rule, segmentRule);
} else if (!rules.containsKey(rule)) {
if (!rules.containsKey(rule)) {
rules.put(rule, rules.size());
}
}
}
private int[] convertTypes(int[] types, Map<RouteTypeRule, Integer> rules, Map<RouteTypeRule, RouteTypeRule> segmentRules) {
private int[] convertTypes(int[] types, Map<RouteTypeRule, Integer> rules) {
if (types == null || types.length == 0) {
return null;
}
int[] res = new int[types.length];
List<Integer> arr = new ArrayList<>();
for (int i = 0; i < types.length; i++) {
int type = types[i];
RouteTypeRule rule = object.region.quickGetEncodingRule(type);
RouteTypeRule segmentRule = segmentRules.get(rule);
if (segmentRule != null) {
res[i] = rules.size();
rules.put(segmentRule, rules.size());
} else {
Integer ruleId = rules.get(rule);
if (ruleId == null) {
throw new IllegalArgumentException("Cannot find collected rule: " + rule.toString());
}
res[i] = ruleId;
Integer ruleId = rules.get(rule);
if (ruleId != null) {
arr.add(ruleId);
}
}
int[] res = new int[arr.size()];
for (int i = 0; i < arr.size(); i++) {
res[i] = arr.get(i);
}
return res;
}
private int[][] convertTypes(int[][] types, Map<RouteTypeRule, Integer> rules, Map<RouteTypeRule, RouteTypeRule> segmentRules) {
private int[][] convertTypes(int[][] types, Map<RouteTypeRule, Integer> rules) {
if (types == null || types.length == 0) {
return null;
}
@ -146,7 +133,7 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
for (int i = 0; i < types.length; i++) {
int[] typesArr = types[i];
if (typesArr != null) {
res[i] = convertTypes(typesArr, rules, segmentRules);
res[i] = convertTypes(typesArr, rules);
}
}
return res;
@ -194,7 +181,6 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
@Override
public void writeToBundle(RouteDataBundle bundle) {
Map<RouteTypeRule, Integer> rules = bundle.getResources().getRules();
Map<RouteTypeRule, RouteTypeRule> segmentRules = bundle.getResources().getSegmentRules(this);
bundle.putInt("length", (Math.abs(endPointIndex - startPointIndex) + 1) * (endPointIndex >= startPointIndex ? 1 : -1));
bundle.putFloat("segmentTime", segmentTime, 2);
bundle.putFloat("speed", speed, 2);
@ -212,11 +198,11 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
}
}
bundle.putLong("id", object.id);
bundle.putArray("types", convertTypes(object.types, rules, segmentRules));
bundle.putArray("types", convertTypes(object.types, rules));
int start = Math.min(startPointIndex, endPointIndex);
int end = Math.max(startPointIndex, endPointIndex);
bundle.putArray("pointTypes", convertTypes(Arrays.copyOfRange(object.pointTypes, start,
Math.min(end + 1, object.pointTypes.length)), rules, segmentRules));
Math.min(end + 1, object.pointTypes.length)), rules));
bundle.putArray("names", convertNameIds(object.nameIds, rules));
}
@ -245,17 +231,22 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
RouteDataResources resources = bundle.getResources();
object.pointsX = new int[length];
object.pointsY = new int[length];
object.heightDistanceArray = new float[length * 2];
int index = plus ? 0 : length - 1;
float distance = 0;
Location prevLocation = null;
for (int i = 0; i < length; i++) {
Location location = resources.getLocation(index);
double dist = 0;
if (prevLocation != null) {
distance += MapUtils.getDistance(prevLocation.getLatitude(), prevLocation.getLongitude(), location.getLatitude(), location.getLongitude());
dist = MapUtils.getDistance(prevLocation.getLatitude(), prevLocation.getLongitude(), location.getLatitude(), location.getLongitude());
distance += dist;
}
prevLocation = location;
object.pointsX[i] = MapUtils.get31TileNumberX(location.getLongitude());
object.pointsY[i] = MapUtils.get31TileNumberY(location.getLatitude());
object.heightDistanceArray[i * 2] = (float) dist;
object.heightDistanceArray[i * 2 + 1] = (float) location.getAltitude();
if (plus) {
index++;
} else {