use of com.graphhopper.util.PointList in project graphhopper by graphhopper.
the class MainActivity method createPathLayer.
private PathLayer createPathLayer(PathWrapper response) {
Style style = Style.builder().fixed(true).generalization(Style.GENERALIZATION_SMALL).strokeColor(0x9900cc33).strokeWidth(4 * getResources().getDisplayMetrics().density).build();
PathLayer pathLayer = new PathLayer(mapView.map(), style);
List<GeoPoint> geoPoints = new ArrayList<>();
PointList pointList = response.getPoints();
for (int i = 0; i < pointList.getSize(); i++) geoPoints.add(new GeoPoint(pointList.getLatitude(i), pointList.getLongitude(i)));
pathLayer.setPoints(geoPoints);
return pathLayer;
}
use of com.graphhopper.util.PointList in project graphhopper by graphhopper.
the class AlternativeRoutingTemplate method isReady.
@Override
public boolean isReady(PathMerger pathMerger, Translation tr) {
if (pathList.isEmpty())
throw new RuntimeException("Empty paths for alternative route calculation not expected");
// if alternative route calculation was done then create the responses from single paths
PointList wpList = getWaypoints();
altResponse.setWaypoints(wpList);
ghResponse.add(altResponse);
pathMerger.doWork(altResponse, Collections.singletonList(pathList.get(0)), tr);
for (int index = 1; index < pathList.size(); index++) {
PathWrapper tmpAltRsp = new PathWrapper();
tmpAltRsp.setWaypoints(wpList);
ghResponse.add(tmpAltRsp);
pathMerger.doWork(tmpAltRsp, Collections.singletonList(pathList.get(index)), tr);
}
return true;
}
use of com.graphhopper.util.PointList in project graphhopper by graphhopper.
the class GraphEdgeIdFinder method fillEdgeIDs.
/**
* This method fills the edgeIds hash with edgeIds found inside the specified geometry
*/
public void fillEdgeIDs(GHIntHashSet edgeIds, Geometry geometry, EdgeFilter filter) {
if (geometry instanceof Point) {
GHPoint point = GHPoint.create((Point) geometry);
findClosestEdgeToPoint(edgeIds, point, filter);
} else if (geometry instanceof LineString) {
PointList pl = PointList.from((LineString) geometry);
// TODO do map matching or routing
int lastIdx = pl.size() - 1;
if (pl.size() >= 2) {
double meanLat = (pl.getLatitude(0) + pl.getLatitude(lastIdx)) / 2;
double meanLon = (pl.getLongitude(0) + pl.getLongitude(lastIdx)) / 2;
findClosestEdge(edgeIds, meanLat, meanLon, filter);
}
} else if (geometry instanceof MultiPoint) {
for (Coordinate coordinate : geometry.getCoordinates()) {
findClosestEdge(edgeIds, coordinate.y, coordinate.x, filter);
}
}
}
use of com.graphhopper.util.PointList in project graphhopper by graphhopper.
the class QueryResult method calcSnappedPoint.
/**
* Calculates the closet point on the edge from the query point.
*/
public void calcSnappedPoint(DistanceCalc distCalc) {
if (closestEdge == null)
throw new IllegalStateException("No closest edge?");
if (snappedPoint != null)
throw new IllegalStateException("Calculate snapped point only once");
PointList fullPL = getClosestEdge().fetchWayGeometry(3);
double tmpLat = fullPL.getLatitude(wayIndex);
double tmpLon = fullPL.getLongitude(wayIndex);
double tmpEle = fullPL.getElevation(wayIndex);
if (snappedPosition != Position.EDGE) {
snappedPoint = new GHPoint3D(tmpLat, tmpLon, tmpEle);
return;
}
double queryLat = getQueryPoint().lat, queryLon = getQueryPoint().lon;
double adjLat = fullPL.getLatitude(wayIndex + 1), adjLon = fullPL.getLongitude(wayIndex + 1);
if (distCalc.validEdgeDistance(queryLat, queryLon, tmpLat, tmpLon, adjLat, adjLon)) {
GHPoint tmpPoint = distCalc.calcCrossingPointToEdge(queryLat, queryLon, tmpLat, tmpLon, adjLat, adjLon);
double adjEle = fullPL.getElevation(wayIndex + 1);
snappedPoint = new GHPoint3D(tmpPoint.lat, tmpPoint.lon, (tmpEle + adjEle) / 2);
} else
// outside of edge boundaries
snappedPoint = new GHPoint3D(tmpLat, tmpLon, tmpEle);
}
use of com.graphhopper.util.PointList in project graphhopper by graphhopper.
the class GraphElevationSmoothingTest method interpolatesElevationOfPillarNodes.
@Test
public void interpolatesElevationOfPillarNodes() {
PointList pl1 = new PointList(3, true);
pl1.add(0, 0, 0);
pl1.add(0.0005, 0.0005, 100);
pl1.add(0.001, 0.001, 50);
GraphElevationSmoothing.smoothElevation(pl1);
assertEquals(3, pl1.size());
assertEquals(50, pl1.getElevation(1), .1);
PointList pl2 = new PointList(3, true);
pl2.add(0.001, 0.001, 50);
pl2.add(0.0015, 0.0015, 160);
pl2.add(0.0016, 0.0015, 150);
pl2.add(0.0017, 0.0015, 220);
pl2.add(0.002, 0.002, 20);
GraphElevationSmoothing.smoothElevation(pl2);
assertEquals(5, pl2.size());
assertEquals(120, pl2.getElevation(1), .1);
// This is not 120 anymore, as the point at index 1 was smoothed from 160=>120
assertEquals(112, pl2.getElevation(2), .1);
assertEquals(50, pl2.getEle(0), .1);
}
Aggregations