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 ); }
/** * 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 minimum Y-coordinate of the extent * * @return the minimum Y-coordinate of the extent */ public double getMinY() { return extent.lowerLeft().getCoordinate(1); }
/** * 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)); }
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); } }
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."); } }
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(); } }
/** * Returns the Morton code for the specified {@code Envelope}. * * @param envelope an {@code Envelope} value. * @return the morton code for the specified {@code Envelope} value. * @throws IllegalArgumentException if the value of the envelope parameter is null, or is not contained in * the spatial extent of this instance's {@code MortonContext} */ public String ofEnvelope(Envelope<P> envelope) { checkForNull(envelope); checkWithinExtent(envelope); // recalculate the X,Y coordinates to grid-cell coordinates. These are // the row,column-indices of grid formed by the (lowest-level) leaves // of the Quadtree int colMin = getCol(envelope.lowerLeft().getCoordinate(0)); int rowMin = getRow(envelope.lowerLeft().getCoordinate(1)); int colMax = getCol(envelope.upperRight().getCoordinate(0)); int rowMax = getRow(envelope.upperRight().getCoordinate(1)); int[] cols = {colMin, colMax}; int[] rows = {rowMin, rowMax}; // interleave the binary representation of the grid-cell coordinates long[] interLeaved = {0L, 0L}; for (int i = 0; i < 2; i++) { interLeaved[i] = interleave(cols[i], rows[i]); } //return the common prefix return commonMortonCodePrefixAsString(interLeaved[0], interLeaved[1]); }