public ReferencedEnvelope getBounds() { ReferencedEnvelope bounds = null; SimpleFeatureIterator i = features(); try { if (!i.hasNext()) { bounds = new ReferencedEnvelope(); bounds.setToNull(); } else { SimpleFeature first = (SimpleFeature) i.next(); bounds = new ReferencedEnvelope(first.getBounds()); } while (i.hasNext()) { SimpleFeature f = (SimpleFeature) i.next(); bounds.include(f.getBounds()); } return bounds; } finally { i.close(); } }
public void visit(org.opengis.feature.Feature feature) { bounds.include(feature.getBounds()); }
/** * Gets the bounding box for the features in this feature collection. * * @return the envelope of the geometries contained by this feature collection. */ public ReferencedEnvelope getBounds() { if (bounds == null) { bounds = new ReferencedEnvelope(); for (Iterator i = contents.values().iterator(); i.hasNext(); ) { BoundingBox geomBounds = ((SimpleFeature) i.next()).getBounds(); // IanS - as of 1.3, JTS expandToInclude ignores "null" Envelope // and simply adds the new bounds... // This check ensures this behavior does not occur. if (!geomBounds.isEmpty()) { bounds.include(geomBounds); } } } return bounds; }
/** * Gets the bounding box for the features in this feature collection. * * @return the envelope of the geometries contained by this feature collection. */ public ReferencedEnvelope getBounds() { if (bounds == null) { bounds = new ReferencedEnvelope(); for (Iterator i = contents.values().iterator(); i.hasNext(); ) { BoundingBox geomBounds = ((SimpleFeature) i.next()).getBounds(); // IanS - as of 1.3, JTS expandToInclude ignores "null" Envelope // and simply adds the new bounds... // This check ensures this behavior does not occur. if (!geomBounds.isEmpty()) { bounds.include(geomBounds); } } } return bounds; }
public CalcResult merge(CalcResult resultsToAdd) { if (!isCompatible(resultsToAdd)) { throw new IllegalArgumentException("Parameter is not a compatible type"); } if (resultsToAdd == CalcResult.NULL_RESULT) { return this; } if (resultsToAdd instanceof BoundsResult) { BoundsResult boundsToAdd = (BoundsResult) resultsToAdd; // add one set to the other (to create one big unique list) ReferencedEnvelope newBounds = new ReferencedEnvelope(bbox); newBounds.include(boundsToAdd.getValue()); return new BoundsResult(newBounds); } else { throw new IllegalArgumentException( "The CalcResults claim to be compatible, but the appropriate merge method has not been implemented."); } } }
/** * Get the total bounds of this feature which is calculated by doing a union of the bounds of * each geometry this feature is associated with. * * @return An Envelope containing the total bounds of this Feature. * @task REVISIT: what to return if there are no geometries in the feature? For now we'll return * a null envelope, make this part of interface? (IanS - by OGC standards, all Feature must * have geom) */ public BoundingBox getBounds() { ReferencedEnvelope bounds = new ReferencedEnvelope(getType().getCoordinateReferenceSystem()); for (Iterator itr = getValue().iterator(); itr.hasNext(); ) { Property property = (Property) itr.next(); if (property instanceof GeometryAttribute) { bounds.include(((GeometryAttribute) property).getBounds()); } } return bounds; }
@Test public void intersection() throws Exception { ReferencedEnvelope australia = new ReferencedEnvelope(DefaultGeographicCRS.WGS84); australia.include(40, 110); australia.include(10, 150); ReferencedEnvelope newZealand = new ReferencedEnvelope(DefaultEngineeringCRS.CARTESIAN_2D); newZealand.include(50, 165); newZealand.include(33, 180); try { australia.intersection(newZealand); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (MismatchedReferenceSystemException t) { // expected } }
@Test public void include() throws Exception { ReferencedEnvelope australia = new ReferencedEnvelope(DefaultGeographicCRS.WGS84); australia.include(40, 110); australia.include(10, 150); ReferencedEnvelope newZealand = new ReferencedEnvelope(DefaultEngineeringCRS.CARTESIAN_2D); newZealand.include(50, 165); newZealand.include(33, 180); try { australia.expandToInclude(newZealand); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (MismatchedReferenceSystemException t) { // expected } try { australia.include(newZealand); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (MismatchedReferenceSystemException t) { // expected } }
@Test public void empty() { // ensure empty can grab a default CRS when starting from nothing ReferencedEnvelope bbox = new ReferencedEnvelope(); // this is empty assertNull(bbox.getCoordinateReferenceSystem()); ReferencedEnvelope australia = new ReferencedEnvelope(DefaultGeographicCRS.WGS84); australia.include(40, 110); australia.include(10, 150); bbox.include(australia); assertEquals(australia.getCoordinateReferenceSystem(), bbox.getCoordinateReferenceSystem()); }
while (reader.hasNext()) { feature = reader.next(); bounds.include(feature.getBounds());
/** * Full collection traversal to obtain bounds of FeatureCollection. Subclasees are strong * encouraged to override this expensive method (even if just to implement caching). */ public ReferencedEnvelope getBounds() { ReferencedEnvelope bounds = null; FeatureIterator<F> it = features(); try { while (it.hasNext()) { Feature feature = it.next(); BoundingBox bbox = feature.getBounds(); if (bbox != null) { if (bounds == null) { bounds = new ReferencedEnvelope(bbox); } else { bounds.include(bbox); } } } } finally { it.close(); } return bounds; } }
public void write() throws IOException { if (live == null) { throw new IOException("No current feature to write"); } if (live.equals(origional)) { writeImplementation(origional); } else { writeImplementation(live); // String typeName = live.getFeatureType().getTypeName(); // Transaction autoCommit = Transaction.AUTO_COMMIT; if (origional != null) { ReferencedEnvelope bounds = ReferencedEnvelope.reference(live.getBounds()); bounds.include(origional.getBounds()); state.fireFeatureUpdated(featureSource, live, bounds); // store.listenerManager.fireFeaturesChanged(typeName, autoCommit, bounds, false); } else { state.fireFeatureAdded(featureSource, live); // store.listenerManager.fireFeaturesAdded(typeName, autoCommit, // ReferencedEnvelope.reference(live.getBounds()), false); } } origional = null; live = null; } // write end
@Override protected ReferencedEnvelope getBoundsInternal(Query query) throws IOException { // TODO: crs? FeatureReader<SimpleFeatureType, SimpleFeature> r = getReader(query); try { ReferencedEnvelope e = new ReferencedEnvelope(); if (r.hasNext()) { e.init(r.next().getBounds()); } while (r.hasNext()) { e.include(r.next().getBounds()); } return e; } finally { r.close(); } }
bounds.include(geomBounds);
@SuppressWarnings("unchecked") private ReferencedEnvelope getBounds(FeatureSource source) { try { ReferencedEnvelope boundingBox = new ReferencedEnvelope(DefaultGeographicCRS.WGS84); FeatureCollection features = source.getFeatures(); FeatureIterator iterator = features.features(); try { while (iterator.hasNext()) { Feature f = iterator.next(); boundingBox.include(f.getBounds()); } } finally { iterator.close(); } return boundingBox; } catch (IOException e) { throw new RuntimeException(e); } }
@Override protected ReferencedEnvelope getBoundsInternal(Query query) throws IOException { if (query.getFilter() == Filter.INCLUDE) { // filtering not implemented ReferencedEnvelope bounds = ReferencedEnvelope.create(getSchema().getCoordinateReferenceSystem()); FeatureReader<SimpleFeatureType, SimpleFeature> featureReader = getReaderInternal(query); try { while (featureReader.hasNext()) { SimpleFeature feature = featureReader.next(); bounds.include(feature.getBounds()); } } finally { featureReader.close(); } return bounds; } return null; // feature by feature scan required to count records }
@Override protected ReferencedEnvelope getBoundsInternal(Query query) throws IOException { if (query.getFilter() == Filter.INCLUDE) { // filtering not implemented FeatureReader<SimpleFeatureType, SimpleFeature> featureReader = getReaderInternal(query); CoordinateReferenceSystem crs = featureReader.getFeatureType().getCoordinateReferenceSystem(); ReferencedEnvelope bounds = ReferencedEnvelope.create(crs); try { while (featureReader.hasNext()) { SimpleFeature feature = featureReader.next(); bounds.include(feature.getBounds()); } } finally { featureReader.close(); } return bounds; } return null; // feature by feature scan required to count records }
public void testBounds() { MemoryFeatureCollection rivers = new MemoryFeatureCollection(riverType); ReferencedEnvelope expected = new ReferencedEnvelope(); for (int i = 0; i < riverFeatures.length; i++) { rivers.add(riverFeatures[i]); expected.include(riverFeatures[i].getBounds()); } assertEquals(riverFeatures.length, rivers.size()); // Should not throw an UnsupportedOperationException assertNotNull(rivers.getBounds()); assertEquals(expected, rivers.getBounds()); }
bounds.include(feature.getBounds()); bounds.expandToInclude(geom.getEnvelopeInternal());