use of org.locationtech.jts.index.strtree.STRtree in project presto by prestodb.
the class BenchmarkJtsStrTreeBuild method buildRtree.
@Benchmark
@OperationsPerInvocation(1)
public void buildRtree(BenchmarkData data, Blackhole blackhole) {
STRtree rtree = new STRtree();
for (Envelope envelope : data.getBuildEnvelopes()) {
rtree.insert(envelope, envelope);
}
rtree.build();
blackhole.consume(rtree);
}
use of org.locationtech.jts.index.strtree.STRtree in project OpenTripPlanner by opentripplanner.
the class ShowGraph method buildSpatialIndex.
/*
* Iterate through all vertices and their (outgoing) edges. If they are of 'interesting' types,
* add them to the corresponding spatial index.
*/
public synchronized void buildSpatialIndex() {
vertexIndex = new STRtree();
edgeIndex = new STRtree();
Envelope env;
// int xminx, xmax, ymin, ymax;
for (Vertex v : graph.getVertices()) {
Coordinate c = v.getCoordinate();
env = new Envelope(c);
vertexIndex.insert(env, v);
for (Edge e : v.getOutgoing()) {
if (e.getGeometry() == null)
continue;
if (e instanceof StreetTransitLink || e instanceof StreetEdge || e instanceof PathwayEdge) {
env = e.getGeometry().getEnvelopeInternal();
edgeIndex.insert(env, e);
}
}
}
vertexIndex.build();
edgeIndex.build();
}
use of org.locationtech.jts.index.strtree.STRtree 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);
}
use of org.locationtech.jts.index.strtree.STRtree 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();
}
use of org.locationtech.jts.index.strtree.STRtree 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);
}
Aggregations