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 ); }
private void AddPointsBetweenPolarCoordinates(double theta, double theta1, P p, P p1, double maxAngleIncr, PositionSequenceBuilder<P> builder) { int dim = p.getCoordinateDimension(); incr[i] = (p1.getCoordinate(2 + i) - p.getCoordinate(2 + i)) / steps; buf[2 + i] = p.getCoordinate(2 + i);
/** * {@inheritDoc} */ @Override public <P extends Position> boolean equals(P first, P second) { if (first == second) return true; //Also if first and second are null? // Or should null arguments trigger IllegalArgumentException if ((first == null || second == null)) return false; if (first.isEmpty() && second.isEmpty()) return true; if (first.isEmpty() || second.isEmpty()) return false; return equals(first.toArray(null), second.toArray(null)); }
/** * Copies the coordinates of this {@code Position} in the specified Array, in normal order. * * <p>If the array is null or smaller than the coordinate dimension, then a new Array instance will be created.</p> * * @param dest the recipient of the coordinates of this instance (if large enough) * @return an array (possibly the same instance as specified by dest) holding the coordinates of this {@code Position} */ public double[] toArray(double[] dest) { if (isEmpty()) { return new double[0]; } int dim = getCoordinateDimension(); if (dest == null || dest.length < dim) { dest = new double[dim]; } System.arraycopy(this.coords, 0, dest, 0, dim); return dest; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Envelope envelope = (Envelope) o; if (crs != null ? !crs.equals(envelope.crs) : envelope.crs != null) return false; if (this.isEmpty() && envelope.isEmpty()) return true; if (lowerLeft != null ? !lowerLeft.equals(envelope.lowerLeft) : envelope.lowerLeft != null) return false; if (upperRight != null ? !upperRight.equals(envelope.upperRight) : envelope.upperRight != null) return false; return true; }
/** * Returns the coordinate at the specified index * * <p>Note that the index here refers to the coordinates ordered in a normalized order.</p> * * @param idx the index of the coordinate (0-based) * @return the coordinate value at the specified index. */ public double getCoordinate(int idx) { return isEmpty() ? Double.NaN : this.coords[idx]; }
/** * Constructs an instance with the specified coordinates * @param coords */ protected Position(double... coords) { if (coords.length == 0) { this.coords = new double[0]; //Arrays.fill(this.coords, Double.NaN); } else { double[] c = new double[getCoordinateDimension()]; System.arraycopy(coords, 0, c, 0, coords.length); this.coords = c; } }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Position)) return false; Position position = (Position) o; if (!Arrays.equals(coords, position.toArray(null))) return false; return true; }
/** * Checks whether this <code>LineString</code> is closed, i.e. the first <code>Point</code> equals the last. * * @return true if this <code>LineString</code> is closed. */ public boolean isClosed() { return !isEmpty() && getStartPosition().equals(getEndPosition()); }
protected double getMaxC0() { return upperRight.getCoordinate(0); }
@Override public <P extends Position> boolean equals2D(P first, P second) { if (first == second) return true; //Also if first and second are null? // Or should null arguments trigger IllegalArgumentException return !(first == null || second == null) && internalEquals(first.toArray(null), 2, second.toArray(null), 2); }
protected double getMaxC1() { return upperRight.getCoordinate(1); }
@Override public void visit(P position) { position.toArray(coordinates); xMin = Math.min(xMin, coordinates[0]); xMax = Math.max(xMax, coordinates[0]); yMin = Math.min(yMin, coordinates[1]); yMax = Math.max(yMax, coordinates[1]); }
protected double getMinC0() { return lowerLeft.getCoordinate(0); }
@Override public PositionSequenceBuilder<P> add(P pos) { pos.toArray(coords); for (double coord : coords) { addCoordinate(coord); } numAdded++; return this; }
/** * 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); }
@Override public void visit(P position) { double ar[] = position.toArray(buffer); this.env.expandToInclude(ar[0], ar[1]); }