Remove elevation tags from gpx
This commit is contained in:
parent
056468be1b
commit
5335d7c3e0
3 changed files with 32 additions and 47 deletions
|
@ -11,7 +11,6 @@ import java.util.Map;
|
||||||
public class RouteDataResources {
|
public class RouteDataResources {
|
||||||
|
|
||||||
private Map<RouteTypeRule, Integer> rules = new LinkedHashMap<>();
|
private Map<RouteTypeRule, Integer> rules = new LinkedHashMap<>();
|
||||||
private Map<RouteSegmentResult, Map<RouteTypeRule, RouteTypeRule>> segmentRules = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
private List<Location> locations;
|
private List<Location> locations;
|
||||||
private int currentLocation;
|
private int currentLocation;
|
||||||
|
@ -28,15 +27,6 @@ public class RouteDataResources {
|
||||||
return rules;
|
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() {
|
public List<Location> getLocations() {
|
||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,11 @@ public class RouteImporter {
|
||||||
List<Location> locations = resources.getLocations();
|
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) {
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,8 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
|
||||||
|
|
||||||
void collectTypes(RouteDataResources resources) {
|
void collectTypes(RouteDataResources resources) {
|
||||||
Map<RouteTypeRule, Integer> rules = resources.getRules();
|
Map<RouteTypeRule, Integer> rules = resources.getRules();
|
||||||
Map<RouteTypeRule, RouteTypeRule> segmentRules = resources.getSegmentRules(this);
|
|
||||||
if (object.types != null) {
|
if (object.types != null) {
|
||||||
collectRules(rules, segmentRules, object.types);
|
collectRules(rules, object.types);
|
||||||
}
|
}
|
||||||
if (object.pointTypes != null) {
|
if (object.pointTypes != null) {
|
||||||
int start = Math.min(startPointIndex, endPointIndex);
|
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++) {
|
for (int i = start; i <= end && i < object.pointTypes.length; i++) {
|
||||||
int[] types = object.pointTypes[i];
|
int[] types = object.pointTypes[i];
|
||||||
if (types != null) {
|
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;
|
RouteRegion region = object.region;
|
||||||
for (int type : types) {
|
for (int type : types) {
|
||||||
RouteTypeRule rule = region.quickGetEncodingRule(type);
|
RouteTypeRule rule = region.quickGetEncodingRule(type);
|
||||||
RouteTypeRule segmentRule = null;
|
|
||||||
String tag = rule.getTag();
|
String tag = rule.getTag();
|
||||||
if (tag.equals("osmand_ele_start")) {
|
if (tag.equals("osmand_ele_start") || tag.equals("osmand_ele_end")
|
||||||
if (object.heightDistanceArray != null && object.heightDistanceArray.length > startPointIndex * 2 + 1) {
|
|| tag.equals("osmand_ele_asc") || tag.equals("osmand_ele_desc"))
|
||||||
float h = object.heightDistanceArray[startPointIndex * 2 + 1];
|
{
|
||||||
segmentRule = new RouteTypeRule(tag, String.valueOf(Math.round(h)));
|
continue;
|
||||||
}
|
|
||||||
} 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 (segmentRule != null) {
|
if (!rules.containsKey(rule)) {
|
||||||
segmentRules.put(rule, segmentRule);
|
|
||||||
} else if (!rules.containsKey(rule)) {
|
|
||||||
rules.put(rule, rules.size());
|
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) {
|
if (types == null || types.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int[] res = new int[types.length];
|
List<Integer> arr = new ArrayList<>();
|
||||||
for (int i = 0; i < types.length; i++) {
|
for (int i = 0; i < types.length; i++) {
|
||||||
int type = types[i];
|
int type = types[i];
|
||||||
RouteTypeRule rule = object.region.quickGetEncodingRule(type);
|
RouteTypeRule rule = object.region.quickGetEncodingRule(type);
|
||||||
RouteTypeRule segmentRule = segmentRules.get(rule);
|
Integer ruleId = rules.get(rule);
|
||||||
if (segmentRule != null) {
|
if (ruleId != null) {
|
||||||
res[i] = rules.size();
|
arr.add(ruleId);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int[] res = new int[arr.size()];
|
||||||
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
|
res[i] = arr.get(i);
|
||||||
|
}
|
||||||
return res;
|
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) {
|
if (types == null || types.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +133,7 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
|
||||||
for (int i = 0; i < types.length; i++) {
|
for (int i = 0; i < types.length; i++) {
|
||||||
int[] typesArr = types[i];
|
int[] typesArr = types[i];
|
||||||
if (typesArr != null) {
|
if (typesArr != null) {
|
||||||
res[i] = convertTypes(typesArr, rules, segmentRules);
|
res[i] = convertTypes(typesArr, rules);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -194,7 +181,6 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
|
||||||
@Override
|
@Override
|
||||||
public void writeToBundle(RouteDataBundle bundle) {
|
public void writeToBundle(RouteDataBundle bundle) {
|
||||||
Map<RouteTypeRule, Integer> rules = bundle.getResources().getRules();
|
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.putInt("length", (Math.abs(endPointIndex - startPointIndex) + 1) * (endPointIndex >= startPointIndex ? 1 : -1));
|
||||||
bundle.putFloat("segmentTime", segmentTime, 2);
|
bundle.putFloat("segmentTime", segmentTime, 2);
|
||||||
bundle.putFloat("speed", speed, 2);
|
bundle.putFloat("speed", speed, 2);
|
||||||
|
@ -212,11 +198,11 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bundle.putLong("id", object.id);
|
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 start = Math.min(startPointIndex, endPointIndex);
|
||||||
int end = Math.max(startPointIndex, endPointIndex);
|
int end = Math.max(startPointIndex, endPointIndex);
|
||||||
bundle.putArray("pointTypes", convertTypes(Arrays.copyOfRange(object.pointTypes, start,
|
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));
|
bundle.putArray("names", convertNameIds(object.nameIds, rules));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,17 +231,22 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
|
||||||
RouteDataResources resources = bundle.getResources();
|
RouteDataResources resources = bundle.getResources();
|
||||||
object.pointsX = new int[length];
|
object.pointsX = new int[length];
|
||||||
object.pointsY = new int[length];
|
object.pointsY = new int[length];
|
||||||
|
object.heightDistanceArray = new float[length * 2];
|
||||||
int index = plus ? 0 : length - 1;
|
int index = plus ? 0 : length - 1;
|
||||||
float distance = 0;
|
float distance = 0;
|
||||||
Location prevLocation = null;
|
Location prevLocation = null;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
Location location = resources.getLocation(index);
|
Location location = resources.getLocation(index);
|
||||||
|
double dist = 0;
|
||||||
if (prevLocation != null) {
|
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;
|
prevLocation = location;
|
||||||
object.pointsX[i] = MapUtils.get31TileNumberX(location.getLongitude());
|
object.pointsX[i] = MapUtils.get31TileNumberX(location.getLongitude());
|
||||||
object.pointsY[i] = MapUtils.get31TileNumberY(location.getLatitude());
|
object.pointsY[i] = MapUtils.get31TileNumberY(location.getLatitude());
|
||||||
|
object.heightDistanceArray[i * 2] = (float) dist;
|
||||||
|
object.heightDistanceArray[i * 2 + 1] = (float) location.getAltitude();
|
||||||
if (plus) {
|
if (plus) {
|
||||||
index++;
|
index++;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue