public Envelope getEnvelopeInternal() { return polygon.getEnvelopeInternal(); }
public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx) throws SQLException, IOException { // String wkb = rs.getString( column ); byte[] wkb = rs.getBytes(column); try { // TODO: srid Polygon polygon = (Polygon) new WKBReader().read(wkb); return polygon.getEnvelopeInternal(); } catch (ParseException e) { String msg = "Error decoding wkb for envelope"; throw (IOException) new IOException(msg).initCause(e); } }
public Object getProperty(Object object, QName name) { // check for a polygon if (object instanceof Polygon) { object = ((Polygon) object).getEnvelopeInternal(); } Envelope e = (Envelope) object; if ("Envelope".equals(name.getLocalPart()) && !e.isNull()) { return e; } if ("Null".equals(name.getLocalPart()) && e.isNull()) { return e; } return null; } }
protected Node find(Polygon polygon) { List close = index.query(polygon.getEnvelopeInternal()); for (Iterator itr = close.iterator(); itr.hasNext(); ) { Node node = (Node) itr.next(); Polygon p = (Polygon) node.getObject(); if (rel.equal(polygon, p)) { return node; } } return null; }
/** * Rectangle ordinates for polygon. * * <p>You should in sure that the provided <code>polygon</code> is a rectangle using * isRectangle( Polygon ) * * <p> * * @param list List to add coordiantes to * @param polygon Polygon to be encoded */ private static void addCoordinatesInterpretation3(List list, Polygon poly) { Envelope e = poly.getEnvelopeInternal(); list.add(new double[] {e.getMinX(), e.getMinY()}); list.add(new double[] {e.getMaxX(), e.getMaxY()}); }
/** * 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; }
public Graphable remove(Object obj) { Node node = (Node) get(obj); if (node != null) { Polygon polygon = (Polygon) node.getObject(); index.remove(polygon.getEnvelopeInternal(), node); builder.removeNode(node); } return node; }
protected void relate(Node node) { Polygon polygon = (Polygon) node.getObject(); List close = index.query(polygon.getEnvelopeInternal()); for (Iterator itr = close.iterator(); itr.hasNext(); ) { Node n = (Node) itr.next(); Polygon p = (Polygon) n.getObject(); if (!rel.equal(polygon, p) && rel.related(polygon, p)) { Edge edge = builder.buildEdge(node, n); builder.addEdge(edge); builder.addEdge(edge); } } } }
public Graphable add(Object obj) { Node node = (Node) get(obj); if (node == null) { node = builder.buildNode(); builder.addNode(node); node.setObject(obj); relate(node); // TODO: the envelope should be buffered by some tolerance index.insert(((Polygon) obj).getEnvelopeInternal(), node); } return node; }
private ReferencedEnvelope reduceEnvelope( ReferencedEnvelope envelope, ProjectionHandler handler) throws TransformException, FactoryException { Polygon polygon = JTS.toGeometry(envelope); Geometry geom = handler.preProcess(polygon); if (geom == null) { return null; } PolygonExtractor pe = new PolygonExtractor(); Polygon largest = null; for (Polygon p : pe.getPolygons(geom)) { if (largest == null || largest.getArea() > p.getArea()) { largest = p; } } ReferencedEnvelope reduced = new ReferencedEnvelope( largest.getEnvelopeInternal(), envelope.getCoordinateReferenceSystem()); return reduced; }
private double[] getTranslationFactors(Polygon reference, Polygon displaced) { // compare the two envelopes Envelope re = reference.getEnvelopeInternal(); Envelope de = displaced.getEnvelopeInternal(); double dw = Math.abs(re.getWidth() - de.getWidth()); double dh = Math.abs(re.getHeight() - de.getHeight()); if (dw > EPS * re.getWidth() || dh > EPS * re.getWidth()) { // this was not just a translation return null; } // compute the translation double dx = de.getMinX() - re.getMinX(); double dy = de.getMinY() - re.getMinY(); Polygon cloned = (Polygon) displaced.copy(); cloned.apply(AffineTransformation.translationInstance(-dx, -dy)); if (1 - new HausdorffSimilarityMeasure().measure(cloned, reference) > EPS) { return null; } else { return new double[] {dx, dy}; } }
if (displayGeomEnv.contains(poly.getEnvelopeInternal())) {
for (Polygon p : polygons) { ReferencedEnvelope cropEnvelope = new ReferencedEnvelope(p.getEnvelopeInternal(), readerCRS); cropEnvelope = new ReferencedEnvelope(
@Test public void box() throws Exception { Polygon p = builder.box( RECT_ENV.getMinX(), RECT_ENV.getMinY(), RECT_ENV.getMaxX(), RECT_ENV.getMaxY()); assertBounds(RECT_ENV, p.getEnvelopeInternal(), 1.0e-8); }
@Test public void circle() throws Exception { double radius = SQUARE_ENV.getWidth() / 2; Polygon p = builder.circle( SQUARE_ENV.getMinX() + radius, SQUARE_ENV.getMinY() + radius, radius, getNumSides(SQUARE_ENV)); assertBounds(SQUARE_ENV, p.getEnvelopeInternal(), 0.01); }
@Test public void ellipse() throws Exception { Polygon p = builder.ellipse( RECT_ENV.getMinX(), RECT_ENV.getMinY(), RECT_ENV.getMaxX(), RECT_ENV.getMaxY(), getNumSides(RECT_ENV)); assertBounds(RECT_ENV, p.getEnvelopeInternal(), 0.01); }
@Test public void boxZ() throws Exception { Polygon p = builder.boxZ( RECT_ENV.getMinX(), RECT_ENV.getMinY(), RECT_ENV.getMaxX(), RECT_ENV.getMaxY(), 42); assertBounds(RECT_ENV, p.getEnvelopeInternal(), 1.0e-8); assertEquals(42, (int) p.getCoordinate().z); }
@Test public void smoothPolygon() { Coordinate[] coords = getPolyCoords(); Polygon poly = factory.createPolygon(factory.createLinearRing(coords), null); Geometry smoothed = JTS.smooth(poly, 0); assertTrue(smoothed instanceof Polygon); CoordList list = new CoordList(smoothed.getCoordinates()); assertTrue(list.containsAll(coords)); Envelope polyEnv = poly.getEnvelopeInternal(); Envelope smoothEnv = smoothed.getEnvelopeInternal(); assertTrue(smoothEnv.covers(polyEnv)); }
bounds.expandToInclude(geom.getEnvelopeInternal());
Envelope e2 = new Envelope(3.25, 3.75, 1.25, 1.75); assertTrue(e1.contains(e2)); assertTrue(p.getEnvelopeInternal().contains(e2)); assertTrue(p.getEnvelopeInternal().intersects(e1)); BBOXImpl bbox1 = (BBOXImpl)