private static Geometry<C2D> toPolygon(Envelope env) { final PositionSequence<C2D> ps = PositionSequenceBuilders.fixedSized( 4, C2D.class ) .add( env.lowerLeft().getCoordinate( 0 ), env.lowerLeft().getCoordinate( 1 ) ) .add( env.lowerLeft().getCoordinate( 0 ), env.upperRight().getCoordinate( 1 ) ) .add( env.upperRight().getCoordinate( 0 ), env.upperRight().getCoordinate( 1 ) ) .add( env.lowerLeft().getCoordinate( 0 ), env.lowerLeft().getCoordinate( 1 ) ) .toPositionSequence(); return new Polygon<C2D>( ps, CoordinateReferenceSystems.PROJECTED_2D_METER ); }
/** * Checks whether this <code>Envelope</code> intersects the specifies <code>Envelope</code>. * <p/> * <p>Two instances intersect when their set-theoretic intersection is non-empty.</p> * * @param other the other <code>Envelope</code> * @return true iff this instance intersects with the other <code>Envelope</code> * @throws IllegalArgumentException when the specified <code>Envelope</code> doesn't have the same coordinate reference system as this instance. */ public boolean intersects(Envelope<P> other) { return !(isEmpty() || other.isEmpty()) && !(this.getMaxC0() < other.getMinC0() || this.getMinC0() > other.getMaxC0() || this.getMaxC1() < other.getMinC1() || this.getMinC1() > other.getMaxC1()); }
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(); } }
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."); } }
public static <P extends Position> P positionWithin(Envelope<P> bbox, Random rnd) { P ll = bbox.lowerLeft(); P ur = bbox.upperRight(); CoordinateReferenceSystem<P> crs = bbox.getCoordinateReferenceSystem(); double[] coords = new double[crs.getCoordinateDimension()]; for (int i = 0; i < coords.length; i++) { coords[i] = ll.getCoordinate(i) + (ur.getCoordinate(i) - ll.getCoordinate(i)) * rnd.nextDouble(); } return Positions.mkPosition(crs, coords); } }
/** * Returns the minimum X-coordinate of the extent * * @return the minimum X-coordinate of the extent */ public double getMinX() { return extent.lowerLeft().getCoordinate(0); } /**
/** * Returns the maximum X-coordinate of the extent. * * @return the maximum X-coordinate of the extent */ public double getMaxX() { return extent.upperRight().getCoordinate(0); }
private Envelope<P> mkEmpty() { return new Envelope<P>(Double.NaN, Double.NaN, Double.NaN, Double.NaN, getCoordinateReferenceSystem()); }
/** * Returns the CrsId of the spatial extent * * @return the CrsId of the spatial extent */ public CoordinateReferenceSystem<?> getCoordinateReferenceSystem() { return extent.getCoordinateReferenceSystem(); }
public Envelope<P> result() { return new Envelope<P>(xMin, yMin, xMax, yMax, crs); } }
/** * Checks whether the specified {@code Point} is contained in the extent. * * @param pos a {@code Point} value * @return true if the specified point is contained in the extent, false otherwise * @throws IllegalArgumentException if the specified point does not share this extent's {@code CrsId} */ public boolean extentContains(P pos) { return this.extent.contains(pos); }
/** * Constructs a {@code MortonContext} with the specified extent and max. tree-depth * * @param extent the extent for this instance * @param depth the tree-depth */ public MortonContext(Envelope<P> extent, int depth) { if (extent == null) { throw new IllegalArgumentException(ERR_MSG_NULL); } if (depth >= Integer.SIZE) { throw new IllegalArgumentException(ERR_MSG_MAX_DEPTH); } this.depth = depth; this.extent = extent; this.numOfDivisionsAlongAxis = (int) (Math.pow(2, depth)); this.leafWidth = (extent.extentAlongDimension(0)) / numOfDivisionsAlongAxis; this.leafHeight = (extent.extentAlongDimension(1)) / numOfDivisionsAlongAxis; }
/** * Checks whether this <code>Envelope</code> is contained within the specified <code>Envelope</code> * * @param other the other <code>Envelope</code> * @return true iff this instance is contained within the specified <code>Envelope</code> * @throws IllegalArgumentException when the specified <code>Envelope</code> doesn't have the same coordinate reference system as this instance. */ public boolean within(Envelope<P> other) { if (isEmpty()) return true; if (other.isEmpty()) return false; if (!this.getCoordinateReferenceSystem().equals(other.getCoordinateReferenceSystem())) throw new IllegalArgumentException("Envelopes have different CRS."); return other.getMinC0() <= this.getMinC0() && other.getMaxC0() >= this.getMaxC0() && other.getMinC1() <= this.getMinC1() && other.getMaxC1() >= this.getMaxC1(); }
/** * Returns the minimum Y-coordinate of the extent * * @return the minimum Y-coordinate of the extent */ public double getMinY() { return extent.lowerLeft().getCoordinate(1); }
/** * Returns the maximum Y-coordinate of the extent. * * @return the maximum Y-coordinate of the extent */ public double getMaxY() { return extent.upperRight().getCoordinate(1); }
public String toString() { StringBuilder builder = new StringBuilder(getCoordinateReferenceSystem().getCrsId().toString()); builder.append("LL: ") .append(this.lowerLeft.toString()) .append(" - UR: ") .append(this.upperRight.toString()); return builder.toString(); }
/** * 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); }
/** * Checks whether the specified {@code Envelope} is contained in the extent. * * @param envelope an {@code Envelope} value * @return true if the specified envelope is contained in the extent, false otherwise * @throws IllegalArgumentException if the specified envelope does not share this extent's {@code CrsId} */ public boolean extentContains(Envelope<P> envelope) { return this.extent.contains(envelope); }
/** * 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()); }
/** * Converts a Geolatte <code>Envelope</code> to a JTS <code>Envelope</code>. * * @param env the geolatte Envelope. * @return the corresponding JTS Envelope. * @throws IllegalArgumentException when a null object is passed */ public static org.locationtech.jts.geom.Envelope to(org.geolatte.geom.Envelope<?> env) { if (env == null) { throw new IllegalArgumentException("Null object passed."); } return new org.locationtech.jts.geom.Envelope(env.lowerLeft().getCoordinate(0), env.upperRight() .getCoordinate(0), env.lowerLeft().getCoordinate(1), env.upperRight().getCoordinate(1)); }