/** Returns the specified bounding box as a JTS envelope. */ private static Envelope getJTSEnvelope(final BoundingBox bbox) { if (bbox == null) { throw new NullPointerException("Provided bbox envelope was null"); } if (bbox instanceof Envelope) { return (Envelope) bbox; } // safe creation if empty bounds return ReferencedEnvelope.create(bbox, bbox.getCoordinateReferenceSystem()); }
/** * Include the provided bounding box, expanding as necessary. * * @since 2.4 */ public void include(final BoundingBox bbox) { if (crs == null) { this.crs = bbox.getCoordinateReferenceSystem(); } else { ensureCompatibleReferenceSystem(bbox); } expandToInclude(ReferencedEnvelope.reference(bbox)); } /**
/** * Make sure that the specified bounding box uses the same CRS than this one. * * @param bbox The other bounding box to test for compatibility. * @throws MismatchedReferenceSystemException if the CRS are incompatibles. */ private void ensureCompatibleReferenceSystem(final BoundingBox bbox) throws MismatchedReferenceSystemException { if (crs != null) { final CoordinateReferenceSystem other = bbox.getCoordinateReferenceSystem(); if (other != null) { if (!CRS.equalsIgnoreMetadata(crs, other)) { throw new MismatchedReferenceSystemException( Errors.format(ErrorKeys.MISMATCHED_COORDINATE_REFERENCE_SYSTEM)); } } } }
public void setBounds(BoundingBox bounds) { this.crs = bounds.getCoordinateReferenceSystem(); this.x = bounds.getMinX(); this.y = bounds.getMinY(); this.width = bounds.getWidth(); this.height = bounds.getHeight(); }
/** * Make sure that the specified bounding box uses the same CRS than this one. * * @param bbox The other bounding box to test for compatibility. * @throws MismatchedReferenceSystemException if the CRS are incompatible. */ protected void ensureCompatibleReferenceSystem(final BoundingBox bbox) throws MismatchedReferenceSystemException { if (crs != null) { final CoordinateReferenceSystem other = bbox.getCoordinateReferenceSystem(); if (other != null) { if (!CRS.equalsIgnoreMetadata(crs, other)) { throw new MismatchedReferenceSystemException( Errors.format(ErrorKeys.MISMATCHED_COORDINATE_REFERENCE_SYSTEM)); } } } } /**
/** Sets this envelope to the specified bounding box. */ public void init(BoundingBox bounds) { super.init( bounds.getMinimum(0), bounds.getMaximum(0), bounds.getMinimum(1), bounds.getMaximum(1)); this.crs = bounds.getCoordinateReferenceSystem(); }
/** * 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()); }
/** Sets this envelope to the specified bounding box. */ public void init(BoundingBox bounds) { init( bounds.getMinimum(0), bounds.getMaximum(0), bounds.getMinimum(1), bounds.getMaximum(1), bounds.getMinimum(2), bounds.getMaximum(2)); this.crs = bounds.getCoordinateReferenceSystem(); }
CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem(); GeneralEnvelope originalEnvelope = null;
public Object visit(BBOX filter, Object extraData) { // grab the original envelope data BoundingBox boundaries = filter.getBounds(); // parse the srs, it might be a code or a WKT definition CoordinateReferenceSystem crs = boundaries.getCoordinateReferenceSystem(); // if no srs is specified we can't transform anyways if (crs == null) return super.visit(filter, extraData); // grab the property data PropertyName propertyName = null; // get the expression as is to preserve namespace context if (filter.getExpression1() instanceof PropertyName) { propertyName = (PropertyName) filter.getExpression1(); } else if (filter.getExpression2() instanceof PropertyName) { propertyName = (PropertyName) filter.getExpression2(); } CoordinateReferenceSystem targetCrs = findPropertyCRS(propertyName); // if there is a mismatch, reproject and replace if (crs != null && targetCrs != null && !CRS.equalsIgnoreMetadata(crs, targetCrs)) { ReferencedEnvelope envelope = ReferencedEnvelope.reference(boundaries); try { envelope = envelope.transform(targetCrs, true); } catch (TransformException e) { throw new RuntimeException(e); } catch (FactoryException e) { throw new RuntimeException(e); } boundaries = envelope; } return getFactory(extraData).bbox(propertyName, boundaries); }
private void setGridGeometry( final ReferencedEnvelope envelope, final GranuleCatalog catalog, String typeName) { Utilities.ensureNonNull("index", catalog); // // save the bbox and prepare other info // final BoundingBox bounds = catalog.getBounds(typeName); // we might have an imposed bbox this.crs = bounds.getCoordinateReferenceSystem(); if (envelope == null) this.originalEnvelope = new GeneralEnvelope(bounds); else { this.originalEnvelope = new GeneralEnvelope(envelope); this.originalEnvelope.setCoordinateReferenceSystem(crs); } // original gridrange (estimated). I am using the floor here in order to make sure // we always stays inside the real area that we have for the granule originalGridRange = new GridEnvelope2D( new Rectangle( (int) (originalEnvelope.getSpan(0) / highestRes[0]), (int) (originalEnvelope.getSpan(1) / highestRes[1]))); raster2Model = new AffineTransform2D( highestRes[0], 0, 0, -highestRes[1], originalEnvelope.getLowerCorner().getOrdinate(0) + 0.5 * highestRes[0], originalEnvelope.getUpperCorner().getOrdinate(1) - 0.5 * highestRes[1]); }
bounds.getMinX(), bounds.getMaxX(), bounds.getCoordinateReferenceSystem())); } else if (bboxLiteral.getValue() instanceof Geometry) { Geometry geom = (Geometry) bboxLiteral.getValue();
CRS.transform(cropBBox, requestedBBox.getCoordinateReferenceSystem()); cropBBOXInRequestCRS.setCoordinateReferenceSystem( requestedBBox.getCoordinateReferenceSystem());
private void inspectCoordinateReferenceSystems() throws DataSourceException { requestCRS = CRS.getHorizontalCRS(requestedBBox.getCoordinateReferenceSystem());
private void inspectCoordinateReferenceSystems() throws DataSourceException { requestCRS = CRS.getHorizontalCRS(requestedBBox.getCoordinateReferenceSystem());
polygon.setUserData(bbox.getCoordinateReferenceSystem());
miny = env.getMinY(); maxy = env.getMaxY(); srs = CRS.toSRS(env.getCoordinateReferenceSystem()); } else { Envelope env = null;
/** * 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; }
assertEquals( DefaultGeographicCRS.WGS84, ((BoundingBox) worldBounds2).getCoordinateReferenceSystem());
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()); } } }