/** * 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(); } }
/** Returns the minimal ordinate along the specified dimension. */ public double getMinimum(final int dimension) { switch (dimension) { case 0: return getMinX(); case 1: return getMinY(); case 2: return getMinZ(); default: throw new IndexOutOfBoundsException(String.valueOf(dimension)); } }
/** Compares the specified object with this envelope for equality. */ @Override public boolean equals(final Object other) { if (!(other instanceof ReferencedEnvelope3D)) { return false; } ReferencedEnvelope3D otherEnvelope = (ReferencedEnvelope3D) other; if (isNull()) { return otherEnvelope.isNull(); } if (super.equals(other) && minz == otherEnvelope.getMinZ() && minz == otherEnvelope.getMinZ()) { final CoordinateReferenceSystem otherCRS = (other instanceof ReferencedEnvelope3D) ? ((ReferencedEnvelope3D) other).crs : null; return CRS.equalsIgnoreMetadata(crs, otherCRS); } return false; }
/** * A coordinate position consisting of all the maximal ordinates for each dimension for all * points within the {@code Envelope}. */ public DirectPosition getUpperCorner() { return new DirectPosition3D(crs, getMaxX(), getMaxY(), getMinZ()); }
/** * A coordinate position consisting of all the minimal ordinates for each dimension for all * points within the {@code Envelope}. */ public DirectPosition getLowerCorner() { return new DirectPosition3D(crs, getMinX(), getMinY(), getMinZ()); }
/** Returns the center ordinate along the specified dimension. */ public double getMedian(final int dimension) { switch (dimension) { case 0: return 0.5 * (getMinX() + getMaxX()); case 1: return 0.5 * (getMinY() + getMaxY()); case 2: return 0.5 * (getMinZ() + getMaxZ()); default: throw new IndexOutOfBoundsException(String.valueOf(dimension)); } }
/** * 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 boolean equals(Object obj) { if (obj == EVERYTHING) { return true; } if (obj instanceof ReferencedEnvelope3D) { ReferencedEnvelope3D other = (ReferencedEnvelope3D) obj; if (other.crs != EVERYTHING.crs) return false; if (other.getMinX() != EVERYTHING.getMinX()) return false; if (other.getMinY() != EVERYTHING.getMinY()) return false; if (other.getMinZ() != EVERYTHING.getMinZ()) return false; if (other.getMaxX() != EVERYTHING.getMaxX()) return false; if (other.getMaxY() != EVERYTHING.getMaxY()) return false; if (other.getMaxZ() != EVERYTHING.getMaxZ()) return false; return true; } return super.equals(obj); }
/** * 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); }
/** * 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; } } }
/** * Translates this envelope by given amounts in the X and Y direction. * * @param transX the amount to translate along the X axis * @param transY the amount to translate along the Y axis * @param transZ the amount to translate along the Z axis */ public void translate(double transX, double transY, double transZ) { if (isNull()) { return; } init( getMinX() + transX, getMaxX() + transX, getMinY() + transY, getMaxY() + transY, getMinZ() + transZ, getMaxZ() + transZ); }
@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); }
private void updateFields() { ReferencedEnvelope e = (ReferencedEnvelope) getModelObject(); if (e != null) { this.minX = e.getMinX(); this.minY = e.getMinY(); this.maxX = e.getMaxX(); this.maxY = e.getMaxY(); this.crs = e.getCoordinateReferenceSystem(); if (is3D()) { if (e instanceof ReferencedEnvelope3D) { this.minZ = ((ReferencedEnvelope3D) e).getMinZ(); this.maxZ = ((ReferencedEnvelope3D) e).getMaxZ(); } else { this.minZ = Double.NaN; this.maxZ = Double.NaN; } } else { this.minZ = Double.NaN; this.maxZ = Double.NaN; } } }