public Envelope<P> result() { return new Envelope<P>(xMin, yMin, xMax, yMax, crs); } }
private Envelope<P> mkEmpty() { return new Envelope<P>(Double.NaN, Double.NaN, Double.NaN, Double.NaN, getCoordinateReferenceSystem()); }
/** * Converts a JTS <code>Envelope</code> to a geolatte <code>Envelope</code>. * * @param jtsEnvelope the JTS Envelope to convert * @return the corresponding geolatte Envelope. * @throws IllegalArgumentException when a null object is passed */ public static org.geolatte.geom.Envelope<C2D> from(org.locationtech.jts.geom.Envelope jtsEnvelope) { if (jtsEnvelope == null) { throw new IllegalArgumentException("Null object passed."); } return new org.geolatte.geom.Envelope<C2D>(jtsEnvelope.getMinX(), jtsEnvelope.getMinY(), jtsEnvelope.getMaxX (), jtsEnvelope.getMaxY(), CoordinateReferenceSystems.PROJECTED_2D_METER); }
private Envelope<P> envelopeOf(String mortoncode, int index, Envelope<P> extent) { assert (extent != null); if (index >= mortoncode.length()) { return extent; } char c = mortoncode.charAt(index); double minX = extent.lowerLeft().getCoordinate(0); double minY = extent.lowerLeft().getCoordinate(1); double w = (extent.extentAlongDimension(0)) / 2.0; double h = (extent.extentAlongDimension(1)) / 2.0; CoordinateReferenceSystem<P> crs = extent.getCoordinateReferenceSystem(); switch (c) { case '0': return envelopeOf(mortoncode, ++index, new Envelope<P>(minX, minY, minX + w, minY + h, crs)); case '1': return envelopeOf(mortoncode, ++index, new Envelope<P>(minX, minY + h, minX + w, minY + 2 * h, crs)); case '2': return envelopeOf(mortoncode, ++index, new Envelope<P>(minX + w, minY, minX + 2 * w, minY + h, crs)); case '3': return envelopeOf(mortoncode, ++index, new Envelope<P>(minX + w, minY + h, minX + 2 * w, minY + 2 * h, crs)); default: //this can only be a programming error! throw new IllegalStateException("Received a mortoncode element that is not 0, 1, 2 or 3."); } }
/** * Converts a JTS <code>Envelope</code> to a geolatte <code>Envelope</code> with the * specified CRS. * * @param jtsEnvelope the JTS Envelope to convert. * @param crs the <code>CoordinateReferenceSystem</code> to use for the return value. * @return the corresponding geolatte Envelope, having the CRS specified in the crsId parameter. * @throws IllegalArgumentException when a null object is passed */ public static <P extends Position> org.geolatte.geom.Envelope<P> from(org.locationtech.jts.geom.Envelope jtsEnvelope, CoordinateReferenceSystem<P> crs) { if (jtsEnvelope == null) { throw new IllegalArgumentException("Null object passed."); } return new org.geolatte.geom.Envelope<P>(jtsEnvelope.getMinX(), jtsEnvelope.getMinY(), jtsEnvelope.getMaxX(), jtsEnvelope.getMaxY(), crs); }
/** * Creates an <code>Envelope</code> that is the set-theoretic union of this {@code Envelope} with the specified {@code Envelope} * * @param other other Envelope * @return an <code>Envelope</code> that encompasses both operands. * @throws IllegalArgumentException when the operand <code>Envelope</code>s don't have the same coordinate reference system. */ public Envelope<P> union(Envelope<P> other) { if (other == null || other.isEmpty()) return this; if (!this.getCoordinateReferenceSystem().equals(other.getCoordinateReferenceSystem())) throw new IllegalArgumentException("Envelopes have different CRS."); double minC0 = Math.min(getMinC0(), other.getMinC0()); double minC1 = Math.min(getMinC1(), other.getMinC1()); double maxC0 = Math.max(getMaxC0(), other.getMaxC0()); double maxC1 = Math.max(getMaxC1(), other.getMaxC1()); return new Envelope<P>(minC0, minC1, maxC0, maxC1, this.getCoordinateReferenceSystem()); }
/** * Intersects the specified <code>Envelope</code> with this <code>Envelope</code> and returns the result. * * @param other the Envelope to intersect with this instance * @return the set-theoretic intersection of this Envelope and the specified Envelope. * @throws IllegalArgumentException when the specified <code>Envelope</code> doesn't have the same coordinate reference system as this instance. */ public Envelope<P> intersect(Envelope<P> other) { if (this.isEmpty() || other.isEmpty()) return mkEmpty(); if (!this.getCoordinateReferenceSystem().equals(other.getCoordinateReferenceSystem())) throw new IllegalArgumentException("Envelopes have different CRS."); double minC0 = Math.max(getMinC0(), other.getMinC0()); double minC1 = Math.max(getMinC1(), other.getMinC1()); double maxC0 = Math.min(getMaxC0(), other.getMaxC0()); double maxC1 = Math.min(getMaxC1(), other.getMaxC1()); if (minC0 > maxC0 || minC1 > maxC1) return mkEmpty(); return new Envelope<P>(minC0, minC1, maxC0, maxC1, this.getCoordinateReferenceSystem()); }
/** * Returns the {@code Envelope} of this instance. * @return the {@code Envelope} of this instance. */ public Envelope<P> getEnvelope() { if (isEmpty()) return new Envelope<P>(getCoordinateReferenceSystem()); PositionSequence<P> positions = getPositions(); EnvelopeVisitor<P> visitor = new EnvelopeVisitor<P>(getCoordinateReferenceSystem()); positions.accept(visitor); return visitor.result(); }
private <P extends Position> PositionSequence<P> env2Seq(P p0, P p1, boolean asExteriorRing) { Envelope<P> env = new Envelope<P>(p0, p1, (CoordinateReferenceSystem<P>) crs); if (asExteriorRing) { return fixedSized(5, (Class<P>) crs.getPositionClass()) .add(env.lowerLeft()) .add(env.lowerRight()) .add(env.upperRight()) .add(env.upperLeft()) .add(env.lowerLeft()).toPositionSequence(); } else { return fixedSized(5, (Class<P>) crs.getPositionClass()) .add(env.lowerLeft()) .add(env.upperLeft()) .add(env.upperRight()) .add(env.lowerRight()) .add(env.lowerLeft()).toPositionSequence(); } }