/** Returns the specified bounding box as a JTS envelope. */ private static ReferencedEnvelope3D getJTSEnvelope(final BoundingBox3D bbox) { if (bbox == null) { throw new NullPointerException("Provided bbox envelope was null"); } if (bbox instanceof ReferencedEnvelope3D) { return (ReferencedEnvelope3D) bbox; } return new ReferencedEnvelope3D(bbox); }
/** * Computes the intersection of two {@link Envelope}s. * * @param env the envelope to intersect with * @return a new Envelope representing the intersection of the envelopes (this will be the null * envelope if either argument is null, or they do not intersect */ public ReferencedEnvelope3D intersection(ReferencedEnvelope3D env) { ensureCompatibleReferenceSystem(env); if (isNull() || env.isNull() || !intersects(env)) return new ReferencedEnvelope3D(); double intMinX = getMinX() > env.getMinX() ? getMinX() : env.getMinX(); double intMinY = getMinY() > env.getMinY() ? getMinY() : env.getMinY(); double intMinZ = minz > env.minz ? minz : env.minz; double intMaxX = getMaxX() < env.getMaxX() ? getMaxX() : env.getMaxX(); double intMaxY = getMaxY() < env.getMaxY() ? getMaxY() : env.getMaxY(); double intMaxZ = maxz < env.maxz ? maxz : env.maxz; return new ReferencedEnvelope3D( intMinX, intMaxX, intMinY, intMaxY, intMinZ, intMaxZ, env.getCoordinateReferenceSystem()); }
/** * Computes the coordinate of the centre of this envelope (as long as it is non-null * * @return the centre coordinate of this envelope <code>null</code> if the envelope is null */ public Coordinate centre() { if (isNull()) return null; return new Coordinate( (getMinX() + getMaxX()) / 2.0, (getMinY() + getMaxY()) / 2.0, (getMinZ() + getMaxZ()) / 2.0); }
@Test public void testWgs84BoundsFromCompoundCRS() throws Exception { try { MapProjection.SKIP_SANITY_CHECKS = true; CatalogBuilder cb = new CatalogBuilder(getCatalog()); ReferencedEnvelope3D bounds = new ReferencedEnvelope3D( 142892, 470783, 16, 142900, 470790, 20, CRS.decode("EPSG:7415")); // used to throw an exception here ReferencedEnvelope latLonBounds = cb.getLatLonBounds(bounds, bounds.getCoordinateReferenceSystem()); assertTrue( CRS.equalsIgnoreMetadata( CRS.decode("EPSG:4326"), latLonBounds.getCoordinateReferenceSystem())); // System.out.println(latLonBounds); } finally { MapProjection.SKIP_SANITY_CHECKS = false; } }
/** * Creates a new envelope from an existing envelope. * * @param envelope The envelope to initialize from * @throws MismatchedDimensionException if the CRS dimension is not valid. */ public ReferencedEnvelope3D(final ReferencedEnvelope3D envelope) throws MismatchedDimensionException { init(envelope); crs = envelope.getCoordinateReferenceSystem(); checkCoordinateReferenceSystemDimension(); }
/** * Creates a new envelope from an existing JTS envelope. * * @param envelope The envelope to initialize from. * @param crs The coordinate reference system. * @throws MismatchedDimensionExceptionif the CRS dimension is not valid. */ public ReferencedEnvelope3D(final Envelope envelope, final CoordinateReferenceSystem crs) throws MismatchedDimensionException { super(envelope, crs); if (envelope instanceof ReferencedEnvelope3D) { this.minz = ((ReferencedEnvelope3D) envelope).getMinZ(); this.maxz = ((ReferencedEnvelope3D) envelope).getMaxZ(); } }
@Test public void testEverything() { ReferencedEnvelope3D everything = ReferencedEnvelope3D.EVERYTHING; ReferencedEnvelope3D world = new ReferencedEnvelope3D(ReferencedEnvelope3D.EVERYTHING); assertEquals(world.getDimension(), 3); assertFalse("This is not an empty 3d envelope", everything.isEmpty()); assertTrue("This is a null 3d envelope", everything.isNull()); Coordinate center = everything.centre(); assertNotNull(center); double volume = everything.getVolume(); assertTrue("volume=" + volume, Double.isInfinite(volume)); volume = world.getVolume(); assertTrue("volume=" + volume, Double.isInfinite(volume)); double area = everything.getArea(); assertTrue("area=" + area, Double.isInfinite(area)); area = world.getArea(); assertTrue("area=" + area, Double.isInfinite(area)); everything.setBounds(new ReferencedEnvelope3D()); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { everything.setToNull(); everything.translate(1.0, 1.0, 1.0);
@Test public void empty() { // ensure empty can grab a default CRS when starting from nothing ReferencedEnvelope3D bbox = new ReferencedEnvelope3D(); // this is empty assertNull(bbox.getCoordinateReferenceSystem()); ReferencedEnvelope3D australia = new ReferencedEnvelope3D(DefaultGeographicCRS.WGS84_3D); australia.include(40, 110, 0); australia.include(10, 150, 10); bbox.include(australia); assertEquals(australia.getCoordinateReferenceSystem(), bbox.getCoordinateReferenceSystem()); assertEquals(0, bbox.getMinZ(), 0d); assertEquals(10, bbox.getMaxZ(), 0d); }
if (isEmpty()) { return new ReferencedEnvelope3D(targetCRS); } else { if (getDimension() != targetCRS.getCoordinateSystem().getDimension()) { if (lenient) { return JTS.transformTo2D(this, targetCRS, lenient, numPointsForTransformation); ErrorKeys.MISMATCHED_DIMENSION_$3, crs.getName().getCode(), Integer.valueOf(getDimension()), Integer.valueOf(targetCRS.getCoordinateSystem().getDimension()))); final ReferencedEnvelope3D target = new ReferencedEnvelope3D(transformed); final MathTransform transform = operation.getMathTransform(); JTS.transform(this, target, transform, numPointsForTransformation); target.expandToInclude(0, 0, this.minz); target.expandToInclude(0, 0, this.maxz);
@Test public void testIntersectXYZ() { ReferencedEnvelope3D envelope = new ReferencedEnvelope3D(); assertTrue(envelope.isNull()); assertFalse(envelope.intersects(1.0, 2.0, 3.0)); double z_ave = (z_min + z_max) / 2.0; envelope.init(x_min, x_max, y_min, y_max, z_min, z_max); assertTrue(envelope.intersects(x_ave, y_ave, z_ave)); assertTrue(envelope.intersects(x_min, y_min, z_min)); assertTrue(envelope.intersects(x_max, y_max, z_max)); assertFalse(envelope.intersects(-x_ave, -y_ave, -z_ave)); assertFalse(envelope.intersects(x_min - delta, y_ave, z_ave)); assertFalse(envelope.intersects(x_max + delta, y_ave, z_ave)); assertFalse(envelope.intersects(x_ave, y_min - delta, z_ave)); assertFalse(envelope.intersects(x_ave, y_max + delta, z_ave)); assertFalse(envelope.intersects(x_ave, y_ave, z_min - delta)); assertFalse(envelope.intersects(x_ave, y_ave, z_max + delta));
public ReferencedEnvelope3D get3DEnvelope(Geometry geom) { Coordinate[] coordinates = geom.getCoordinates(); ReferencedEnvelope3D env = new ReferencedEnvelope3D(); for (Coordinate coordinate : coordinates) { env.expandToInclude(coordinate); } return env; }
@Test public void include() throws Exception { ReferencedEnvelope3D australia = new ReferencedEnvelope3D(DefaultGeographicCRS.WGS84_3D); australia.include(40, 110, 0); australia.include(10, 150, 10); ReferencedEnvelope3D newZealand = new ReferencedEnvelope3D(DefaultEngineeringCRS.CARTESIAN_3D); newZealand.include(50, 165, 0); newZealand.include(33, 180, 5); try { australia.expandToInclude(newZealand); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (MismatchedReferenceSystemException t) { // expected } try { australia.include(newZealand); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (MismatchedReferenceSystemException t) { // expected } }
@Test public void intersection() throws Exception { ReferencedEnvelope3D australia = new ReferencedEnvelope3D(DefaultGeographicCRS.WGS84_3D); australia.include(40, 110, 0); australia.include(10, 150, 10); ReferencedEnvelope3D newZealand = new ReferencedEnvelope3D(DefaultEngineeringCRS.CARTESIAN_3D); newZealand.include(50, 165, 0); newZealand.include(33, 180, 5); try { australia.intersection(newZealand); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (MismatchedReferenceSystemException t) { // expected } }
@Test public void testDistanceWhenMinZOfThisIsGreaterThanMaxZOfOther() { CoordinateReferenceSystem crs = DefaultEngineeringCRS.CARTESIAN_3D; ReferencedEnvelope3D a = new ReferencedEnvelope3D(2.0, 3.0, 2.0, 3.0, 2.0, 3.0, crs); ReferencedEnvelope3D b = new ReferencedEnvelope3D(0.0, 1.0, 0.0, 1.0, 0.0, 0.5, crs); assertEquals(Math.sqrt(1 * 1 + 1 * 1 + 1.5 * 1.5), a.distance(b), 0.00001); }
/** * Enlarges this <code>Envelope</code> so that it contains the <code>other</code> Envelope. Has * no effect if <code>other</code> is wholly on or within the envelope. * * @param other the <code>Envelope</code> to expand to include */ public void expandToInclude(ReferencedEnvelope3D other) { ensureCompatibleReferenceSystem(other); if (other.isNull()) { return; } if (isNull()) { super.expandToInclude(other); minz = other.getMinZ(); maxz = other.getMaxZ(); } else { super.expandToInclude(other); if (other.minz < minz) { minz = other.minz; } if (other.maxz > maxz) { maxz = other.maxz; } } }
/** * Tests if the <code>Envelope other</code> lies wholely inside this <code>Envelope</code> * (inclusive of the boundary). * * @param other the <code>Envelope</code> to check * @return true if this <code>Envelope</code> covers the <code>other</code> */ public boolean covers(ReferencedEnvelope3D other) { if (isNull() || other.isNull()) { return false; } return super.covers(other) && other.getMinZ() >= minz && other.getMaxZ() <= maxz; }
public Expression getExpression2() { // in this case, the 3D BBOX falls back to regular 2D bbox behaviour (until there is more // support for 3D geometries) // 3DBBOX must be run as a post-filter in order to support the third coordinate. Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(envelope.getMinX(), envelope.getMinY()); coords[1] = new Coordinate(envelope.getMinX(), envelope.getMaxY()); coords[2] = new Coordinate(envelope.getMaxX(), envelope.getMaxY()); coords[3] = new Coordinate(envelope.getMaxX(), envelope.getMinY()); coords[4] = new Coordinate(envelope.getMinX(), envelope.getMinY()); LinearRing ring = null; GeometryFactory gfac = new GeometryFactory(); try { ring = gfac.createLinearRing(coords); } catch (TopologyException tex) { throw new IllegalFilterException(tex.toString()); } Polygon polygon = gfac.createPolygon(ring, null); if (envelope instanceof ReferencedEnvelope3D) { ReferencedEnvelope3D refEnv = (ReferencedEnvelope3D) envelope; polygon.setUserData(refEnv.getCoordinateReferenceSystem()); } return factory.literal(polygon); }
eps *= 0.5 * (getWidth() + getHeight()); delta[0] = getMinimum(0) - other.getMinimum(0); delta[1] = getMaximum(0) - other.getMaximum(0); delta[2] = getMinimum(1) - other.getMinimum(1); delta[3] = getMaximum(1) - other.getMaximum(1); delta[4] = getMinimum(2) - other.getMinimum(2); delta[5] = getMaximum(2) - other.getMaximum(2);