/** * Returns the polygon surrounding the specified rectangle. Code lifted from ArcGridDataSource * (temporary). */ public static Polygon getPolygon(final Rectangle2D rect, final int srid) { final PrecisionModel pm = new PrecisionModel(); final GeometryFactory gf = new GeometryFactory(pm, srid); final Coordinate[] coord = new Coordinate[] { new Coordinate(rect.getMinX(), rect.getMinY()), new Coordinate(rect.getMaxX(), rect.getMinY()), new Coordinate(rect.getMaxX(), rect.getMaxY()), new Coordinate(rect.getMinX(), rect.getMaxY()), new Coordinate(rect.getMinX(), rect.getMinY()) }; final LinearRing ring = gf.createLinearRing(coord); return new Polygon(ring, null, gf); }
/** * Convert the crop envelope into a polygon and the use the world-to-grid transform to get a ROI * for the source coverage. */ public static Polygon getPolygon(final GeneralEnvelope env, final GeometryFactory gf) throws IllegalStateException, MismatchedDimensionException { final Rectangle2D rect = env.toRectangle2D(); final Coordinate[] coord = new Coordinate[] { new Coordinate(rect.getMinX(), rect.getMinY()), new Coordinate(rect.getMinX(), rect.getMaxY()), new Coordinate(rect.getMaxX(), rect.getMaxY()), new Coordinate(rect.getMaxX(), rect.getMinY()), new Coordinate(rect.getMinX(), rect.getMinY()) }; final LinearRing ring = gf.createLinearRing(coord); final Polygon modelSpaceROI = new Polygon(ring, null, gf); // check that we have the same thing here assert modelSpaceROI .getEnvelopeInternal() .equals(new ReferencedEnvelope(rect, env.getCoordinateReferenceSystem())); return modelSpaceROI; }
private Polygon createPolygon(float... coords) { LinearRing shell = new LinearRing(new LiteCoordinateSequence(coords), geometryFactory); return new Polygon(shell, null, geometryFactory); }
final Polygon bounds = new Polygon(ring, null, gf);
/** * Constructs a <code>Polygon</code> with the given exterior boundary and * interior boundaries. * * @param shell * the outer boundary of the new <code>Polygon</code>, or * <code>null</code> or an empty <code>LinearRing</code> if * the empty geometry is to be created. * @param holes * the inner boundaries of the new <code>Polygon</code>, or * <code>null</code> or empty <code>LinearRing</code> s if * the empty geometry is to be created. * @throws IllegalArgumentException if a ring is invalid */ public Polygon createPolygon(LinearRing shell, LinearRing[] holes) { return new Polygon(shell, holes, this); }
new LinearRing( new LiteCoordinateSequence(0, 0, 0, h, w, h, w, 0, 0, 0), GEOMETRY_FACTORY); Polygon polygon = new Polygon(shell, null, GEOMETRY_FACTORY); SimpleFeatureType ft = DataUtilities.createType("test", "geom:Polygon:srid=4326"); SimpleFeatureBuilder fb = new SimpleFeatureBuilder(ft);
protected Polygon copyInternal() { LinearRing shellCopy = (LinearRing) shell.copy(); LinearRing[] holeCopies = new LinearRing[this.holes.length]; for (int i = 0; i < holes.length; i++) { holeCopies[i] = (LinearRing) holes[i].copy(); } return new Polygon(shellCopy, holeCopies, factory); }
/** * Create a new polygon without hole. * * @param polygon * @return */ public static Polygon removeHolesPolygon(Polygon polygon) { return new Polygon((LinearRing) polygon.getExteriorRing(), null, polygon.getFactory()); } }
}), GEOMETRY_FACTORY); Polygon p2 = new Polygon(shell, new LinearRing[] {hole}, GEOMETRY_FACTORY);