Search in sources :

Example 96 with Envelope

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;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Vertex(org.opentripplanner.routing.graph.Vertex) STRtree(com.vividsolutions.jts.index.strtree.STRtree) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Envelope(com.vividsolutions.jts.geom.Envelope) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 97 with Envelope

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;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) SampleVertex(org.opentripplanner.routing.vertextype.SampleVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 98 with Envelope

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;
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 99 with Envelope

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);
    }
}
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)

Example 100 with Envelope

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);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) Coordinate(com.vividsolutions.jts.geom.Coordinate) Envelope(com.vividsolutions.jts.geom.Envelope)

Aggregations

Envelope (com.vividsolutions.jts.geom.Envelope)111 Coordinate (com.vividsolutions.jts.geom.Coordinate)21 Node (org.locationtech.geogig.api.Node)16 Geometry (com.vividsolutions.jts.geom.Geometry)13 ObjectId (org.locationtech.geogig.api.ObjectId)13 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)12 STRtree (com.vividsolutions.jts.index.strtree.STRtree)11 ArrayList (java.util.ArrayList)11 Vertex (org.opentripplanner.routing.graph.Vertex)11 Test (org.junit.Test)9 NodeRef (org.locationtech.geogig.api.NodeRef)9 Edge (org.opentripplanner.routing.graph.Edge)9 LineString (com.vividsolutions.jts.geom.LineString)8 RevTree (org.locationtech.geogig.api.RevTree)8 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)7 Map (java.util.Map)6 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)6 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)6 RevFeature (org.locationtech.geogig.api.RevFeature)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5