Fix route to gpx issues
This commit is contained in:
parent
f26f57f97d
commit
b7a6d89b18
3 changed files with 93 additions and 65 deletions
|
@ -271,7 +271,7 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
|
|||
bundle.putString("turnLanes", TurnType.lanesToString(turnLanes));
|
||||
}
|
||||
}
|
||||
bundle.putLong("id", object.id);
|
||||
bundle.putLong("id", object.id >> 6); // OsmAnd ID to OSM ID
|
||||
bundle.putArray("types", convertTypes(object.types, rules));
|
||||
|
||||
int start = Math.min(startPointIndex, endPointIndex);
|
||||
|
@ -327,22 +327,21 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
|
|||
Location prevLocation = null;
|
||||
for (int i = 0; i < length; i++) {
|
||||
Location location = resources.getLocation(index);
|
||||
if (location == null) {
|
||||
continue;
|
||||
}
|
||||
double dist = 0;
|
||||
if (prevLocation != null) {
|
||||
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());
|
||||
if (location.hasAltitude() && object.heightDistanceArray.length > 0) {
|
||||
object.heightDistanceArray[i * 2] = (float) dist;
|
||||
object.heightDistanceArray[i * 2 + 1] = (float) location.getAltitude();
|
||||
} else {
|
||||
object.heightDistanceArray = new float[0];
|
||||
if (location != null) {
|
||||
double dist = 0;
|
||||
if (prevLocation != null) {
|
||||
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());
|
||||
if (location.hasAltitude() && object.heightDistanceArray.length > 0) {
|
||||
object.heightDistanceArray[i * 2] = (float) dist;
|
||||
object.heightDistanceArray[i * 2 + 1] = (float) location.getAltitude();
|
||||
} else {
|
||||
object.heightDistanceArray = new float[0];
|
||||
}
|
||||
}
|
||||
if (plus) {
|
||||
index++;
|
||||
|
|
|
@ -517,47 +517,90 @@ public class MeasurementEditingContext {
|
|||
roadSegmentData.clear();
|
||||
List<WptPt> routePoints = new ArrayList<>();
|
||||
List<GpxPoint> gpxPoints = gpxApproximation.finalPoints;
|
||||
for (int i = 0; i < gpxPoints.size() - 1; i++) {
|
||||
GpxPoint rp1 = gpxPoints.get(i);
|
||||
GpxPoint rp2 = gpxPoints.get(i + 1);
|
||||
WptPt p1 = new WptPt();
|
||||
p1.lat = rp1.loc.getLatitude();
|
||||
p1.lon = rp1.loc.getLongitude();
|
||||
p1.setProfileType(mode.getStringKey());
|
||||
if (i == 0) {
|
||||
routePoints.add(p1);
|
||||
}
|
||||
WptPt p2 = new WptPt();
|
||||
p2.lat = rp2.loc.getLatitude();
|
||||
p2.lon = rp2.loc.getLongitude();
|
||||
p2.setProfileType(mode.getStringKey());
|
||||
routePoints.add(p2);
|
||||
Pair<WptPt, WptPt> pair = new Pair<>(p1, p2);
|
||||
for (int i = 0; i < gpxPoints.size(); i++) {
|
||||
GpxPoint gp1 = gpxPoints.get(i);
|
||||
boolean lastGpxPoint = isLastGpxPoint(gpxPoints, i);
|
||||
List<WptPt> points = new ArrayList<>();
|
||||
List<RouteSegmentResult> segments = new ArrayList<>();
|
||||
for (RouteSegmentResult seg : rp1.routeToTarget) {
|
||||
segments.add(seg);
|
||||
int ind = seg.getStartPointIndex();
|
||||
boolean plus = seg.isForwardDirection();
|
||||
float[] pf = seg.getObject().calculateHeightArray();
|
||||
while (ind != seg.getEndPointIndex()) {
|
||||
LatLon l = seg.getPoint(ind);
|
||||
WptPt pt = new WptPt();
|
||||
if (pf != null && pf.length > ind * 2 + 1) {
|
||||
pt.ele = pf[ind * 2 + 1];
|
||||
|
||||
}
|
||||
pt.lat = l.getLatitude();
|
||||
pt.lon = l.getLongitude();
|
||||
points.add(pt);
|
||||
ind = plus ? ind + 1 : ind - 1;
|
||||
for (int k = 0; k < gp1.routeToTarget.size(); k++) {
|
||||
RouteSegmentResult seg = gp1.routeToTarget.get(k);
|
||||
if (seg.getStartPointIndex() != seg.getEndPointIndex()) {
|
||||
segments.add(seg);
|
||||
}
|
||||
}
|
||||
roadSegmentData.put(pair, new RoadSegmentData(appMode, pair.first, pair.second, points, segments));
|
||||
for (int k = 0; k < segments.size(); k++) {
|
||||
RouteSegmentResult seg = segments.get(k);
|
||||
fillPointsArray(points, seg, lastGpxPoint && k == segments.size() - 1);
|
||||
}
|
||||
if (!points.isEmpty()) {
|
||||
WptPt wp1 = new WptPt();
|
||||
wp1.lat = gp1.loc.getLatitude();
|
||||
wp1.lon = gp1.loc.getLongitude();
|
||||
wp1.setProfileType(mode.getStringKey());
|
||||
routePoints.add(wp1);
|
||||
WptPt wp2 = new WptPt();
|
||||
if (lastGpxPoint) {
|
||||
wp2.lat = points.get(points.size() - 1).getLatitude();
|
||||
wp2.lon = points.get(points.size() - 1).getLongitude();
|
||||
routePoints.add(wp2);
|
||||
} else {
|
||||
GpxPoint gp2 = gpxPoints.get(i + 1);
|
||||
wp2.lat = gp2.loc.getLatitude();
|
||||
wp2.lon = gp2.loc.getLongitude();
|
||||
}
|
||||
wp2.setProfileType(mode.getStringKey());
|
||||
Pair<WptPt, WptPt> pair = new Pair<>(wp1, wp2);
|
||||
roadSegmentData.put(pair, new RoadSegmentData(appMode, pair.first, pair.second, points, segments));
|
||||
}
|
||||
if (lastGpxPoint) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
addPoints(routePoints);
|
||||
}
|
||||
|
||||
private boolean isLastGpxPoint(List<GpxPoint> gpxPoints, int index) {
|
||||
if (index == gpxPoints.size() - 1) {
|
||||
return true;
|
||||
} else {
|
||||
for (int i = index + 1; i < gpxPoints.size(); i++) {
|
||||
GpxPoint gp = gpxPoints.get(i);
|
||||
for (int k = 0; k < gp.routeToTarget.size(); k++) {
|
||||
RouteSegmentResult seg = gp.routeToTarget.get(k);
|
||||
if (seg.getStartPointIndex() != seg.getEndPointIndex()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void fillPointsArray(List<WptPt> points, RouteSegmentResult seg, boolean includeEndPoint) {
|
||||
int ind = seg.getStartPointIndex();
|
||||
boolean plus = seg.isForwardDirection();
|
||||
float[] heightArray = seg.getObject().calculateHeightArray();
|
||||
while (ind != seg.getEndPointIndex()) {
|
||||
addPointToArray(points, seg, ind, heightArray);
|
||||
ind = plus ? ind + 1 : ind - 1;
|
||||
}
|
||||
if (includeEndPoint) {
|
||||
addPointToArray(points, seg, ind, heightArray);
|
||||
}
|
||||
}
|
||||
|
||||
private void addPointToArray(List<WptPt> points, RouteSegmentResult seg, int index, float[] heightArray) {
|
||||
LatLon l = seg.getPoint(index);
|
||||
WptPt pt = new WptPt();
|
||||
if (heightArray != null && heightArray.length > index * 2 + 1) {
|
||||
pt.ele = heightArray[index * 2 + 1];
|
||||
}
|
||||
pt.lat = l.getLatitude();
|
||||
pt.lon = l.getLongitude();
|
||||
points.add(pt);
|
||||
}
|
||||
|
||||
private int findPointIndex(WptPt point, List<WptPt> points, int firstIndex) {
|
||||
double minDistance = Double.MAX_VALUE;
|
||||
int index = 0;
|
||||
|
@ -740,10 +783,7 @@ public class MeasurementEditingContext {
|
|||
}
|
||||
locations.add(l);
|
||||
}
|
||||
pair.second.setTrkPtIndex(locations.size() - 1);
|
||||
if (i < size - 2 && !locations.isEmpty()) {
|
||||
locations.remove(locations.size() - 1);
|
||||
}
|
||||
pair.second.setTrkPtIndex(i < size - 1 ? locations.size() : locations.size() - 1);
|
||||
route.addAll(data.segments);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -356,17 +356,6 @@ public class RouteCalculationResult {
|
|||
}
|
||||
lastHeight = h;
|
||||
}
|
||||
// FIXME: investigate gpx file
|
||||
if (s.getObject().getPoint31XTile(i) == 0 && s.getObject().getPoint31YTile(i) == 0) {
|
||||
if (locations.size() > 0) {
|
||||
Location prev = locations.get(locations.size() - 1);
|
||||
n.setLatitude(prev.getLatitude());
|
||||
n.setLongitude(prev.getLongitude());
|
||||
if (prev.hasAltitude()) {
|
||||
n.setAltitude(prev.getAltitude());
|
||||
}
|
||||
}
|
||||
}
|
||||
locations.add(n);
|
||||
attachAlarmInfo(alarms, s, i, locations.size());
|
||||
segmentsToPopulate.add(s);
|
||||
|
|
Loading…
Reference in a new issue