/** * Writes an BoundingBox instance as GeoJSON returning the result as a string. * * @param bbox The bounding box. * @return The bounding box encoded as GeoJSON */ public String toString(BoundingBox bbox) { return new StringBuffer() .append("[") .append(bbox.getMinX()) .append(",") .append(bbox.getMinY()) .append(",") .append(bbox.getMaxX()) .append(",") .append(bbox.getMaxY()) .append("]") .toString(); }
/** * Creates a new envelope from an existing bounding box. * * <p>NOTE: if the bounding box is empty, the resulting ReferencedEnvelope will not be. In case * this is needed use {@link #create(org.opengis.geometry.Envelope, CoordinateReferenceSystem) * ReferencedEnvelope.create(bbox, bbox.getCoordinateReferenceSystem())} * * @param bbox The bounding box to initialize from. * @throws MismatchedDimensionException if the CRS dimension is not valid. * @since 2.4 */ public ReferencedEnvelope(final BoundingBox bbox) throws MismatchedDimensionException { this( bbox.getMinX(), bbox.getMaxX(), bbox.getMinY(), bbox.getMaxY(), bbox.getCoordinateReferenceSystem()); }
/** * writes the <code>gml:boundedBy</code> element to output based on <code>fc.getBounds() * </code> * * @param bounds * @throws RuntimeException if it is thorwn while writing the element or coordinates */ public void writeBounds(BoundingBox bounds) { try { String boundedBy = geometryTranslator.getDefaultPrefix() + ":" + "boundedBy"; contentHandler.startElement("", "", boundedBy, NULL_ATTS); Envelope env = null; if (bounds != null) { env = new Envelope( new Coordinate(bounds.getMinX(), bounds.getMinY()), new Coordinate(bounds.getMaxX(), bounds.getMaxY())); } geometryTranslator.encode(env, srsName); contentHandler.endElement("", "", boundedBy); } catch (SAXException se) { throw new RuntimeException(se); } }
new ReferencedEnvelope( requestedBBox.getMinX(), requestedBBox.getMaxX(), requestedBBox.getMinY(), requestedBBox.getMaxY(),
public boolean contains(BoundingBox bounds) { ensureCompatibleReferenceSystem(bounds); if (isEmpty() || bounds.isEmpty()) { return false; } return bounds.getMinX() >= this.getMinX() && bounds.getMaxX() <= this.getMaxX() && bounds.getMinY() >= this.getMinY() && bounds.getMaxY() <= this.getMaxY(); }
new ReferencedEnvelope( requestedBBox.getMinX(), requestedBBox.getMaxX(), requestedBBox.getMinY(), requestedBBox.getMaxY(),
/** * Returns {@code true} if the interior of this bounds intersects the interior of the provided * bounds. * * <p>Note this method conflicts with {@link Rectangle2D#intersects(Rectangle2D)} so you may * need to call it via envelope2d.intersects( (Envelope2D) bounds ) in order to correctly check * that the coordinate reference systems match. * * @param bounds The bounds to test for intersection. * @return {@code true} if the two bounds intersect. */ public boolean intersects(BoundingBox bounds) { ensureCompatibleReferenceSystem(bounds); if (isNull() || bounds.isEmpty()) { return false; } return !(bounds.getMinX() > this.getMaxX() || bounds.getMaxX() < this.getMinX() || bounds.getMinY() > this.getMaxY() || bounds.getMaxY() < this.getMinY()); }
/** * Converts a {@link BoundingBox} to a JTS polygon using the given JTS geometry factory. * * <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. * @since 2.8 * @throws IllegalArgumentException if either {@code bbox} or {@code factory} is {@code null} */ public static Polygon toGeometry(BoundingBox bbox, final GeometryFactory factory) { ensureNonNull("bbox", bbox); ensureNonNull("factory", factory); Polygon polygon = factory.createPolygon( factory.createLinearRing( new Coordinate[] { new Coordinate(bbox.getMinX(), bbox.getMinY()), new Coordinate(bbox.getMaxX(), bbox.getMinY()), new Coordinate(bbox.getMaxX(), bbox.getMaxY()), new Coordinate(bbox.getMinX(), bbox.getMaxY()), new Coordinate(bbox.getMinX(), bbox.getMinY()) }), null); polygon.setUserData(bbox.getCoordinateReferenceSystem()); return polygon; }
new ReferencedEnvelope( requestedBBox.getMinX(), requestedBBox.getMaxX(), requestedBBox.getMinY(), requestedBBox.getMaxY(),
public void include(BoundingBox bounds) { if (crs == null) { this.crs = bounds.getCoordinateReferenceSystem(); } else { ensureCompatibleReferenceSystem(bounds); } if (bounds.isEmpty()) { return; } if (isNull()) { setBounds(bounds); } else { if (bounds.getMinX() < getMinX()) { this.width = width + (getMinX() - bounds.getMinX()); this.x = bounds.getMinX(); } if (bounds.getMaxX() > getMaxX()) { this.width = width + (bounds.getMaxX() - getMaxX()); } if (bounds.getMinY() < getMinY()) { this.height = height + (getMinY() - bounds.getMinY()); this.y = bounds.getMinY(); } if (bounds.getMaxY() > getMaxY()) { this.height = height + (bounds.getMaxY() - getMaxY()); } } }
bounds.getMaxY(), bounds.getMinX(), bounds.getMaxX(), bounds.getCoordinateReferenceSystem())); } else if (bboxLiteral.getValue() instanceof Geometry) {
final double xmax = bbox.getMaxX(); final double ymin = bbox.getMinY(); final double ymax = bbox.getMaxY();
/** * Writes an BoundingBox instance as GeoJSON returning the result as a string. * * @param bbox The bounding box. * * @return The bounding box encoded as GeoJSON */ public String toString(BoundingBox bbox) { return new StringBuffer().append("[").append(bbox.getMinX()).append(",") .append(bbox.getMinY()).append(",").append(bbox.getMaxX()).append(",") .append(bbox.getMaxY()).append("]").toString(); }
BoundingBox env = (BoundingBox) value; minx = env.getMinX(); maxx = env.getMaxX(); miny = env.getMinY(); maxy = env.getMaxY();
@Test public void testToBounds() { BoundingBox testBox; try { newZealand.toBounds(crs); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (TransformException t) { // expected } try { testBox = australia.toBounds(crs); // expected assertEquals("unexpected bounds x min after toBounds", 10, testBox.getMinX(), 0); assertEquals("unexpected bounds y min after toBounds", 110, testBox.getMinY(), 0); assertEquals("unexpected bounds x max after toBounds", 40, testBox.getMaxX(), 0); assertEquals("unexpected bounds y max after toBounds", 150, testBox.getMaxY(), 0); } catch (TransformException t) { fail("Missmatch of CoordinateReferenceSystem"); } } }
private static CharSequence bounds(BoundingBox b) { if (b.isEmpty()) { return "<empty>"; } return String.format("%f,%f,%f,%f", b.getMinX(), b.getMinY(), b.getMaxX(), b.getMaxY()); }
private static CharSequence bounds(BoundingBox b) { if (b.isEmpty()) { return "<empty>"; } return String.format("%f,%f,%f,%f", b.getMinX(), b.getMinY(), b.getMaxX(), b.getMaxY()); }
/** * Creates a new envelope from an existing bounding box. * * @param bbox The bounding box to initialize from. * @throws MismatchedDimensionException if the CRS dimension is not valid. * * @since 2.4 */ public ReferencedEnvelope(final BoundingBox bbox) throws MismatchedDimensionException { this(bbox.getMinX(), bbox.getMaxX(), bbox.getMinY(), bbox.getMaxY(), bbox.getCoordinateReferenceSystem()); }
public BBOX bbox( Expression geometry, BoundingBox bounds ) { return bbox( geometry, bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMaxY(), CRS.toSRS( bounds.getCoordinateReferenceSystem() ) ); }
public static Rectangle forBoundingBox(final BoundingBox boundingBox) { return Rectangle.forLocations( new Location(Latitude.degrees(boundingBox.getMinY()), Longitude.degrees(boundingBox.getMinX())), new Location(Latitude.degrees(boundingBox.getMaxY()), Longitude.degrees(boundingBox.getMaxX()))); }