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 maximum X-coordinate of the extent. * * @return the maximum X-coordinate of the extent */ public double getMaxX() { return extent.upperRight().getCoordinate(0); }
/** * Returns the maximum Y-coordinate of the extent. * * @return the maximum Y-coordinate of the extent */ public double getMaxY() { return extent.upperRight().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); } }
/** * 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]); }
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(); } }