use of com.graphhopper.storage.index.Snap in project graphhopper by graphhopper.
the class NearestResource method doGet.
@GET
public Response doGet(@QueryParam("point") GHPoint point, @QueryParam("elevation") @DefaultValue("false") boolean elevation) {
Snap snap = index.findClosest(point.lat, point.lon, EdgeFilter.ALL_EDGES);
if (snap.isValid()) {
GHPoint3D snappedPoint = snap.getSnappedPoint();
double[] coordinates = hasElevation && elevation ? new double[] { snappedPoint.lon, snappedPoint.lat, snappedPoint.ele } : new double[] { snappedPoint.lon, snappedPoint.lat };
return new Response(coordinates, calc.calcDist(point.lat, point.lon, snappedPoint.lat, snappedPoint.lon));
} else {
throw new WebApplicationException("Nearest point cannot be found!");
}
}
use of com.graphhopper.storage.index.Snap in project graphhopper by graphhopper.
the class OSMReaderTest method testCrossBoundary_issue667.
@Test
public void testCrossBoundary_issue667() {
GraphHopper hopper = new GraphHopperFacade("test-osm-waterway.xml").importOrLoad();
Snap snap = hopper.getLocationIndex().findClosest(0.1, 179.5, EdgeFilter.ALL_EDGES);
assertTrue(snap.isValid());
assertEquals(0.1, snap.getSnappedPoint().lat, 0.1);
assertEquals(179.5, snap.getSnappedPoint().lon, 0.1);
assertEquals(11, snap.getClosestEdge().getDistance() / 1000, 1);
snap = hopper.getLocationIndex().findClosest(0.1, -179.6, EdgeFilter.ALL_EDGES);
assertTrue(snap.isValid());
assertEquals(0.1, snap.getSnappedPoint().lat, 0.1);
assertEquals(-179.6, snap.getSnappedPoint().lon, 0.1);
assertEquals(112, snap.getClosestEdge().getDistance() / 1000, 1);
}
use of com.graphhopper.storage.index.Snap in project graphhopper by graphhopper.
the class GraphHopperTest method issue2306_2.
@Test
public void issue2306_2() {
// This is the same test as above, but without increasing the search radius.
// As I am writing this, we find _no_ match here. But since the search radius
// is a meta-parameter that could go away at some point, I say that _if_ we find a match,
// it should be a close one. (And not a far away one, as happened in issue2306.)
final String profile = "profile";
final String vehicle = "car";
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile("../map-matching/files/leipzig_germany.osm.pbf").setProfiles(new Profile("profile").setVehicle(vehicle).setWeighting("fastest")).setMinNetworkSize(200);
hopper.importOrLoad();
Weighting weighting = hopper.createWeighting(hopper.getProfile(profile), new PMap());
EdgeFilter edgeFilter = new DefaultSnapFilter(weighting, hopper.getEncodingManager().getBooleanEncodedValue(Subnetwork.key(profile)));
Snap snap = hopper.getLocationIndex().findClosest(51.229248, 12.328892, edgeFilter);
if (snap.isValid()) {
assertTrue(snap.getQueryDistance() < 3_000);
}
}
use of com.graphhopper.storage.index.Snap in project graphhopper by graphhopper.
the class MapMatching method findCandidateSnaps.
public List<Snap> findCandidateSnaps(final double queryLat, final double queryLon) {
double rLon = (measurementErrorSigma * 360.0 / DistanceCalcEarth.DIST_EARTH.calcCircumference(queryLat));
double rLat = measurementErrorSigma / DistanceCalcEarth.METERS_PER_DEGREE;
Envelope envelope = new Envelope(queryLon, queryLon, queryLat, queryLat);
for (int i = 0; i < 50; i++) {
envelope.expandBy(rLon, rLat);
List<Snap> snaps = findCandidateSnapsInBBox(queryLat, queryLon, BBox.fromEnvelope(envelope));
if (!snaps.isEmpty()) {
return snaps;
}
}
return Collections.emptyList();
}
use of com.graphhopper.storage.index.Snap in project graphhopper by graphhopper.
the class MapMatching method findCandidateSnapsInBBox.
private List<Snap> findCandidateSnapsInBBox(double queryLat, double queryLon, BBox queryShape) {
EdgeFilter edgeFilter = new DefaultSnapFilter(unwrappedWeighting, inSubnetworkEnc);
List<Snap> snaps = new ArrayList<>();
IntHashSet seenEdges = new IntHashSet();
IntHashSet seenNodes = new IntHashSet();
locationIndex.query(queryShape, edgeId -> {
EdgeIteratorState edge = graph.getEdgeIteratorStateForKey(edgeId * 2);
if (seenEdges.add(edgeId) && edgeFilter.accept(edge)) {
Snap snap = new Snap(queryLat, queryLon);
locationIndex.traverseEdge(queryLat, queryLon, edge, (node, normedDist, wayIndex, pos) -> {
if (normedDist < snap.getQueryDistance()) {
snap.setQueryDistance(normedDist);
snap.setClosestNode(node);
snap.setWayIndex(wayIndex);
snap.setSnappedPosition(pos);
}
});
double dist = DIST_PLANE.calcDenormalizedDist(snap.getQueryDistance());
snap.setClosestEdge(edge);
snap.setQueryDistance(dist);
if (snap.isValid() && (snap.getSnappedPosition() != Snap.Position.TOWER || seenNodes.add(snap.getClosestNode()))) {
snap.calcSnappedPoint(DistanceCalcEarth.DIST_EARTH);
if (queryShape.contains(snap.getSnappedPoint().lat, snap.getSnappedPoint().lon)) {
snaps.add(snap);
}
}
}
});
return snaps;
}
Aggregations