private void checkLinearRing(LinearRing<P> ring, CoordinateReferenceSystem<P> crs) { if (ring == null) throw new IllegalArgumentException("NULL linear ring is not valid."); if (ring.isEmpty()) throw new IllegalArgumentException("Empty linear ring is not valid."); if (!ring.getCoordinateReferenceSystem().equals(crs)) throw new IllegalArgumentException("Linear ring with different CRS than exterior boundary."); }
private void checkCompatibleCRS(Geometry<?> geometry, Geometry<?> other) { if (!geometry.getCoordinateReferenceSystem().equals(other.getCoordinateReferenceSystem())) { throw new IllegalArgumentException("Geometries have different CRS's"); } }
@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; }
/** * Verifies that the <code>Geometry</code> array can be used to construct a Geometry collection. * <p/> * <p>Conditions:</p> * <il> * <li>Array contains no NULL values</li> * <li>All non-empty elements have the same coordinate reference system/li> * </il> * * @param geometries * @throws IllegalStateException When geometries contains a null value or when the given geometries do not share the * same {@link CrsId} */ private void check(G[] geometries) { if (geometries == null || geometries.length == 0) return; String msg = "NULL element not allowd in Geometry array"; if (geometries[0] == null) throw new IllegalStateException(msg); CoordinateReferenceSystem<P> crs = geometries[0].getCoordinateReferenceSystem(); for (int i = 1; i < geometries.length; i++) { if (geometries[i] == null) throw new IllegalStateException(msg); if (!(geometries[i].isEmpty() || crs.equals(geometries[i].getCoordinateReferenceSystem()))) { throw new IllegalStateException("Geometries in the array do no share the same coordinate reference systems."); } } }
private CoordinateReferenceSystem<?> ensureZM(CoordinateReferenceSystem<?> crs, boolean needZ, boolean needM) { CoordinateReferenceSystem<?> compound = crs; if (needZ && ! hasVerticalAxis(compound)) { compound = addVerticalSystem(compound, Unit.METER); } if (needM && ! hasMeasureAxis(compound)) { compound = addLinearSystem(compound, Unit.METER); } if (forceToCRS && !compound.equals(crs)) { throw new WktDecodeException("WKT inconsistent with specified Coordinate Reference System"); } return compound; }
/** * 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()); }
/** * Intersects the specified <code>Envelope</code> with this <code>Envelope</code> and returns the result. * * @param other the Envelope to intersect with this instance * @return the set-theoretic intersection of this Envelope and the specified Envelope. * @throws IllegalArgumentException when the specified <code>Envelope</code> doesn't have the same coordinate reference system as this instance. */ public Envelope<P> intersect(Envelope<P> other) { if (this.isEmpty() || other.isEmpty()) return mkEmpty(); if (!this.getCoordinateReferenceSystem().equals(other.getCoordinateReferenceSystem())) throw new IllegalArgumentException("Envelopes have different CRS."); double minC0 = Math.max(getMinC0(), other.getMinC0()); double minC1 = Math.max(getMinC1(), other.getMinC1()); double maxC0 = Math.min(getMaxC0(), other.getMaxC0()); double maxC1 = Math.min(getMaxC1(), other.getMaxC1()); if (minC0 > maxC0 || minC1 > maxC1) return mkEmpty(); return new Envelope<P>(minC0, minC1, maxC0, maxC1, this.getCoordinateReferenceSystem()); }
public static <Q extends Position> Geometry<Q> forceToCrs(Geometry<?> geometry, CoordinateReferenceSystem<Q> crs) { if (crs == null || geometry == null) return (Geometry<Q>) geometry; if (crs.equals(geometry.getCoordinateReferenceSystem())) return (Geometry<Q>) geometry; if (geometry instanceof Simple) { Simple simple = (Simple) geometry;
/** * 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(); }
/** * {@inheritDoc} */ @Override public <P extends Position> boolean equals(Geometry<P> first, Geometry<P> second) { if (first == second) return true; if (first == null || second == null) return false; if (first.isEmpty() && second.isEmpty()) return true; if (first.isEmpty() || second.isEmpty()) return false; if (! first.getCoordinateReferenceSystem().equals(second.getCoordinateReferenceSystem())) return false; if (first.getGeometryType() != second.getGeometryType()) return false; if (first instanceof GeometryCollection) { assert(second instanceof GeometryCollection); return equals((GeometryCollection<?,?>)first, (GeometryCollection<?,?>)second); } if (first instanceof Polygon) { assert(second instanceof Polygon); return equals((Polygon<P>)first, (Polygon<P>)second); } return pointSeqEq.equals(first.getPositions(), second.getPositions()); }