private CoordinateReferenceSystem<P> getCrs(){ return this.geometry.getCoordinateReferenceSystem(); }
private void checkCompatibleCRS(Geometry<?> geometry, Geometry<?> other) { if (!geometry.getCoordinateReferenceSystem().equals(other.getCoordinateReferenceSystem())) { throw new IllegalArgumentException("Geometries have different CRS's"); } }
@SuppressWarnings("unchecked") protected static <T extends Position> CoordinateReferenceSystem<T> getCrs(Geometry<T>[] geometries) { if (geometries == null || geometries.length == 0) { return (CoordinateReferenceSystem<T>)CrsRegistry.getCoordinateReferenceSystemForEPSG(-1, CoordinateReferenceSystems.PROJECTED_2D_METER); } return geometries[0].getCoordinateReferenceSystem(); }
/** * Returns the numeric identifier of the coordinate reference system of this <code>Geometry</code>. * <p/> * <p>A SRID is usually interpreted as meaning the EPSG-code for the coordinate reference system. In this * implementation, this is not enforced.</p> * * @return the numeric identifier of the coordinate reference system of this <code>Geometry</code>. */ public int getSRID() { return getCoordinateReferenceSystem().getCrsId().getCode(); }
@Override public <P extends C2D & Measured> Geometry<P> locateBetween(final Geometry<P> geometry, final double startMeasure, final double endMeasure) { if (geometry == null) throw new IllegalArgumentException("Null geometries not allowed."); if (geometry.isEmpty()) return new Point<P>(geometry.getCoordinateReferenceSystem()); if (C2D.class.isAssignableFrom(geometry.getPositionClass()) && Measured.class.isAssignableFrom(geometry.getPositionClass())) { MeasureInterpolatingVisitor visitor = new MeasureInterpolatingVisitor(geometry, startMeasure, endMeasure); geometry.accept((GeometryVisitor<P>) visitor); return (Geometry<P>) visitor.result(); } throw new IllegalArgumentException("Requires projected coordinates"); }
/** * Returns the {@code Envelope} of this instance. * @return the {@code Envelope} of this instance. */ public Envelope<P> getEnvelope() { if (isEmpty()) return new Envelope<P>(getCoordinateReferenceSystem()); PositionSequence<P> positions = getPositions(); EnvelopeVisitor<P> visitor = new EnvelopeVisitor<P>(getCoordinateReferenceSystem()); positions.accept(visitor); return visitor.result(); }
@SuppressWarnings("unchecked") public <P extends Position, G extends Geometry<P>> SqlServerGeometry encode(G geom) { SqlServerGeometry nativeGeom = new SqlServerGeometry(); if( geom.getSRID() > 0 ) { nativeGeom.setCoordinateReferenceSystem(geom.getCoordinateReferenceSystem()); } nativeGeom.setIsValid(); if ( CoordinateReferenceSystems.hasMeasureAxis(geom.getCoordinateReferenceSystem()) ) { nativeGeom.setHasMValues(); } if ( CoordinateReferenceSystems.hasVerticalAxis(geom.getCoordinateReferenceSystem()) ) { nativeGeom.setHasZValues(); } CountingPositionSequenceBuilder<?> coordinates = new CountingPositionSequenceBuilder(geom.getCoordinateReferenceSystem()); List<Figure> figures = new ArrayList<Figure>(); List<Shape> shapes = new ArrayList<Shape>(); encode( geom, -1, coordinates, figures, shapes ); encodePoints( nativeGeom, coordinates.toPositionSequence() ); encodeFigures( nativeGeom, figures ); encodeShapes( nativeGeom, shapes ); return nativeGeom; }
@Override public <P extends C2D> Geometry<P> boundary(final Geometry<P> geometry) { final BoundaryOp boundaryOp = new BoundaryOp(JTS.to(geometry)); final CoordinateReferenceSystem<P> crs = geometry.getCoordinateReferenceSystem(); return JTS.from(boundaryOp.getBoundary(), crs); }
@Override public <P extends C2D> Geometry<P> buffer(final Geometry<P> geometry, final double distance) { final BufferOp op = new BufferOp(JTS.to(geometry)); return JTS.from(op.getResultGeometry(distance), geometry.getCoordinateReferenceSystem()); }
@Override public <P extends C2D> Geometry<P> convexHull(final Geometry<P> geometry) { final ConvexHull convexHull = new ConvexHull(JTS.to(geometry)); return JTS.from(convexHull.getConvexHull(), geometry.getCoordinateReferenceSystem()); }
/** * Returns the position at the specified index in the <code>PositionSequence</code> of this <code>Geometry</code>. * * @param index the position in the <code>PositionSequence</code> (first point is at index 0). * @return the position at the specified index in the <code>PositionSequence</code> of this <code>Geometry</code>. */ public P getPositionN(int index) { if (index >= getPositions().size()) { throw new IndexOutOfBoundsException(); } double[] coords = new double[getCoordinateDimension()]; getPositions().getCoordinates(index, coords); return Positions.mkPosition(getCoordinateReferenceSystem(), coords); }
@Override public <P extends C2D> Geometry<P> difference(final Geometry<P> geometry, final Geometry<P> other) { checkCompatibleCRS(geometry, other); if (geometry.isEmpty()) return new Point<P>(geometry.getCoordinateReferenceSystem()); if (other.isEmpty()) return geometry; checkNotGeometryCollection(geometry); checkNotGeometryCollection(other); org.locationtech.jts.geom.Geometry difference = SnapIfNeededOverlayOp.overlayOp(JTS.to(geometry), JTS.to(other), OverlayOp.DIFFERENCE); return JTS.from(difference, geometry.getCoordinateReferenceSystem()); }
/** * Creates a <code>Geometry</code> having as coordinates the coordinates of the input <code>Geometry</code> in reverse order. * * @param geometry the <code>Geometry</code> to reverse * @return a <code>Geometry</code> with the same coordinates as the specified input <code>Geometry</code> but in reverse order */ @Override public <P extends C2D, G extends Geometry<P>> G reverse(G geometry) { PositionSequence<P> pos = geometry.getPositions().reverse(); if (geometry instanceof Simple) { return (G)Geometries.mkGeometry((Class<? extends Simple>)geometry.getClass(), pos, geometry.getCoordinateReferenceSystem()); } else { Complex<P, ?> complex = (Complex<P, ?>) geometry; Geometry<P>[] geoms = complex.components(); reverseOrder(reverseAll(geoms)); return (G)Geometries.mkGeometry((Class<? extends Complex>)geometry.getClass(), geoms); } }
@Override public <P extends C2D> Geometry<P> intersection(final Geometry<P> geometry, final Geometry<P> other) { checkCompatibleCRS(geometry, other); if (geometry.isEmpty() || other.isEmpty()) return new Point<P>(geometry.getCoordinateReferenceSystem()); checkNotGeometryCollection(geometry); checkNotGeometryCollection(other); org.locationtech.jts.geom.Geometry intersection = SnapIfNeededOverlayOp.overlayOp(JTS.to(geometry), JTS.to(other), OverlayOp.INTERSECTION); return JTS.from(intersection, geometry.getCoordinateReferenceSystem()); }
/** * Determines whether the candidate has the same measured 'M' suffix as the geometry in WKT. * The suffix is only added when the geometry is measured and not 3D. * <p/> * POINT(x y): 2D point, * POINT(x y z): 3D point, * POINTM(x y m): 2D measured point (with 'M' suffix), * POINT(x y z m): 3D measured point (without 'M' suffix) * * * @param candidate The candidate wkt geometry token * @param geometry The geometry to check the candidate wkt geometry token for * @param ignoreMeasureMarker when set to true, this method returns true iff the candidate token is not measured * @return The candidate is measured if and only if the geometry is measured and not 3D */ private boolean hasSameMeasuredSuffixInWkt(WktGeometryToken candidate, Geometry geometry, boolean ignoreMeasureMarker) { if (ignoreMeasureMarker) { return !candidate.isMeasured(); } CoordinateReferenceSystem<?> crs = geometry.getCoordinateReferenceSystem(); if (hasMeasureAxis(crs) && ! hasVerticalAxis(crs)) { return candidate.isMeasured(); } else { return !candidate.isMeasured(); } } }
@Override protected void writeTypeCodeAndSrid(Geometry<P> geometry, ByteBuffer output) { int typeCode = getGeometryType(geometry); CoordinateReferenceSystem<P> crs = geometry.getCoordinateReferenceSystem(); if (!this.hasWrittenSrid) { typeCode |= PostgisWkbTypeMasks.SRID_FLAG; } if (hasMeasureAxis(crs)) { typeCode |= PostgisWkbTypeMasks.M_FLAG; } if (hasVerticalAxis(crs)) { typeCode |= PostgisWkbTypeMasks.Z_FLAG; } output.putUInt(typeCode); if (!this.hasWrittenSrid) { int srid = geometry.getSRID(); // Write the SRID, the HANA default SRID is 0 output.putInt(srid < 0 ? 0 : srid); this.hasWrittenSrid = true; } }
/** * {@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()); }
@Override public <P extends C2D> Geometry<P> union(final Geometry<P> geometry, final Geometry<P> other) { checkCompatibleCRS(geometry, other); if (geometry.isEmpty()) return other; if (other.isEmpty()) return geometry; checkNotGeometryCollection(geometry); checkNotGeometryCollection(other); org.locationtech.jts.geom.Geometry union = SnapIfNeededOverlayOp.overlayOp(JTS.to(geometry), JTS.to(other), OverlayOp.UNION); return JTS.from(union, geometry.getCoordinateReferenceSystem()); }
protected void writeTypeCodeAndSrid(Geometry<P> geometry, ByteBuffer output) { int typeCode = getGeometryType(geometry); boolean hasSrid = (geometry.getSRID() > 0); CoordinateReferenceSystem<P> crs = geometry.getCoordinateReferenceSystem(); if (hasSrid && !hasWrittenSrid) { typeCode |= PostgisWkbTypeMasks.SRID_FLAG; } if (hasMeasureAxis(crs)) { typeCode |= PostgisWkbTypeMasks.M_FLAG; } if (hasVerticalAxis(crs)) { typeCode |= PostgisWkbTypeMasks.Z_FLAG; } output.putUInt(typeCode); if (hasSrid && !hasWrittenSrid) { output.putInt(geometry.getSRID()); hasWrittenSrid = true; } }
@Override public <P extends C2D> Geometry<P> symmetricDifference(final Geometry<P> geometry, final Geometry<P> other) { checkCompatibleCRS(geometry, other); if (geometry.isEmpty()) return other; if (other.isEmpty()) return geometry; checkNotGeometryCollection(geometry); checkNotGeometryCollection(other); org.locationtech.jts.geom.Geometry symDifference = SnapIfNeededOverlayOp.overlayOp(JTS.to(geometry), JTS.to(other), OverlayOp.SYMDIFFERENCE); return JTS.from(symDifference, geometry.getCoordinateReferenceSystem()); }