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

final class Wrapper extends GeometryWrapper<org.locationtech.jts.geom.Geometry>
The wrapper of Java Topology Suite (JTS) geometries.
Since:
1.1
Version:
1.2
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private 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 by
    invalid reference
    #predicate(SpatialOperatorName, Geometry)
    .
    private static final String[]
    The SQLMM names for the types listed in the TYPES array.
    private static final Class<?>[]
    The types of JTS objects to be recognized by the SQLMM ST_GeometryType operation.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Wrapper(org.locationtech.jts.geom.Geometry geometry)
    Creates a new wrapper around the given geometry.
  • Method Summary

    Modifier and Type
    Method
    Description
    private org.locationtech.jts.geom.Geometry
    Converts the given geometry to the specified type without wrapper.
    Geometries<org.locationtech.jts.geom.Geometry>
    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, or null 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.
    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)
    Returns true if the given geometry is a collection other than MultiPoint.
    boolean
    isSameCRS(GeometryWrapper<org.locationtech.jts.geom.Geometry> other)
    Returns true if the given geometry use the same CRS than this geometry, or conservatively returns false 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, or this if g 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.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.
    GeometryWrapper<org.locationtech.jts.geom.Geometry>
    Converts the given geometry to the specified type.
    private static int
    toIndex(Object argument)
    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

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • geometry

      private final org.locationtech.jts.geom.Geometry geometry
      The wrapped implementation.
    • PREDICATES

      private static final BiPredicate<org.locationtech.jts.geom.Geometry,org.locationtech.jts.geom.Geometry>[] PREDICATES
      All predicates recognized by
      invalid reference
      #predicate(SpatialOperatorName, Geometry)
      . Array indices are Enum.ordinal() values.
    • TYPES

      private static final Class<?>[] TYPES
      The types of JTS objects to be recognized by the SQLMM ST_GeometryType operation.
    • SQLMM_NAMES

      private static final String[] SQLMM_NAMES
      The SQLMM names for the types listed in the TYPES array.
  • Constructor Details

    • Wrapper

      Wrapper(org.locationtech.jts.geom.Geometry geometry)
      Creates a new wrapper around the given geometry.
  • Method Details

    • rewrap

      private Wrapper rewrap(org.locationtech.jts.geom.Geometry result)
      Returns the given geometry in new wrapper, or this if g is same as current geometry.
      Parameters:
      result - the geometry computed by a JTS operation.
      Returns:
      wrapper for the given geometry. May be this.
    • factory

      public Geometries<org.locationtech.jts.geom.Geometry> factory()
      Returns the implementation-dependent factory of geometric object.
      Specified by:
      factory in class GeometryWrapper<org.locationtech.jts.geom.Geometry>
      Returns:
      the factory of implementation-dependent geometric objects (never null).
    • implementation

      public Object implementation()
      Returns the geometry specified at construction time.
      Specified by:
      implementation in class GeometryWrapper<org.locationtech.jts.geom.Geometry>
      Returns:
      the geometry implementation wrapped by this instance (never null).
    • getSRID

      public OptionalInt 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 that getCoordinateReferenceSystem() would return no CRS.
      Overrides:
      getSRID in class GeometryWrapper<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, or null if none.
      Specified by:
      getCoordinateReferenceSystem in class GeometryWrapper<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 class GeometryWrapper<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

      public GeneralEnvelope getEnvelope()
      Returns the envelope of the wrapped JTS geometry. Never null, but may be empty. In current implementation, z values of three-dimensional envelopes are Double.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 class GeometryWrapper<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 class GeometryWrapper<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 returns null. If non-null, the returned array may have a length of 2 or 3.
      Specified by:
      getPointCoordinates in class GeometryWrapper<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

      @Debug public double[] getAllCoordinates()
      Returns all coordinate tuples in the wrapped geometry. This method is currently used for testing purpose only.
      Specified by:
      getAllCoordinates in class GeometryWrapper<org.locationtech.jts.geom.Geometry>
      Returns:
      the sequence of all coordinate values in the wrapped geometry, or null if they cannot be obtained.
    • mergePolylines

      protected org.locationtech.jts.geom.Geometry mergePolylines(Iterator<?> polylines)
      Merges a sequence of points or paths after the wrapped geometry.
      Specified by:
      mergePolylines in class GeometryWrapper<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 by NOT DISJOINT. It is caller's responsibility to ensure that one of the geometries is rectangular, for example by a call to Geometry.getEnvelope().

      Overrides:
      predicateSameCRS in class GeometryWrapper<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 for distance than for axes (this is not verified).
      Overrides:
      predicateSameCRS in class GeometryWrapper<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 class GeometryWrapper<org.locationtech.jts.geom.Geometry>
      Parameters:
      operation - the SQLMM operation to apply.
      other - the other geometry, or null if the operation requires only one geometry.
      argument - an operation-specific argument, or null 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

      private static int toIndex(Object argument)
      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

      public GeometryWrapper<org.locationtech.jts.geom.Geometry> toGeometryType(GeometryType target)
      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.
      The conversion from MultiLineString to Polygon is defined as following: the first LineString is taken as the exterior LinearRing and all others LineStrings are interior LinearRings. This rule is defined by some SQLMM operations.
      Overrides:
      toGeometryType in class GeometryWrapper<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

      private org.locationtech.jts.geom.Geometry convert(GeometryType target)
      Converts the given geometry to the specified type without wrapper. This is the implementation of toGeometryType(GeometryType). Caller should invoke JTS.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 for toGeometryType(GeometryType).
      Type Parameters:
      T - the compile-time value of type.
      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 given type.
      newComponent - constructor for a geometry component of given type.
      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)
      Returns true if the given geometry is a collection other than MultiPoint. Collections are handled recursively by getLineStrings(…) and getPolygons(…).
    • 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 is null, then the geometry is returned unchanged. If the geometry uses a different CRS than the source CRS of the given operation and validate is true, then a new operation to the target CRS will be automatically computed.
      Overrides:
      transform in class GeometryWrapper<org.locationtech.jts.geom.Geometry>
      Parameters:
      operation - the coordinate operation to apply, or null.
      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 class GeometryWrapper<org.locationtech.jts.geom.Geometry>
      Parameters:
      targetCRS - the target coordinate reference system, or null.
      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

      public boolean isSameCRS(GeometryWrapper<org.locationtech.jts.geom.Geometry> other)
      Returns true if the given geometry use the same CRS than this geometry, or conservatively returns false in case of doubt. This method should perform only a cheap test; it is used as a way to filter rapidly if transform(CoordinateReferenceSystem) needs to be invoked.
      Specified by:
      isSameCRS in class GeometryWrapper<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, or false in case of doubt.
    • formatWKT

      public String formatWKT(double flatness)
      Returns the WKT representation of the wrapped geometry.
      Specified by:
      formatWKT in class GeometryWrapper<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: