/** * Crops the coverage to the specified bounds * * @param coverage * @param bounds */ public static GridCoverage2D crop(final GridCoverage2D coverage, final Envelope bounds) { // checks final ReferencedEnvelope cropBounds = new ReferencedEnvelope(bounds); final ReferencedEnvelope coverageBounds = new ReferencedEnvelope(coverage.getEnvelope()); if (cropBounds.contains((org.locationtech.jts.geom.Envelope) coverageBounds)) { return coverage; } Polygon polygon = JTS.toGeometry(cropBounds); Geometry roi = polygon.getFactory().createMultiPolygon(new Polygon[] {polygon}); // perform the crops final ParameterValueGroup param = PROCESSOR.getOperation("CoverageCrop").getParameters(); param.parameter("Source").setValue(coverage); param.parameter("Envelope").setValue(bounds); param.parameter("ROI").setValue(roi); return (GridCoverage2D) PROCESSOR.doOperation(param); }
boolean isAccurateResolutionComputationSafe(ReferencedEnvelope readEnvelope) throws MismatchedDimensionException, FactoryException, TransformException { // accurate resolution computation depends on reprojection working, we need // to make sure the read envelope is sane for the source data at hand CoordinateReferenceSystem readCRS = readEnvelope.getCoordinateReferenceSystem(); ProjectionHandler handler = ProjectionHandlerFinder.getHandler( new ReferencedEnvelope(readCRS), DefaultGeographicCRS.WGS84, true); if (handler != null) { // if there are no limits or the projection is periodic, assume it's fine to read // whatever if (handler.getValidAreaBounds() == null || handler instanceof WrappingProjectionHandler) { return true; } // in this case we need to make sure the area is actually safe to perform reprojections // on try { // when assertions are enabled accuracy tests might fail this path ReferencedEnvelope validBounds = handler.getValidAreaBounds().transform(readCRS, true); return validBounds.contains((Envelope) readEnvelope); } catch (Exception e) { return false; } } else { return false; } }
/** * Check FeatureType for ... * * <p>Detailed description... * * @param layers Map of SimpleFeatureSource by "dataStoreID:typeName" * @param envelope The bounding box that encloses the unvalidated data * @param results Used to coallate results information * @return <code>true</code> if all the features pass this test. * @throws Exception DOCUMENT ME! */ public boolean validate( Map layers, ReferencedEnvelope envelope, final ValidationResults results) throws Exception { LineStringGraphGenerator lgb = new LineStringGraphGenerator(); SimpleFeatureSource fs = (SimpleFeatureSource) layers.get(typeName); SimpleFeatureCollection fr = fs.getFeatures(); SimpleFeatureCollection fc = fr; SimpleFeatureIterator f = fc.features(); while (f.hasNext()) { SimpleFeature ft = f.next(); if (envelope.contains(ft.getBounds())) { // lgb.add(ft); lgb.add(ft.getDefaultGeometry()); } } // lgb is loaded Graph g = lgb.getGraph(); return (g.getNodesOfDegree(0).size() == 0); }
if (validAreaBounds.contains((Envelope) geWGS84)) { return geometry; if (validAreaBounds.contains( 180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(-360, 0); if (translated.contains((Envelope) geWGS84)) { return geometry; } else if (validAreaBounds.contains( -180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(360, 0); if (translated.contains((Envelope) geWGS84)) { return geometry;
@Override public InfoToolResult getInfo(DirectPosition2D pos) throws Exception { InfoToolResult result = new InfoToolResult(); if (isValid()) { GridCoverage2D source = ((GridCoverageLayer) getLayer()).getCoverage(); ReferencedEnvelope env = new ReferencedEnvelope(source.getEnvelope2D()); DirectPosition2D trPos = InfoToolHelperUtils.getTransformed(pos, getContentToLayerTransform()); if (env.contains(trPos)) { Object objArray = source.evaluate(trPos); Number[] bandValues = InfoToolHelperUtils.asNumberArray(objArray); if (bandValues != null) { result.newFeature("Raw values"); for (int i = 0; i < bandValues.length; i++) { result.setFeatureValue("Band " + i, bandValues[i]); } } } } return result; } }
if (width < radius && renderingEnvelope.contains(env) && reWidth <= radius * 2) { return geometry;
public boolean contains(Coordinate c) { return envelope.contains(c); }
if (coverageFootprint.equals(preProcessed)) { if (!readingEnvelope.contains((Envelope) coverageEnvelope)) { ReferencedEnvelope cropEnvelope = new ReferencedEnvelope(
/** Test for ticket GEOT-5684 Bounds cache was wrong after features were removed from list */ @Test public void removeAndAddFeatureBounds() { // create test points createPointFeatures(WORLD, 3); // remove last feature in collection List<SimpleFeature> copy = new ArrayList<SimpleFeature>(featureList); SimpleFeature f = copy.get(2); featureCollection.remove(f); // get the new bounds (removed feature) ReferencedEnvelope postRemoveFeatureBounds = featureCollection.getBounds(); // add new feature SimpleFeature newFeature = createPointFeature(10, 4); featureCollection.add(newFeature); // get new bounds ReferencedEnvelope newFeatureBounds = featureCollection.getBounds(); // compare new bounds with old boolean isContained = newFeatureBounds.contains((Envelope) postRemoveFeatureBounds); assertTrue(isContained); // ensure new point bounds don't equal over-all bounds assertNotEquals(newFeatureBounds, newFeature.getBounds()); }
public void testBounds() throws Exception { ReprojectingFeatureCollection rfc = new ReprojectingFeatureCollection(delegate, target); ReferencedEnvelope bounds = delegate.getBounds(); // the reprojection of the full bounds is going to be bigger than the sum of the // feature by feature reprojected bounds assertTrue(bounds.transform(target, true).contains((BoundingBox) rfc.getBounds())); // make sure that the reprojected bounds contain the target CRS assertEquals(target, rfc.getBounds().getCoordinateReferenceSystem()); }
} else if (!coverageEnvelope.contains((Envelope) geometryEnvelope)) {
@Test public void testCutGeometryUTM() throws Exception { ReferencedEnvelope wgs84Envelope = new ReferencedEnvelope(8, 10, 40, 45, WGS84); ReferencedEnvelope utmEnvelope = wgs84Envelope.transform(UTM32N, true); // a geometry that will definitely go outside of the UTM32N valid area Geometry g = new WKTReader().read("LINESTRING(-170 -40, 170 40)"); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(utmEnvelope, WGS84, true); assertTrue(handler.requiresProcessing(g)); Geometry preProcessed = handler.preProcess(g); assertTrue(!preProcessed.equalsTopo(g)); assertTrue(handler.validAreaBounds.contains(preProcessed.getEnvelopeInternal())); }
/** * Returns the parent of this tile, or null if this tile is (one of) the * root of the current dataset * * @return */ public Tile getParent() { // if we got to one of the root tiles for this data set, just stop if (z == 0 || envelope.contains((BoundingBox) dataEnvelope)) return null; else return new Tile((long) Math.floor(x / 2.0), (long) Math .floor(y / 2.0), z - 1); }
@Test public void testWrapGeometrySmall() throws Exception { // projected dateline CRS CoordinateReferenceSystem FIJI = CRS.decode("EPSG:3460", true); // a small geometry that will cross the dateline Geometry g = new WKTReader() .read( "POLYGON ((2139122 5880020, 2139122 5880030, 2139922 5880030, 2139122 5880020))"); Geometry original = g.copy(); // rendering bounds only slightly bigger than geometry ReferencedEnvelope world = new ReferencedEnvelope(178, 181, -1, 1, WGS84); // make sure the geometry is not wrapped, but it is preserved ProjectionHandler handler = ProjectionHandlerFinder.getHandler(world, FIJI, true); assertTrue(handler.requiresProcessing(g)); Geometry preProcessed = handler.preProcess(g); // no cutting expected assertEquals(original, preProcessed); // post process MathTransform mt = CRS.findMathTransform(FIJI, WGS84); Geometry transformed = JTS.transform(g, mt); Geometry postProcessed = handler.postProcess(mt.inverse(), transformed); // check the geometry is in the same area as the rendering envelope assertTrue(world.contains(postProcessed.getEnvelopeInternal())); }
private PointEvent getRandomPoint() { PointEvent randomPoint = new PointEvent(); while (true) { double x = extent.getMinX() + random.nextInt((int) extent.getWidth()); double y = extent.getMinY() + random.nextInt((int) extent.getHeight()); if (extent.contains(x, y)) { randomPoint.x = x; randomPoint.y = y; break; } } return randomPoint; }
public GridCoverage2D execute(GridCoverage2D inputCoverage, Geometry cropShape) { // must be same CRS! GridCoverage2D clipped = null; cropShape = transformGeometry(cropShape, inputCoverage.getCoordinateReferenceSystem()); ReferencedEnvelope gridExtent = new ReferencedEnvelope(inputCoverage.getEnvelope()); RasterCropOperation cropOp = new RasterCropOperation(); if (gridExtent.contains(cropShape.getEnvelopeInternal())) { clipped = cropOp.execute(inputCoverage, cropShape); } else { // resize extent CoordinateReferenceSystem crs = inputCoverage.getCoordinateReferenceSystem(); ReferencedEnvelope extent = new ReferencedEnvelope(cropShape.getEnvelopeInternal(), crs); clipped = cropOp.execute(execute(inputCoverage, extent), cropShape); } return clipped; }
private void assertBBox(Feature f, ReferencedEnvelope... envelopes) throws Exception { Property p = f.getProperty(CSWRecordDescriptor.RECORD_BBOX_NAME); MultiPolygon geometry = (MultiPolygon) p.getValue(); List<ReferencedEnvelope> featureEnvelopes = (List<ReferencedEnvelope>) p.getUserData().get(GenericRecordBuilder.ORIGINAL_BBOXES); ReferencedEnvelope total = null; for (int i = 0; i < envelopes.length; i++) { assertEquals(envelopes[i], featureEnvelopes.get(i)); ReferencedEnvelope re = envelopes[i].transform(CSWRecordDescriptor.DEFAULT_CRS, true); if(total == null) { total = re; } else { total.expandToInclude(re); } } assertTrue(total.contains(geometry.getEnvelopeInternal())); }
private void assertBBox(Feature f, ReferencedEnvelope... envelopes) throws Exception { PropertyName bbox = ff.property("gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox", MetaDataDescriptor.NAMESPACES); Property p = (Property) bbox.evaluate(f); MultiPolygon geometry = (MultiPolygon) p.getValue(); List<ReferencedEnvelope> featureEnvelopes = (List<ReferencedEnvelope>) p.getUserData().get(GenericRecordBuilder.ORIGINAL_BBOXES); ReferencedEnvelope total = null; for (int i = 0; i < envelopes.length; i++) { assertEquals(envelopes[i], featureEnvelopes.get(i)); ReferencedEnvelope re = envelopes[i].transform(CSWRecordDescriptor.DEFAULT_CRS, true); if(total == null) { total = re; } else { total.expandToInclude(re); } } assertTrue(total.contains(geometry.getEnvelopeInternal())); }