Skip to content
Snippets Groups Projects

fix-return-coordinates

Merged yolas01 requested to merge fix-return-coordinates into main
1 file
+ 18
0
Compare changes
  • Side-by-side
  • Inline
@@ -2,6 +2,7 @@ package de.fuberlin.navigator.routingserver.utility;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
@@ -263,6 +264,23 @@ public class ApplyShortestPath {
Segment segment = roadnetwork.getSegmentsMap().get(edge.getId());
List<Coordinates> geometryList= segment.getGeometryList();
// handle reversed edges (the edges that are added if the street is no oneway)
// find right geometryList order by calculating distance between last element of coordinateList and geometryList
Point last = coordinateList.get(coordinateList.size() - 1);
Coordinates firstGeometry = geometryList.get(0);
Coordinates lastGeometry = geometryList.get(geometryList.size() -1);
int distanceToFirst = GeoUtils.haversine((float)last.getLat(), (float)last.getLon(), firstGeometry.getLat(), firstGeometry.getLon());
int distanceToLast = GeoUtils.haversine((float)last.getLat(), (float)last.getLon(), lastGeometry.getLat(), lastGeometry.getLon());
if(distanceToLast < distanceToFirst){
//reverse geometryList
List<Coordinates> tempList = new ArrayList<Coordinates>(geometryList);
Collections.reverse(tempList);
geometryList = tempList;
}
for(Coordinates coordinates : geometryList){
coordinateList.add(new Point(coordinates.getLat(), coordinates.getLon()));
}
Loading