Search in sources :

Example 1 with HashGridSpatialIndex

use of org.opentripplanner.common.geometry.HashGridSpatialIndex 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);
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) SampleVertex(org.opentripplanner.routing.vertextype.SampleVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) HashGridSpatialIndex(org.opentripplanner.common.geometry.HashGridSpatialIndex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) LineString(com.vividsolutions.jts.geom.LineString) Envelope(com.vividsolutions.jts.geom.Envelope) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

Envelope (com.vividsolutions.jts.geom.Envelope)1 LineString (com.vividsolutions.jts.geom.LineString)1 HashGridSpatialIndex (org.opentripplanner.common.geometry.HashGridSpatialIndex)1 Edge (org.opentripplanner.routing.graph.Edge)1 Vertex (org.opentripplanner.routing.graph.Vertex)1 SampleVertex (org.opentripplanner.routing.vertextype.SampleVertex)1 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)1 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)1