private static STRtree buildRTree(LongArrayList addresses, List<List<Block>> channels, int geometryChannel, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel) STRtree rtree = new STRtree(); Operator relateOperator = OperatorFactoryLocal.getInstance().getOperator(Operator.Type.Relate); rtree.insert(getEnvelope(ogcGeometry, radius), new GeometryWithPosition(ogcGeometry, partition, position)); rtree.build(); return rtree;
rtree.query(envelope, item -> { GeometryWithPosition geometryWithPosition = (GeometryWithPosition) item; OGCGeometry buildGeometry = geometryWithPosition.getGeometry();
@Override protected Iterator openIterator() { List features; synchronized (CachingFeatureSource.this) { try { if (index == null || dirty || !isSubQuery(query)) { fillCache(query); } if (queryBounds != null) { features = index.query(queryBounds); } else { features = index.query((Envelope) index.getRoot().getBounds()); } } catch (Exception e) { throw new RuntimeException("Failed to get data", e); } } Iterator it = features.iterator(); if (query.getFilter() != null && Filter.INCLUDE.equals(query.getFilter())) { it = new FilteringIterator<Feature>(it, query.getFilter()); } if (targetSchema != sourceSchema) { it = new ReTypingIterator(it, sourceSchema, targetSchema); } return it; }
public PagesSpatialIndexSupplier( Session session, LongArrayList addresses, List<Type> types, List<Integer> outputChannels, List<List<Block>> channels, int geometryChannel, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel, SpatialPredicate spatialRelationshipTest, Optional<JoinFilterFunctionCompiler.JoinFilterFunctionFactory> filterFunctionFactory, Map<Integer, Rectangle> partitions) { this.session = session; this.addresses = addresses; this.types = types; this.outputChannels = outputChannels; this.channels = channels; this.spatialRelationshipTest = spatialRelationshipTest; this.filterFunctionFactory = filterFunctionFactory; this.partitions = partitions; this.rtree = buildRTree(addresses, channels, geometryChannel, radiusChannel, partitionChannel); this.radiusChannel = radiusChannel; this.memorySizeInBytes = INSTANCE_SIZE + (rtree.isEmpty() ? 0 : STRTREE_INSTANCE_SIZE + computeMemorySizeInBytes(rtree.getRoot())); }
public void testDisallowedInserts() { STRtree t = new STRtree(5); t.insert(new Envelope(0, 0, 0, 0), new Object()); t.insert(new Envelope(0, 0, 0, 0), new Object()); t.query(new Envelope()); try { t.insert(new Envelope(0, 0, 0, 0), new Object()); assertTrue(false); } catch (AssertionFailedException e) { assertTrue(true); } }
public boolean add(SimpleFeature feature) { ReferencedEnvelope bounds = ReferencedEnvelope.reference(feature.getBounds()); index.insert(bounds, feature); return false; }
STRtree strtree = new STRtree(); for(int i=0;i<totalRecords;i++) strtree.insert(testDataset.get(i).getEnvelopeInternal(), testDataset.get(i)); strtree.query(new Envelope(1+0.1,1+0.1,2+0.1,2+0.1)); Object[] testTopK = (Object[])strtree.nearestNeighbour(queryCenter.getEnvelopeInternal(), queryCenter, new GeometryItemDistance(), topK); List topKList = Arrays.asList(testTopK); Collections.sort(topKList,distanceComparator);
private void fillCache(Query query) throws IOException { Query cloned = new DefaultQuery(query); cloned.getHints().remove(Hints.GEOMETRY_DISTANCE); FeatureCollection features = wrapped.getFeatures(cloned); FeatureIterator fi = features.features(); index = null; STRtree newIndex = new STRtree(); while (fi.hasNext()) { // consider turning all geometries into packed ones, to save space Feature f = fi.next(); newIndex.insert(ReferencedEnvelope.reference(f.getBounds()), f); } fi.close(); index = newIndex; cachedQuery = query; cachedBounds = getEnvelope(query.getFilter()); dirty = false; }
public void testRemove() { STRtree tree = new STRtree(); tree.insert(new Envelope(0, 10, 0, 10), "1"); tree.insert(new Envelope(5, 15, 5, 15), "2"); tree.insert(new Envelope(10, 20, 10, 20), "3"); tree.insert(new Envelope(15, 25, 15, 25), "4"); tree.remove(new Envelope(10, 20, 10, 20), "4"); assertEquals(3, tree.size()); }
public SpatialIndexFeatureCollection(SimpleFeatureType schema) { this.index = new STRtree(); this.schema = schema; }
/** * Finds the two nearest items in the tree, * using {@link ItemDistance} as the distance metric. * A Branch-and-Bound tree traversal algorithm is used * to provide an efficient search. * * @param itemDist a distance metric applicable to the items in this tree * @return the pair of the nearest items */ public Object[] nearestNeighbour(ItemDistance itemDist) { BoundablePair bp = new BoundablePair(this.getRoot(), this.getRoot(), itemDist); return nearestNeighbour(bp); } /**
private Object[] nearestNeighbour(BoundablePair initBndPair) { return nearestNeighbour(initBndPair, Double.POSITIVE_INFINITY); } private Object[] nearestNeighbour(BoundablePair initBndPair, int k)
public ReferencedEnvelope getBounds() { CoordinateReferenceSystem crs = schema.getCoordinateReferenceSystem(); Envelope bounds = (Envelope) index.getRoot().getBounds(); return new ReferencedEnvelope(bounds, crs); }
public void finishInserting() { index.build(); } }