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 ); }
incr[i] = (p1.getCoordinate(2 + i) - p.getCoordinate(2 + i)) / steps; buf[2 + i] = p.getCoordinate(2 + i);
/** * Creates an instance from specified lower-left and upper-right <code>Point</code>s. * * If the positions have coordinate dimension > 2, the Z/M coordinate values will be * set to 0 in the constructed Envelope * * @param lowerLeft the <code>Point</code> designating the lower-left coordinates * @param upperRight the <code>Point</code> designating the upper-right coordinates * of the envelope. */ public Envelope(P lowerLeft, P upperRight, CoordinateReferenceSystem<P> crs) { this(lowerLeft.getCoordinate(0), lowerLeft.getCoordinate(1), upperRight.getCoordinate(0), upperRight.getCoordinate(1), crs); }
protected double getMaxC0() { return upperRight.getCoordinate(0); }
protected double getMaxC1() { return upperRight.getCoordinate(1); }
protected double getMinC0() { return lowerLeft.getCoordinate(0); }
protected double getMinC1() { return lowerLeft.getCoordinate(1); }
private double angleInDirection(Position p) { double x = (p.getCoordinate(0) - c.x); double y = (p.getCoordinate(1) - c.y); return atan2(y, x); }
public double extentAlongDimension(int i) { if (i < 0 || i > 2) { throw new IndexOutOfBoundsException("Index negative or larger than defined extent dimension"); } return upperRight.getCoordinate(i) - lowerLeft.getCoordinate(i); }
/** * Creates a Circle through three {@code Position}s * @param p0 first {@code Position} * @param p1 second {@code Position} * @param p2 third {@code Position} * @param doCollinearityCheck if true, then first verify that points are not collinear * @throws IllegalArgumentException if {@code Position}s are collinear, and collinearity check if enabled */ public Circle(Position p0, Position p1, Position p2, boolean doCollinearityCheck){ //the collinear check is the most expensive part in this calculation. if (doCollinearityCheck && collinear(p0, p1, p2)){ throw new IllegalArgumentException("Positions are collinear in 2D"); } //note we don't check for counterclockwise direction, //because sign inversions in numerator and denominator cancel out double X1 = p1.getCoordinate(0) - p0.getCoordinate(0); double Y1 = p1.getCoordinate(1) - p0.getCoordinate(1); double X2 = p2.getCoordinate(0) - p0.getCoordinate(0); double Y2 = p2.getCoordinate(1) - p0.getCoordinate(1); double areaM = 2 * determinant(X1, Y1, X2, Y2); // 4 times area double sqrL10 = Math.pow(X1, 2) + Math.pow(Y1, 2); double sqrL20 = Math.pow(X2, 2) + Math.pow(Y2, 2); this.x = p0.getCoordinate(0) + (Y2 * sqrL10 - Y1 * sqrL20) / areaM; this.y = p0.getCoordinate(1) + (X1*sqrL20 - X2*sqrL10) / areaM; this.radius = Math.hypot(x - p0.getCoordinate(0), y - p0.getCoordinate(1)); }
/** * Returns the upper-left point of this <code>Envelope</code>. * * @return the upper-left point */ public P upperLeft() { return Positions.mkPosition(getCoordinateReferenceSystem(), lowerLeft.getCoordinate(0), upperRight.getCoordinate(1)); }
/** * Returns the lower-right point of this <code>Envelope</code>. * * @return the lower-right point */ public P lowerRight() { return Positions.mkPosition(getCoordinateReferenceSystem(), upperRight.getCoordinate(0), lowerLeft.getCoordinate(1)); }
public double getCoordinate(CoordinateSystemAxis axis) { return getCoordinate(axis.getNormalOrder()); }
/** * 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); } }
/** * Checks whether this <code>Envelope</code> contains the specifies <code>Envelope</code>. * * @param p the <code>Point</code> * @return true iff this instance contains the specified <code>Point</code> * @throws IllegalArgumentException when the specified <code>Point</code> doesn't have the same coordinate reference system as this instance. */ public boolean contains(P p) { if (!p.getClass().equals(this.getCoordinateReferenceSystem().getPositionClass())) throw new IllegalArgumentException("Position and envelope of different types"); if (isEmpty()) return false; return getMinC0() <= p.getCoordinate(0) && getMaxC0() >= p.getCoordinate(0) && getMinC1() <= p.getCoordinate(1) && getMaxC1() >= p.getCoordinate(1); }
/** * Gets the coordinate value for the specified axis * * * @param axis the CoordinateSystemAxis for which to get the coordinate * @return the coordinate value for the specified axis * @throws IllegalArgumentException if the specified axis is not present in the {@code CoordinateReferenceSystem} * of this instance * * @Deprecated Use {@code getCoordinate(CoordinateSystemAxis axis)} * */ @Deprecated public double getCoordinate(CoordinateSystemAxis axis, CoordinateReferenceSystem<?> crs) { int idx = crs.getAxisIndex(axis); if (idx == -1) throw new IllegalArgumentException("Not an axis of this coordinate reference system."); return getCoordinate(axis.getNormalOrder()); }
void setCoordinate(int index, PositionSequence<?> positions) { points[2 * index] = positions.getPositionN(index).getCoordinate(0); points[2 * index + 1] = positions.getPositionN(index).getCoordinate(1); if (hasZValues()) { //TODO ensure this conditions is satisfied if (!hasVerticalAxis(crs)) throw new IllegalStateException(); zValues[index] = positions.getPositionN(index).getCoordinate(2); } if (hasMValues()) { if (!hasMeasureAxis(crs)) throw new IllegalStateException(); int idx = hasZValues() ? 3 : 2; mValues[index] = positions.getPositionN(index).getCoordinate(idx); } }