/** @param crs */ public void calculateBounds(CoordinateReferenceSystem crs) throws Exception { List<LayerInfo> layers = allLayers(); if (layers.isEmpty()) { return; } LayerInfo l = layers.get(0); ReferencedEnvelope bounds = new ReferencedEnvelope(crs); for (int i = 0; i < layers.size(); i++) { l = layers.get(i); bounds.expandToInclude(transform(l.getResource().getLatLonBoundingBox(), crs)); } group.setBounds(bounds); }
+ crs2); e1.expandToInclude(e2); return e1; })
"Could not calculate bounds from layer with no bounds, " + l.getName()); bounds.expandToInclude(re);
private ReferencedEnvelope aggregateEnvelopes(LayerInfo... layers) { ReferencedEnvelope eoExpected = new ReferencedEnvelope( layers[0].getResource().getNativeBoundingBox(), layers[0].getResource().getCRS()); for (int i = 1; i < layers.length; i++) { eoExpected.expandToInclude(layers[i].getResource().getNativeBoundingBox()); } return eoExpected; } }
@Override public void include(double x, double y) { super.expandToInclude(x, y); } }
/** * Converts a {@link Envelope} into a {@link ReferencedEnvelope} * * @param envelope * @return */ ReferencedEnvelope reference(Envelope envelope) { ReferencedEnvelope env = new ReferencedEnvelope(envelope.getCoordinateReferenceSystem()); env.expandToInclude(envelope.getMinimum(0), envelope.getMinimum(1)); env.expandToInclude(envelope.getMaximum(0), envelope.getMaximum(1)); return env; }
/** * Converts a {@link Envelope} into a {@link ReferencedEnvelope} * * @param envelope * @return */ ReferencedEnvelope reference(Envelope envelope) { ReferencedEnvelope env = new ReferencedEnvelope(envelope.getCoordinateReferenceSystem()); env.expandToInclude(envelope.getMinimum(0), envelope.getMinimum(1)); env.expandToInclude(envelope.getMaximum(0), envelope.getMaximum(1)); return env; }
@Override public Object visit(Function expression, Object data) { // drill down and merge ReferencedEnvelope merged = new ReferencedEnvelope((ReferencedEnvelope) data); for (Expression param : expression.getParameters()) { ReferencedEnvelope result = (ReferencedEnvelope) param.accept(this, data); if (result != null) merged.expandToInclude(result); } // apply the current function is possible if (expression instanceof GeometryTransformation) { merged = ((GeometryTransformation) expression).invert(merged); } return merged; } }
/** Include the provided envelope, expanding as necessary. */ @Override public void expandToInclude(Envelope other) { if (other instanceof BoundingBox) { if (other.isNull()) { return; } BoundingBox bbox = (BoundingBox) other; ensureCompatibleReferenceSystem(bbox); expandToInclude(bbox.getLowerCorner()); expandToInclude(bbox.getUpperCorner()); } else { super.expandToInclude(other); } }
/** * Expand to include the provided DirectPosition * * @param pt */ public void expandToInclude(DirectPosition pt) { Coordinate coordinate = new Coordinate(pt.getOrdinate(0), pt.getOrdinate(1)); expandToInclude(coordinate); } /** Include the provided envelope, expanding as necessary. */
/** * Include the provided bounding box, expanding as necessary. * * @since 2.4 */ public void include(final BoundingBox bbox) { if (crs == null) { this.crs = bbox.getCoordinateReferenceSystem(); } else { ensureCompatibleReferenceSystem(bbox); } expandToInclude(ReferencedEnvelope.reference(bbox)); } /**
/** * Returns the layer bounds * * @return */ public void updateBounds() { ReferencedEnvelope result = reference(layers.get(0).getLayer().getEnvelope(crs)); for (int i = 1; i < layers.size(); i++) { ReferencedEnvelope layerEnvelope = reference(layers.get(i).getLayer().getEnvelope(crs)); result.expandToInclude(layerEnvelope); } this.bounds = result; this.originalEnvelope = new GeneralEnvelope(result); }
/** * Returns the non null envelope of this attribute. If the attribute's geometry is <code>null * </code> the returned Envelope <code>isNull()</code> is true. * * @return */ public synchronized BoundingBox getBounds() { if (bounds == null) { ReferencedEnvelope bbox = new ReferencedEnvelope(getType().getCoordinateReferenceSystem()); Geometry geom = (Geometry) getValue(); if (geom != null) { bbox.expandToInclude(geom.getEnvelopeInternal()); } else { bbox.setToNull(); } bounds = bbox; } return bounds; }
public Object visit(BBOX filter, Object data) { ReferencedEnvelope bbox = bbox(data); // consider doing reprojection here into data CRS? Envelope bounds = new Envelope( filter.getMinX(), filter.getMaxX(), filter.getMinY(), filter.getMaxY()); if (bbox != null) { bbox.expandToInclude(bounds); return bbox; } else { return bbox(bounds); } } /**
@Test public void testExpandToIncludeNull() throws Exception { ReferencedEnvelope r1 = new ReferencedEnvelope(DefaultGeographicCRS.WGS84); ReferencedEnvelope r2 = new ReferencedEnvelope(DefaultGeographicCRS.WGS84); assertTrue(r1.isNull()); assertTrue(r2.isNull()); r1.expandToInclude(r2); assertTrue(r1.isNull()); }
/** * Calculate bounds from features * * @return */ protected ReferencedEnvelope calculateBounds() { ReferencedEnvelope extent = ReferencedEnvelope.create(getSchema().getCoordinateReferenceSystem()); for (SimpleFeature feature : list) { if (feature == null) { continue; } ReferencedEnvelope bbox = ReferencedEnvelope.reference(feature.getBounds()); if (bbox == null || bbox.isEmpty() || bbox.isNull()) { continue; } extent.expandToInclude(bbox); } return extent; }
public void changed(FeatureEvent featureEvent) { type = featureEvent.getType(); if (bounds == null) { bounds = featureEvent.getBounds(); } else { bounds.expandToInclude(featureEvent.getBounds()); } filter = featureEvent.getFilter(); source = featureEvent.getFeatureSource(); count++; }
@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 } }
BufferedImage render(FeatureSource[] sources, Style[] styles) throws Exception { DefaultMapContext map = new DefaultMapContext(); ReferencedEnvelope env = sources[0].getBounds(); for (int i = 1; i < sources.length; i++) { env.expandToInclude(sources[i].getBounds()); } map.setAreaOfInterest(env); map.setCoordinateReferenceSystem(env.getCoordinateReferenceSystem()); for (int i = 0; i < sources.length; i++) { if (styles[i] != null) { map.addLayer(sources[i], styles[i]); } } try { StreamingRenderer r = new StreamingRenderer(); r.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); r.setContext(map); return RendererBaseTest.showRender("testPointLabeling", r, 5000, env); } finally { map.dispose(); } }
public void testGetFeaturesWithMax() throws Exception { Query q = new Query(featureSource.getSchema().getTypeName()); q.setMaxFeatures(2); SimpleFeatureCollection features = featureSource.getFeatures(q); // check size assertEquals(2, features.size()); // check actual iteration try (SimpleFeatureIterator it = features.features()) { int count = 0; ReferencedEnvelope env = new ReferencedEnvelope(features.getSchema().getCoordinateReferenceSystem()); while (it.hasNext()) { SimpleFeature f = it.next(); env.expandToInclude(ReferencedEnvelope.reference(f.getBounds())); count++; } assertEquals(2, count); assertTrue(areReferencedEnvelopesEqual(env, features.getBounds())); } }