use of org.locationtech.jts.index.strtree.STRtree in project urban-eureka by errir503.
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 HashGridTest method testHashGridRandom.
/**
* We perform a non-regression random test. We insert many random-envelop objects
* into both a hash grid (OTP) and STRtree (JTS) spatial indexes. We check with
* many random query that the set of returned objects is the same (after pruning
* because both could return false positives).
*/
@SuppressWarnings("unchecked")
public void testHashGridRandom() {
final double X0 = -0.05;
final double Y0 = 44.0;
final double DX = 0.1;
final double DY = 0.1;
final int N_OBJS = 1000;
final int N_QUERIES = 1000;
Random rand = new Random(42);
SpatialIndex hashGrid = new HashGridSpatialIndex<>();
SpatialIndex strTree = new STRtree();
for (int i = 0; i < N_OBJS; i++) {
Coordinate a = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
Coordinate b = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
DummyObject obj = new DummyObject();
obj.envelope = new Envelope(a, b);
hashGrid.insert(obj.envelope, obj);
strTree.insert(obj.envelope, obj);
}
for (int i = 0; i < N_QUERIES; i++) {
Coordinate a = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
Coordinate b = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
Envelope searchEnv = new Envelope(a, b);
List<DummyObject> hashGridObjs = hashGrid.query(searchEnv);
// Need to remove non intersecting
Set<DummyObject> hashGridObjs2 = new HashSet<>();
for (DummyObject obj : hashGridObjs) {
if (obj.envelope.intersects(searchEnv))
hashGridObjs2.add(obj);
}
List<DummyObject> strtreeObjs = hashGrid.query(searchEnv);
// Need to remove non intersecting
Set<DummyObject> strtreeObjs2 = new HashSet<>();
for (DummyObject obj : strtreeObjs) {
if (obj.envelope.intersects(searchEnv))
strtreeObjs2.add(obj);
}
boolean equals = hashGridObjs2.equals(strtreeObjs2);
assertTrue(equals);
}
}
use of org.locationtech.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;
}
use of org.locationtech.jts.index.strtree.STRtree in project onebusaway-application-modules by camsys.
the class RoutesBeanServiceImpl method setup.
@Refreshable(dependsOn = { RefreshableResources.NARRATIVE_DATA })
@PostConstruct
public void setup() {
_stopTreesByRouteId.clear();
for (StopEntry stop : _graphDao.getAllStops()) {
Set<AgencyAndId> routeIds = _routeService.getRouteCollectionIdsForStop(stop.getId());
for (AgencyAndId routeId : routeIds) {
STRtree tree = _stopTreesByRouteId.get(routeId);
if (tree == null) {
tree = new STRtree();
_stopTreesByRouteId.put(routeId, tree);
}
double x = stop.getStopLon();
double y = stop.getStopLat();
Envelope env = new Envelope(x, x, y, y);
tree.insert(env, routeId);
}
}
for (STRtree tree : _stopTreesByRouteId.values()) tree.build();
}
use of org.locationtech.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++);
}
Aggregations