Class Wrapper
java.lang.Object
org.apache.sis.internal.feature.AbstractGeometry
org.apache.sis.internal.feature.GeometryWrapper<org.locationtech.jts.geom.Geometry>
org.apache.sis.internal.feature.jts.Wrapper
- All Implemented Interfaces:
org.opengis.geometry.Geometry
The wrapper of Java Topology Suite (JTS) geometries.
- Since:
- 1.1
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.locationtech.jts.geom.Geometry
The wrapped implementation.private static final BiPredicate<org.locationtech.jts.geom.Geometry,
org.locationtech.jts.geom.Geometry>[] All predicates recognized byinvalid reference
#predicate(SpatialOperatorName, Geometry)
private static final String[]
The SQLMM names for the types listed in theTYPES
array.private static final Class<?>[]
The types of JTS objects to be recognized by the SQLMMST_GeometryType
operation. -
Constructor Summary
ConstructorsConstructorDescriptionWrapper
(org.locationtech.jts.geom.Geometry geometry) Creates a new wrapper around the given geometry. -
Method Summary
Modifier and TypeMethodDescriptionprivate org.locationtech.jts.geom.Geometry
convert
(GeometryType target) Converts the given geometry to the specified type without wrapper.Geometries
<org.locationtech.jts.geom.Geometry> factory()
Returns the implementation-dependent factory of geometric object.formatWKT
(double flatness) Returns the WKT representation of the wrapped geometry.double[]
Returns all coordinate tuples in the wrapped geometry.org.opengis.geometry.DirectPosition
Returns the centroid of the wrapped geometry as a direct position.org.opengis.referencing.crs.CoordinateReferenceSystem
Returns the geometry coordinate reference system, ornull
if none.private static int
getCoordinatesDimension
(org.locationtech.jts.geom.Geometry geometry) Gets the number of dimensions of geometry vertex (sequence of coordinate tuples), which can be 2 or 3.Returns the envelope of the wrapped JTS geometry.double[]
If the wrapped geometry is a point, returns its coordinates.getSRID()
Returns the Spatial Reference System Identifier (SRID) if available.Returns the geometry specified at construction time.private static boolean
isCollection
(org.locationtech.jts.geom.Geometry geometry) Returnstrue
if the given geometry is a collection other thanMultiPoint
.boolean
isSameCRS
(GeometryWrapper<org.locationtech.jts.geom.Geometry> other) Returnstrue
if the given geometry use the same CRS than this geometry, or conservatively returnsfalse
in case of doubt.protected org.locationtech.jts.geom.Geometry
mergePolylines
(Iterator<?> polylines) Merges a sequence of points or paths after the wrapped geometry.protected Object
operationSameCRS
(SQLMM operation, GeometryWrapper<org.locationtech.jts.geom.Geometry> other, Object argument) Applies a SQLMM operation on this geometry.protected boolean
predicateSameCRS
(DistanceOperatorName type, GeometryWrapper<org.locationtech.jts.geom.Geometry> other, double distance) Applies a filter predicate between this geometry and another geometry within a given distance.protected boolean
predicateSameCRS
(SpatialOperatorName type, GeometryWrapper<org.locationtech.jts.geom.Geometry> other) Applies a filter predicate between this geometry and another geometry.private Wrapper
rewrap
(org.locationtech.jts.geom.Geometry result) Returns the given geometry in new wrapper, orthis
ifg
is same as current geometry.void
setCoordinateReferenceSystem
(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Sets the coordinate reference system.private <T extends org.locationtech.jts.geom.Geometry>
org.locationtech.jts.geom.GeometryCollectiontoCollection
(org.locationtech.jts.geom.GeometryFactory factory, Class<T> type, IntFunction<T[]> newArray, BiFunction<org.locationtech.jts.geom.GeometryFactory, org.locationtech.jts.geom.Coordinate[], T> newComponent, BiFunction<org.locationtech.jts.geom.GeometryFactory, T[], org.locationtech.jts.geom.GeometryCollection> newCollection) Converts a single geometry or a geometry collection to a collection of another type.GeometryWrapper
<org.locationtech.jts.geom.Geometry> toGeometryType
(GeometryType target) Converts the given geometry to the specified type.private static int
Converts the given argument to a zero-based index.GeometryWrapper
<org.locationtech.jts.geom.Geometry> transform
(org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS) Transforms this geometry to the specified Coordinate Reference System (CRS).GeometryWrapper
<org.locationtech.jts.geom.Geometry> transform
(org.opengis.referencing.operation.CoordinateOperation operation, boolean validate) Transforms this geometry using the given coordinate operation.Methods inherited from class org.apache.sis.internal.feature.GeometryWrapper
equals, hashCode, operation, operation, operationWithArgument, operationWithArgument, predicate, predicate, toString
-
Field Details
-
geometry
private final org.locationtech.jts.geom.Geometry geometryThe wrapped implementation. -
PREDICATES
private static final BiPredicate<org.locationtech.jts.geom.Geometry,org.locationtech.jts.geom.Geometry>[] PREDICATESAll predicates recognized byinvalid reference
#predicate(SpatialOperatorName, Geometry)
Enum.ordinal()
values. -
TYPES
The types of JTS objects to be recognized by the SQLMMST_GeometryType
operation. -
SQLMM_NAMES
The SQLMM names for the types listed in theTYPES
array.
-
-
Constructor Details
-
Wrapper
Wrapper(org.locationtech.jts.geom.Geometry geometry) Creates a new wrapper around the given geometry.
-
-
Method Details
-
rewrap
Returns the given geometry in new wrapper, orthis
ifg
is same as current geometry.- Parameters:
result
- the geometry computed by a JTS operation.- Returns:
- wrapper for the given geometry. May be
this
.
-
factory
Returns the implementation-dependent factory of geometric object.- Specified by:
factory
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Returns:
- the factory of implementation-dependent geometric objects (never
null
).
-
implementation
Returns the geometry specified at construction time.- Specified by:
implementation
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Returns:
- the geometry implementation wrapped by this instance (never
null
).
-
getSRID
Returns the Spatial Reference System Identifier (SRID) if available. This is not necessarily an EPSG code, even it is common practice to use the same numerical values than EPSG. Note that the absence of SRID does not mean thatgetCoordinateReferenceSystem()
would return no CRS.- Overrides:
getSRID
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Returns:
- the Spatial Reference System Identifier of the geometry.
-
getCoordinateReferenceSystem
public org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()Returns the geometry coordinate reference system, ornull
if none.- Specified by:
getCoordinateReferenceSystem
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Returns:
- the coordinate reference system, or
null
if none. - Throws:
BackingStoreException
- if the CRS cannot be created from the SRID code.
-
setCoordinateReferenceSystem
public void setCoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Sets the coordinate reference system. This method overwrites any previous user object. This is okay for the context in which Apache SIS uses this method, which is only for newly created geometries.- Specified by:
setCoordinateReferenceSystem
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Parameters:
crs
- the coordinate reference system to set.- See Also:
-
getCoordinatesDimension
private static int getCoordinatesDimension(org.locationtech.jts.geom.Geometry geometry) Gets the number of dimensions of geometry vertex (sequence of coordinate tuples), which can be 2 or 3. Note that this is different than the geometry topological dimension, which can be 0, 1 or 2.- Parameters:
geometry
- the geometry for which to get vertex (not topological) dimension.- Returns:
- vertex dimension of the given geometry.
- Throws:
IllegalArgumentException
- if the type of the given geometry is not recognized.
-
getEnvelope
Returns the envelope of the wrapped JTS geometry. Never null, but may be empty. In current implementation, z values of three-dimensional envelopes areDouble.NaN
. It may change in a future version if we have a way to get those z values from a JTS object.- Specified by:
getEnvelope
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Returns:
- the geometry envelope. Should never be
null
. Note though that for an empty geometry or a single point, the returned envelope will be empty.
-
getCentroid
public org.opengis.geometry.DirectPosition getCentroid()Returns the centroid of the wrapped geometry as a direct position.- Specified by:
getCentroid
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Returns:
- the centroid of the wrapped geometry.
-
getPointCoordinates
public double[] getPointCoordinates()If the wrapped geometry is a point, returns its coordinates. Otherwise returnsnull
. If non-null, the returned array may have a length of 2 or 3.- Specified by:
getPointCoordinates
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Returns:
- the coordinate of the point as an array of length 2 or 3,
or
null
if the geometry is not a point. - See Also:
-
getAllCoordinates
Returns all coordinate tuples in the wrapped geometry. This method is currently used for testing purpose only.- Specified by:
getAllCoordinates
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Returns:
- the sequence of all coordinate values in the wrapped geometry,
or
null
if they cannot be obtained.
-
mergePolylines
Merges a sequence of points or paths after the wrapped geometry.- Specified by:
mergePolylines
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Parameters:
polylines
- the points or polylines to merge in a single polyline instance.- Returns:
- the merged polyline (may be the wrapper geometry but never
null
). - Throws:
ClassCastException
- if an element in the iterator is not a JTS geometry.
-
predicateSameCRS
protected boolean predicateSameCRS(SpatialOperatorName type, GeometryWrapper<org.locationtech.jts.geom.Geometry> other) Applies a filter predicate between this geometry and another geometry. This method assumes that the two geometries are in the same CRS (this is not verified).Note:
SpatialOperatorName.BBOX
is implemented byNOT DISJOINT
. It is caller's responsibility to ensure that one of the geometries is rectangular, for example by a call toGeometry.getEnvelope()
.- Overrides:
predicateSameCRS
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Parameters:
type
- the predicate operation to apply.other
- the other geometry to test with this geometry.- Returns:
- result of applying the specified predicate.
-
predicateSameCRS
protected boolean predicateSameCRS(DistanceOperatorName type, GeometryWrapper<org.locationtech.jts.geom.Geometry> other, double distance) Applies a filter predicate between this geometry and another geometry within a given distance. This method assumes that the two geometries are in the same CRS and that the unit of measurement is the same fordistance
than for axes (this is not verified).- Overrides:
predicateSameCRS
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Parameters:
type
- the predicate operation to apply.other
- the other geometry to test with this geometry.distance
- distance to test between the geometries.- Returns:
- result of applying the specified predicate.
-
operationSameCRS
protected Object operationSameCRS(SQLMM operation, GeometryWrapper<org.locationtech.jts.geom.Geometry> other, Object argument) Applies a SQLMM operation on this geometry.- Overrides:
operationSameCRS
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Parameters:
operation
- the SQLMM operation to apply.other
- the other geometry, ornull
if the operation requires only one geometry.argument
- an operation-specific argument, ornull
if not applicable.- Returns:
- result of the specified operation.
- Throws:
ClassCastException
- if the operation can only be executed on some specific argument types (for example geometries that are polylines) and one of the argument is not of that type.
-
toIndex
Converts the given argument to a zero-based index.- Throws:
ClassCastException
- if the argument is not a string or a number.NumberFormatException
- if the argument is an unparseable string.IllegalArgumentException
- if the argument is zero or negative.
-
toGeometryType
Converts the given geometry to the specified type. If the geometry is already of that type, it is returned unchanged. Otherwise coordinates are copied in a new geometry of the requested type.The following conversions are illegal and will cause an
IllegalArgumentException
to be thrown:- From point to polyline or polygon (exception thrown by JTS itself).
- From geometry collection (except multi-point) to polyline.
- From geometry collection (except multi-point and multi-line string) to polygon.
- From geometry collection containing nested collections.
MultiLineString
toPolygon
is defined as following: the firstLineString
is taken as the exteriorLinearRing
and all othersLineString
s are interiorLinearRing
s. This rule is defined by some SQLMM operations.- Overrides:
toGeometryType
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Parameters:
target
- the desired type.- Returns:
- the converted geometry.
- Throws:
IllegalArgumentException
- if the geometry cannot be converted to the specified type.
-
convert
Converts the given geometry to the specified type without wrapper. This is the implementation oftoGeometryType(GeometryType)
. Caller should invokeJTS.copyMetadata(Geometry, Geometry)
after this method.- Parameters:
target
- the desired type.- Returns:
- the converted geometry.
- Throws:
IllegalArgumentException
- if the geometry cannot be converted to the specified type.
-
toCollection
private <T extends org.locationtech.jts.geom.Geometry> org.locationtech.jts.geom.GeometryCollection toCollection(org.locationtech.jts.geom.GeometryFactory factory, Class<T> type, IntFunction<T[]> newArray, BiFunction<org.locationtech.jts.geom.GeometryFactory, org.locationtech.jts.geom.Coordinate[], T> newComponent, BiFunction<org.locationtech.jts.geom.GeometryFactory, T[], org.locationtech.jts.geom.GeometryCollection> newCollection) Converts a single geometry or a geometry collection to a collection of another type. This is a helper method fortoGeometryType(GeometryType)
.- Type Parameters:
T
- the compile-time value oftype
.- Parameters:
factory
- the factory to use for creating new geometries.type
- the type of geometry components to put in a collection.newArray
- constructor for a new array of giventype
.newComponent
- constructor for a geometry component of giventype
.newCollection
- constructor for a geometry collection from an array of components/- Returns:
- the geometry collection created from the given type.
- Throws:
IllegalArgumentException
- if a geometry collection contains nested collection.
-
isCollection
private static boolean isCollection(org.locationtech.jts.geom.Geometry geometry) Returnstrue
if the given geometry is a collection other thanMultiPoint
. Collections are handled recursively bygetLineStrings(…)
andgetPolygons(…)
. -
transform
public GeometryWrapper<org.locationtech.jts.geom.Geometry> transform(org.opengis.referencing.operation.CoordinateOperation operation, boolean validate) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException Transforms this geometry using the given coordinate operation. If the operation isnull
, then the geometry is returned unchanged. If the geometry uses a different CRS than the source CRS of the given operation andvalidate
istrue
, then a new operation to the target CRS will be automatically computed.- Overrides:
transform
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Parameters:
operation
- the coordinate operation to apply, ornull
.validate
- whether to validate the operation source CRS.- Returns:
- the transformed geometry (may be the same geometry instance, but never
null
). - Throws:
org.opengis.util.FactoryException
- if transformation to the target CRS cannot be found.org.opengis.referencing.operation.TransformException
- if the geometry cannot be transformed.
-
transform
public GeometryWrapper<org.locationtech.jts.geom.Geometry> transform(org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS) throws org.opengis.referencing.operation.TransformException Transforms this geometry to the specified Coordinate Reference System (CRS). If the given CRS is null or is the same CRS than current one, the geometry is returned unchanged. If the geometry has no Coordinate Reference System, then the geometry is returned unchanged.- Overrides:
transform
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Parameters:
targetCRS
- the target coordinate reference system, ornull
.- Returns:
- the transformed geometry (may be the same geometry instance), or
null
. - Throws:
org.opengis.referencing.operation.TransformException
- if this geometry cannot be transformed.- See Also:
-
isSameCRS
Returnstrue
if the given geometry use the same CRS than this geometry, or conservatively returnsfalse
in case of doubt. This method should perform only a cheap test; it is used as a way to filter rapidly iftransform(CoordinateReferenceSystem)
needs to be invoked.- Specified by:
isSameCRS
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Parameters:
other
- the second geometry.- Returns:
true
if the two geometries use equivalent CRS or if the CRS is undefined on both side, orfalse
in case of doubt.
-
formatWKT
Returns the WKT representation of the wrapped geometry.- Specified by:
formatWKT
in classGeometryWrapper<org.locationtech.jts.geom.Geometry>
- Parameters:
flatness
- maximal distance between the approximated WKT and any point on the curve.- Returns:
- the Well Known Text for the wrapped geometry (never
null
). - See Also:
-