Search in sources :

Example 6 with STRtree

use of com.vividsolutions.jts.index.strtree.STRtree 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 7 with STRtree

use of com.vividsolutions.jts.index.strtree.STRtree in project onebusaway-application-modules by camsys.

the class TransitGraphImpl method initialize.

public void initialize() {
    if (_stopLocationTree == null) {
        System.out.println("initializing transit graph...");
        if (_stops.size() == 0) {
            _log.warn("no stops found for graph");
        } else {
            _stopLocationTree = new STRtree(_stops.size());
            for (int i = 0; i < _stops.size(); i++) {
                StopEntry stop = _stops.get(i);
                double x = stop.getStopLon();
                double y = stop.getStopLat();
                Envelope r = new Envelope(x, x, y, y);
                _stopLocationTree.insert(r, stop);
            }
            _stopLocationTree.build();
        }
        System.out.println("  stops=" + _stops.size());
        System.out.println("  trips= " + _trips.size());
    }
    if (_agencyEntriesById == null || _agencyEntriesById.size() < _agencies.size()) {
        refreshAgencyMapping();
    }
    if (_tripEntriesById == null || _tripEntriesById.size() < _trips.size()) {
        refreshTripMapping();
    }
    if (_blockEntriesById == null || _blockEntriesById.size() < _blocks.size()) {
        refreshBlockMapping();
    }
    if (_stopEntriesById == null || _stopEntriesById.size() < _stops.size())
        refreshStopMapping();
    if (_routeCollectionEntriesById == null || _routeCollectionEntriesById.size() < _routeCollections.size())
        refreshRouteCollectionMapping();
    if (_routeEntriesById == null || _routeEntriesById.size() < _routes.size())
        refreshRouteMapping();
    int i = 0;
    for (StopEntryImpl stop : _stops) stop.setIndex(i++);
}
Also used : STRtree(com.vividsolutions.jts.index.strtree.STRtree) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 8 with STRtree

use of com.vividsolutions.jts.index.strtree.STRtree in project onebusaway-application-modules by camsys.

the class HierarchicalSTRtree method query.

@SuppressWarnings("unchecked")
public List<T> query(CoordinateBounds b) {
    List<T> results = new ArrayList<T>();
    Envelope env = new Envelope(b.getMinLon(), b.getMaxLon(), b.getMinLat(), b.getMaxLat());
    List<STRtree> subTrees = _parentTree.query(env);
    for (STRtree subTree : subTrees) {
        List<T> result = subTree.query(env);
        results.addAll(result);
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) STRtree(com.vividsolutions.jts.index.strtree.STRtree) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 9 with STRtree

use of com.vividsolutions.jts.index.strtree.STRtree in project onebusaway-application-modules by camsys.

the class HierarchicalSTRtreeFactory method create.

public HierarchicalSTRtree<T> create() {
    STRtree parentTree = new STRtree();
    for (Map.Entry<CoordinateBounds, STRtree> entry : _treesByBounds.entrySet()) {
        CoordinateBounds b = entry.getKey();
        Envelope env = new Envelope(b.getMinLon(), b.getMaxLon(), b.getMinLat(), b.getMaxLat());
        STRtree tree = entry.getValue();
        tree.build();
        parentTree.insert(env, tree);
    }
    parentTree.build();
    return new HierarchicalSTRtree<T>(parentTree);
}
Also used : STRtree(com.vividsolutions.jts.index.strtree.STRtree) Envelope(com.vividsolutions.jts.geom.Envelope) Map(java.util.Map) HashMap(java.util.HashMap) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 10 with STRtree

use of com.vividsolutions.jts.index.strtree.STRtree in project onebusaway-application-modules by camsys.

the class WhereGeospatialServiceImpl method initialize.

@PostConstruct
@Refreshable(dependsOn = RefreshableResources.STOP_GEOSPATIAL_INDEX)
public void initialize() {
    List<StopEntry> stops = _transitGraphDao.getAllStops();
    if (stops.size() == 0) {
        _tree = null;
        return;
    }
    _tree = new STRtree(stops.size());
    for (StopEntry stop : stops) {
        float x = (float) stop.getStopLon();
        float y = (float) stop.getStopLat();
        Envelope env = new Envelope(x, x, y, y);
        _tree.insert(env, stop.getId());
    }
    _tree.build();
}
Also used : STRtree(com.vividsolutions.jts.index.strtree.STRtree) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) Envelope(com.vividsolutions.jts.geom.Envelope) Refreshable(org.onebusaway.container.refresh.Refreshable) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Envelope (com.vividsolutions.jts.geom.Envelope)11 STRtree (com.vividsolutions.jts.index.strtree.STRtree)11 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)3 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 PostConstruct (javax.annotation.PostConstruct)2 Refreshable (org.onebusaway.container.refresh.Refreshable)2 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)2 Edge (org.opentripplanner.routing.graph.Edge)2 Vertex (org.opentripplanner.routing.graph.Vertex)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 SpatialIndex (com.vividsolutions.jts.index.SpatialIndex)1 File (java.io.File)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Random (java.util.Random)1