Fix broken geometry

This commit is contained in:
Victor Shcherb 2020-05-16 21:28:00 +02:00
parent 0d96394a0e
commit a01a4ad63e
2 changed files with 32 additions and 23 deletions

View file

@ -36,6 +36,7 @@ public class TransportRoutePlanner {
private static final boolean MEASURE_TIME = false; private static final boolean MEASURE_TIME = false;
private static final int MISSING_STOP_SEARCH_RADIUS = 15000; private static final int MISSING_STOP_SEARCH_RADIUS = 15000;
private static final int MIN_DIST_STOP_TO_GEOMETRY = 150;
public static final long GEOMETRY_WAY_ID = -1; public static final long GEOMETRY_WAY_ID = -1;
public static final long STOPS_WAY_ID = -2; public static final long STOPS_WAY_ID = -2;
@ -381,8 +382,7 @@ public class TransportRoutePlanner {
} }
public List<Way> getGeometry() { public List<Way> getGeometry() {
List<Way> list = new ArrayList<>(); route.mergeForwardWays();
route.mergeForwardWays(); //TODO merge ways of all Route parts
if (DISPLAY_FULL_SEGMENT_ROUTE) { if (DISPLAY_FULL_SEGMENT_ROUTE) {
System.out.println("TOTAL SEGMENTS: " + route.getForwardWays().size()); System.out.println("TOTAL SEGMENTS: " + route.getForwardWays().size());
if (route.getForwardWays().size() > DISPLAY_SEGMENT_IND) { if (route.getForwardWays().size() > DISPLAY_SEGMENT_IND) {
@ -390,30 +390,40 @@ public class TransportRoutePlanner {
} }
return route.getForwardWays(); return route.getForwardWays();
} }
List<Way> fw = route.getForwardWays(); List<Way> ways = route.getForwardWays();
double minStart = 150;
double minEnd = 150; final LatLon startLoc = getStart().getLocation();
LatLon str = getStart().getLocation(); final LatLon endLoc = getEnd().getLocation();
LatLon en = getEnd().getLocation();
int endInd = -1; List<Node> finalr = Collections.emptyList();
int fendInd = -1;
double fminStartDist = MIN_DIST_STOP_TO_GEOMETRY;
for (int i = 0; i < ways.size() ; i++) {
List<Node> nodes = ways.get(i).getNodes();
List<Node> res = new ArrayList<>(); List<Node> res = new ArrayList<>();
for (int i = 0; i < fw.size() ; i++) { double minStartDist = MIN_DIST_STOP_TO_GEOMETRY;
List<Node> nodes = fw.get(i).getNodes(); double minDistEnd = MIN_DIST_STOP_TO_GEOMETRY;
int endInd = -1;
for (int j = 0; j < nodes.size(); j++) { for (int j = 0; j < nodes.size(); j++) {
Node n = nodes.get(j); Node n = nodes.get(j);
if (MapUtils.getDistance(str, n.getLatitude(), n.getLongitude()) < minStart) { if (MapUtils.getDistance(startLoc, n.getLatitude(), n.getLongitude()) < minStartDist) {
minStart = MapUtils.getDistance(str, n.getLatitude(), n.getLongitude()); minStartDist = MapUtils.getDistance(startLoc, n.getLatitude(), n.getLongitude());
res.clear(); res.clear();
} }
res.add(n); res.add(n);
if (MapUtils.getDistance(en, n.getLatitude(), n.getLongitude()) < minEnd) { if (MapUtils.getDistance(endLoc, n.getLatitude(), n.getLongitude()) < minDistEnd) {
endInd = res.size(); endInd = res.size();
minEnd = MapUtils.getDistance(en, n.getLatitude(), n.getLongitude()); minDistEnd = MapUtils.getDistance(endLoc, n.getLatitude(), n.getLongitude());
} }
} }
if(endInd != -1 && res.size() > 0 && minStartDist < fminStartDist) {
finalr = res;
fendInd = endInd;
fminStartDist = minStartDist;
}
} }
Way way; Way way;
if (res.isEmpty() || endInd == -1) { if (finalr.isEmpty() || fendInd == -1) {
way = new Way(STOPS_WAY_ID); way = new Way(STOPS_WAY_ID);
for (int i = start; i <= end; i++) { for (int i = start; i <= end; i++) {
LatLon l = getStop(i).getLocation(); LatLon l = getStop(i).getLocation();
@ -422,12 +432,11 @@ public class TransportRoutePlanner {
} }
} else { } else {
way = new Way(GEOMETRY_WAY_ID); way = new Way(GEOMETRY_WAY_ID);
for(int k = 0; k < res.size() && k < endInd; k++) { for(int k = 0; k < finalr.size() && k < fendInd; k++) {
way.addNode(res.get(k)); way.addNode(finalr.get(k));
} }
} }
list.add(way); return Collections.singletonList(way);
return list;
} }
public double getTravelDist() { public double getTravelDist() {