JTS.toGeometry((Envelope) new ReferencedEnvelope(grid.getEnvelope2D())); if (coverageBounds.intersects(rasterFilter)) { final ParameterValueGroup param = cropParams.clone();
/** * 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); }
/** * Create a Point from a ISO Geometry DirectPosition. * * @param position * @return Point */ public static Point toGeometry(DirectPosition position) { return toGeometry(position, null); }
/** * Converts an arbitrary Java2D shape into a JTS geometry. The created JTS geometry may be any * of {@link LineString}, {@link LinearRing} or {@link MultiLineString}. * * @param shape The Java2D shape to create. * @param factory The JTS factory to use for creating geometry. * @return The JTS geometry. * @deprecated Please use {@link #toGeometry(Shape)} or {@link #toGeometry(Shape, * GeometryFactory)} */ public static Geometry shapeToGeometry(final Shape shape, final GeometryFactory factory) { return toGeometry(shape, factory); }
/** * Converts an arbitrary Java2D shape into a JTS geometry. The created JTS geometry may be any * of {@link LineString}, {@link LinearRing} or {@link MultiLineString}. * * @param shape the input shape * @return A new JTS geometry instance * @throws IllegalArgumentException if {@code shape} is {@code null} */ public static Geometry toGeometry(final Shape shape) { return toGeometry(shape, new GeometryFactory()); }
/** * Converts a {@link ReferencedEnvelope} to a JTS polygon. * * <p>The resulting polygon contains an outer ring with vertices: * (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1) * * @param envelope The original envelope. * @return The envelope as a polygon. * @throws IllegalArgumentException if {@code bbox} is {@code null} * @since 2.4 */ public static Polygon toGeometry(ReferencedEnvelope bbox) { return toGeometry((BoundingBox) bbox, new GeometryFactory()); }
/** * Converts a {@link BoundingBox} to a JTS polygon. * * <p>The resulting polygon contains an outer ring with vertices: * (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1) * * @param envelope The original envelope. * @return The envelope as a polygon. * @throws IllegalArgumentException if {@code bbox} is {@code null} * @since 2.4 */ public static Polygon toGeometry(BoundingBox bbox) { return toGeometry(bbox, new GeometryFactory()); }
private void setRoiProvider() throws IOException { Geometry granuleGeometry = JTS.toGeometry(new ReferencedEnvelope(originalEnvelope)); roiProvider = MultiLevelROIProviderFactory.createFootprintProvider(inputFile, granuleGeometry); if (roiProvider != null) { multiLevelRoi = roiProvider.getMultiScaleROI(null); } }
@Override public Object evaluate(Object object) { if (!(object instanceof Feature)) { return null; } Feature feature = (Feature) object; ReferencedEnvelope env = ReferencedEnvelope.reference(feature.getBounds()); if (env != null) { return JTS.toGeometry(env); } else { return null; } } }
public MultiLevelROIRaster(DatasetLayout layout, File file, SimpleFeature sf) throws IOException { // Initialization this.file = file; // Getting Feature Geometry Geometry geo = (Geometry) sf.getDefaultGeometry(); // Getting as envelope env = JTS.toEnvelope(geo); // Save envelope as Geometry footprint = JTS.toGeometry(env); // Getting the Mask provider maskOvrProvider = new MaskOverviewProvider(layout, file); }
private Geometry clipToWorldFeatureTypeGeometry(Geometry geom) { // Oracle cannot deal with filters using geometries that span beyond the whole world if (isFeatureTypeGeometryGeodetic() && !WORLD.contains(geom.getEnvelopeInternal())) { Geometry result = geom.intersection(JTS.toGeometry(WORLD)); if (result != null && !result.isEmpty()) { if (result instanceof GeometryCollection) { result = distillSameTypeGeometries((GeometryCollection) result, geom); } return result; } } return geom; }
/** Try and Filter by the provided bbox, will default to Filter.EXCLUDE if null */ public static Filter filterBBox(Envelope bBox, SimpleFeatureType ft) throws FactoryRegistryException, IllegalFilterException { if (bBox == null) { return Filter.INCLUDE; } FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); PropertyName geomExpr = ff.property(ft.getGeometryDescriptor().getLocalName()); Literal bboxExpr = ff.literal(JTS.toGeometry(bBox)); Disjoint disjointFilter = ff.disjoint(geomExpr, bboxExpr); return ff.not(disjointFilter); } }
@Test public void testCutGeometryLambertConformal() throws Exception { // get a lambert conformal conic with ReferencedEnvelope wgs84South = new ReferencedEnvelope(-180, -90, -40, 0, WGS84); ReferencedEnvelope laeSouth = wgs84South.transform(CRS.decode("EPSG:2194"), true); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(laeSouth, WGS84, true); // a Geometry that crosses the opposite of the central meridian Polygon geometry = JTS.toGeometry(new Envelope(5, 15, 0, 10)); Geometry preProcessed = handler.preProcess(geometry); assertTrue( "Should have sliced the geometry in two parts", preProcessed instanceof MultiPolygon); }
@Test public void testToGeoemtry() { DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84; // straight up Polygon polygon = JTS.toGeometry(new Envelope(-10, 10, -10, 10)); assertEquals(5, polygon.getExteriorRing().getCoordinateSequence().size()); // bounding box polygon = JTS.toGeometry((BoundingBox) new ReferencedEnvelope(-10, 10, -10, 10, crs)); assertEquals(5, polygon.getExteriorRing().getCoordinateSequence().size()); }
private LineString circleArcInBounds( double x, double y, double radius, ReferencedEnvelope bounds) { Point center = gf.createPoint(new Coordinate(x, y)); Polygon buffered = (Polygon) center.buffer(radius, 64); Polygon mask = JTS.toGeometry(bounds); Geometry intersection = buffered.getExteriorRing().intersection(mask); return (LineString) intersection; }
public void testBoundedBy() { Geometry box = JTS.toGeometry(new Envelope(0, 10, 0, 10)); Intersects intersects = fac.intersects(fac.function("boundedBy"), fac.literal(box)); assertTrue(intersects.evaluate(testFeature)); } }
@Test public void toGeometry_Shape_Poly() { Shape shape = new java.awt.Polygon(XPOINTS, YPOINTS, NPOINTS); Geometry geom = JTS.toGeometry(shape); assertTrue(geom instanceof LinearRing); Coordinate[] coords = geom.getCoordinates(); assertEquals(NPOINTS + 1, coords.length); CoordList list = new CoordList(coords); Coordinate c = new Coordinate(); for (int i = 0; i < NPOINTS; i++) { c.x = XPOINTS[i]; c.y = YPOINTS[i]; assertTrue(list.contains(c)); } }
@Test public void toGeometry_BoundingBox() { BoundingBox bbox = new ReferencedEnvelope(-10, 10, -5, 5, null); Geometry geom = JTS.toGeometry(bbox); assertTrue(geom instanceof org.locationtech.jts.geom.Polygon); Envelope geomEnv = geom.getEnvelopeInternal(); assertEquals(-10.0, geomEnv.getMinX(), TOL); assertEquals(10.0, geomEnv.getMaxX(), TOL); assertEquals(-5.0, geomEnv.getMinY(), TOL); assertEquals(5.0, geomEnv.getMaxY(), TOL); }
@Test public void toGeometry_ReferencedEnvelope() { ReferencedEnvelope refEnv = new ReferencedEnvelope(-10, 10, -5, 5, DefaultGeographicCRS.WGS84); Geometry geom = JTS.toGeometry(refEnv); assertTrue(geom instanceof org.locationtech.jts.geom.Polygon); Envelope geomEnv = geom.getEnvelopeInternal(); assertEquals(-10.0, geomEnv.getMinX(), TOL); assertEquals(10.0, geomEnv.getMaxX(), TOL); assertEquals(-5.0, geomEnv.getMinY(), TOL); assertEquals(5.0, geomEnv.getMaxY(), TOL); }
@Test public void toGeometry_Envelope() { Envelope refEnv = new Envelope(-10, 10, -5, 5); Geometry geom = JTS.toGeometry(refEnv); assertTrue(geom instanceof org.locationtech.jts.geom.Polygon); Envelope geomEnv = geom.getEnvelopeInternal(); assertEquals(-10.0, geomEnv.getMinX(), TOL); assertEquals(10.0, geomEnv.getMaxX(), TOL); assertEquals(-5.0, geomEnv.getMinY(), TOL); assertEquals(5.0, geomEnv.getMaxY(), TOL); }