private void rebuildRtrees() { ftToIndex.clear(); for ( FeatureType ft : ftToFeatures.keySet() ) { FeatureCollection fc = ftToFeatures.get( ft ); Envelope env = fc.getEnvelope(); if ( env != null ) { RTree<Feature> index = new RTree<Feature>( toFloats( env ), 16 ); List<Pair<float[], Feature>> fBboxes = new ArrayList<Pair<float[], Feature>>( fc.size() ); for ( Feature f : fc ) { Envelope fEnv = f.getEnvelope(); if ( fEnv != null ) { float[] floats = toFloats( fEnv ); fBboxes.add( new Pair<float[], Feature>( floats, f ) ); } } index.insertBulk( fBboxes ); ftToIndex.put( ft, index ); } } }
/** * Adds the given {@link Feature} instance and updates the index structures. * * @param features * feature to be added, must not be <code>null</code> and must have an id (as well as every geometry) */ void addFeature( Feature feature ) { FeatureType ft = feature.getType(); FeatureCollection fc = ftToFeatures.get( ft ); if ( fc == null ) { fc = new GenericFeatureCollection(); ftToFeatures.put( ft, fc ); } fc.add( feature ); idToObject.put( feature.getId(), feature ); if ( feature.getEnvelope() != null ) { RTree<Feature> rTree = ftToIndex.get( ft ); float[] insertBox = toFloats( feature.getEnvelope() ); if ( rTree == null ) { rTree = new RTree<Feature>( insertBox, 16 ); } rTree.insert( insertBox, feature ); } }
float[] floats = toFloats( prefilterBox ); RTree<Feature> index = ftToIndex.get( ft ); fc = new GenericFeatureCollection( null, index.query( floats ) );