use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class StreetMatcher method createIndex.
STRtree createIndex() {
STRtree edgeIndex = new STRtree();
for (Vertex v : graph.getVertices()) {
for (Edge e : v.getOutgoing()) {
if (e instanceof StreetEdge) {
Envelope envelope;
Geometry geometry = e.getGeometry();
envelope = geometry.getEnvelopeInternal();
edgeIndex.insert(envelope, e);
}
}
}
log.debug("Created index");
return edgeIndex;
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class StreetVertexIndexServiceImpl method getIntersectionAt.
/**
* @param coordinate Location to search intersection at. Look in a MAX_CORNER_DISTANCE_METERS radius.
* @return The nearest intersection, null if none found.
*/
public StreetVertex getIntersectionAt(Coordinate coordinate) {
double dLon = SphericalDistanceLibrary.metersToLonDegrees(MAX_CORNER_DISTANCE_METERS, coordinate.y);
double dLat = SphericalDistanceLibrary.metersToDegrees(MAX_CORNER_DISTANCE_METERS);
Envelope envelope = new Envelope(coordinate);
envelope.expandBy(dLon, dLat);
List<Vertex> nearby = getVerticesForEnvelope(envelope);
StreetVertex nearest = null;
double bestDistanceMeter = Double.POSITIVE_INFINITY;
for (Vertex v : nearby) {
if (v instanceof StreetVertex) {
v.getLabel().startsWith("osm:");
double distanceMeter = SphericalDistanceLibrary.fastDistance(coordinate, v.getCoordinate());
if (distanceMeter < MAX_CORNER_DISTANCE_METERS) {
if (distanceMeter < bestDistanceMeter) {
bestDistanceMeter = distanceMeter;
nearest = (StreetVertex) v;
}
}
}
}
return nearest;
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class StreetVertexIndexServiceImpl method getNearbyTransitStops.
/**
* Get all transit stops within a given distance of a coordinate
*/
@Override
public List<TransitStop> getNearbyTransitStops(Coordinate coordinate, double radius) {
Envelope env = new Envelope(coordinate);
env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(radius, coordinate.y), SphericalDistanceLibrary.metersToDegrees(radius));
List<TransitStop> nearby = getTransitStopForEnvelope(env);
List<TransitStop> results = new ArrayList<TransitStop>();
for (TransitStop v : nearby) {
if (SphericalDistanceLibrary.distance(v.getCoordinate(), coordinate) <= radius) {
results.add(v);
}
}
return results;
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class StreetVertexIndexServiceImpl method postSetup.
@SuppressWarnings("rawtypes")
private void postSetup() {
for (Vertex gv : graph.getVertices()) {
Vertex v = gv;
/*
* We add all edges with geometry, skipping transit, filtering them out after. We do not
* index transit edges as we do not need them and some GTFS do not have shape data, so
* long straight lines between 2 faraway stations will wreck performance on a hash grid
* spatial index.
*
* If one need to store transit edges in the index, we could improve the hash grid
* rasterizing splitting long segments.
*/
for (Edge e : gv.getOutgoing()) {
if (e instanceof PatternEdge || e instanceof SimpleTransfer)
continue;
LineString geometry = e.getGeometry();
if (geometry == null) {
continue;
}
Envelope env = geometry.getEnvelopeInternal();
if (edgeTree instanceof HashGridSpatialIndex)
((HashGridSpatialIndex) edgeTree).insert(geometry, e);
else
edgeTree.insert(env, e);
}
if (v instanceof TransitStop) {
Envelope env = new Envelope(v.getCoordinate());
transitStopTree.insert(env, v);
}
Envelope env = new Envelope(v.getCoordinate());
verticesTree.insert(env, v);
}
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class GraphIndexTest method testSpatialIndex.
public void testSpatialIndex() {
String feedId = graph.getFeedIds().iterator().next();
Stop stopJ = graph.index.stopForId.get(new AgencyAndId(feedId, "J"));
Stop stopL = graph.index.stopForId.get(new AgencyAndId(feedId, "L"));
Stop stopM = graph.index.stopForId.get(new AgencyAndId(feedId, "M"));
TransitStop stopvJ = graph.index.stopVertexForStop.get(stopJ);
TransitStop stopvL = graph.index.stopVertexForStop.get(stopL);
TransitStop stopvM = graph.index.stopVertexForStop.get(stopM);
// There are a two other stops within 100 meters of stop J.
Envelope env = new Envelope(new Coordinate(stopJ.getLon(), stopJ.getLat()));
env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(100, stopJ.getLat()), SphericalDistanceLibrary.metersToDegrees(100));
List<TransitStop> stops = graph.index.stopSpatialIndex.query(env);
assertTrue(stops.contains(stopvJ));
assertTrue(stops.contains(stopvL));
assertTrue(stops.contains(stopvM));
// Query can overselect
assertTrue(stops.size() >= 3);
}
Aggregations