Search in sources :

Example 36 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project onebusaway-application-modules by camsys.

the class BlockGeospatialServiceImpl method getBlockSequenceIndexPassingThroughBounds.

@Override
public Set<BlockSequenceIndex> getBlockSequenceIndexPassingThroughBounds(CoordinateBounds bounds) {
    Envelope env = new Envelope(bounds.getMinLon(), bounds.getMaxLon(), bounds.getMinLat(), bounds.getMaxLat());
    @SuppressWarnings("unchecked") List<List<AgencyAndId>> results = _tree.query(env);
    Set<AgencyAndId> visitedShapeIds = new HashSet<AgencyAndId>();
    Set<BlockSequenceIndex> allIndices = new HashSet<BlockSequenceIndex>();
    for (List<AgencyAndId> shapeIds : results) {
        for (AgencyAndId shapeId : shapeIds) {
            if (visitedShapeIds.add(shapeId)) {
                List<BlockSequenceIndex> indices = _blockSequenceIndicesByShapeId.get(shapeId);
                if (!CollectionsLibrary.isEmpty(indices)) {
                    allIndices.addAll(indices);
                }
            }
        }
    }
    return allIndices;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) List(java.util.List) ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope) HashSet(java.util.HashSet)

Example 37 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project onebusaway-application-modules by camsys.

the class BlockGeospatialServiceImpl method buildShapeSpatialIndex.

private void buildShapeSpatialIndex() throws IOException, ClassNotFoundException {
    File path = _bundle.getShapeGeospatialIndexDataPath();
    if (!path.exists()) {
        _tree = null;
        return;
    }
    _log.info("loading shape point geospatial index...");
    Map<CoordinateBounds, List<AgencyAndId>> shapeIdsByGridCell = ObjectSerializationLibrary.readObject(path);
    _log.info("block shape geospatial nodes: " + shapeIdsByGridCell.size());
    if (shapeIdsByGridCell.isEmpty()) {
        _tree = null;
        return;
    }
    _tree = new STRtree(shapeIdsByGridCell.size());
    for (Map.Entry<CoordinateBounds, List<AgencyAndId>> entry : shapeIdsByGridCell.entrySet()) {
        CoordinateBounds b = entry.getKey();
        Envelope env = new Envelope(b.getMinLon(), b.getMaxLon(), b.getMinLat(), b.getMaxLat());
        List<AgencyAndId> shapeIds = entry.getValue();
        _tree.insert(env, shapeIds);
    }
    _tree.build();
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) STRtree(com.vividsolutions.jts.index.strtree.STRtree) List(java.util.List) ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 38 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project onebusaway-application-modules by camsys.

the class RoutesBeanServiceImpl method getRoutesWithRouteNameQuery.

private RoutesBean getRoutesWithRouteNameQuery(SearchQueryBean query) throws ServiceException {
    SearchResult<AgencyAndId> result = searchForRoutes(query);
    List<RouteBean> routeBeans = new ArrayList<RouteBean>();
    CoordinateBounds bounds = query.getBounds();
    for (AgencyAndId id : result.getResults()) {
        STRtree tree = _stopTreesByRouteId.get(id);
        if (tree == null) {
            _log.warn("stop tree not found for routeId=" + id);
            continue;
        }
        Envelope env = new Envelope(bounds.getMinLon(), bounds.getMaxLon(), bounds.getMinLat(), bounds.getMaxLat());
        HasItemsVisitor v = new HasItemsVisitor();
        tree.query(env, v);
        if (v.hasItems()) {
            RouteBean routeBean = _routeBeanService.getRouteForId(id);
            routeBeans.add(routeBean);
        }
    }
    boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(routeBeans, query.getMaxCount());
    return constructResult(routeBeans, limitExceeded);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) STRtree(com.vividsolutions.jts.index.strtree.STRtree) Envelope(com.vividsolutions.jts.geom.Envelope) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 39 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project onebusaway-application-modules by camsys.

the class HierarchicalSTRtreeFactory method add.

public void add(double lat, double lon, T element) {
    STRtree tree = null;
    for (Map.Entry<CoordinateBounds, STRtree> entry : _treesByBounds.entrySet()) {
        CoordinateBounds bounds = entry.getKey();
        if (bounds.contains(lat, lon)) {
            tree = entry.getValue();
            break;
        }
    }
    if (tree == null) {
        double gLat = Math.floor(lat / _latStep) * _latStep;
        double gLon = Math.floor(lon / _lonStep) * _lonStep;
        CoordinateBounds b = new CoordinateBounds(gLat, gLon, gLat + _latStep, gLon + _lonStep);
        tree = new STRtree();
        _treesByBounds.put(b, tree);
    }
    Envelope env = new Envelope(lon, lon, lat, lat);
    tree.insert(env, element);
}
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 40 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project onebusaway-application-modules by camsys.

the class BoundingBoxController method index.

@RequestMapping()
public ModelAndView index() {
    GeometryFactory gf = new GeometryFactory();
    List<Polygon> polygons = new ArrayList<Polygon>();
    Map<String, CoordinateBounds> agencies = _agencyService.getAgencyIdsAndCoverageAreas();
    for (CoordinateBounds cb : agencies.values()) {
        Envelope e = new Envelope(cb.getMinLon(), cb.getMaxLon(), cb.getMinLat(), cb.getMaxLat());
        Polygon p = (Polygon) gf.toGeometry(e);
        polygons.add(p);
    }
    MultiPolygon mp = gf.createMultiPolygon(polygons.toArray(new Polygon[0]));
    Geometry hull = mp.convexHull();
    Envelope env = hull.getEnvelopeInternal();
    ModelAndView mv = new ModelAndView("bounding-box.jspx");
    mv.addObject("minY", env.getMinY());
    mv.addObject("minX", env.getMinX());
    mv.addObject("maxY", env.getMaxY());
    mv.addObject("maxX", env.getMaxX());
    mv.addObject("hullWKT", hull.toText());
    return mv;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Envelope(com.vividsolutions.jts.geom.Envelope) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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