java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.feature.jts.JTS

public final class JTS extends Static
Utilities for Java Topology Suite (JTS) objects. We use this class for functionalities not supported by Apache SIS with other libraries. For library-agnostic functionalities, see Geometries instead.

This method may be modified or removed in any future version. For example, we may replace it by a more general mechanism working also on other geometry libraries.

Since:
1.0
Version:
1.2
Author:
Johann Sorel (Geomatys), Alexis Manin (Geomatys)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Key used in user data map for storing an instance of CoordinateReferenceSystem.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Shape
    asShape(org.locationtech.jts.geom.Geometry geometry)
    Returns a view of the given JTS geometry as a Java2D shape.
    static org.locationtech.jts.geom.Geometry
    fromAWT(org.locationtech.jts.geom.GeometryFactory factory, Shape shape, double flatness)
    Converts a Java2D shape to a JTS geometry.
    static org.opengis.referencing.crs.CoordinateReferenceSystem
    getCoordinateReferenceSystem(org.locationtech.jts.geom.Geometry source)
    Gets the Coordinate Reference System (CRS) from the given geometry.
    static org.locationtech.jts.geom.Geometry
    transform(org.locationtech.jts.geom.Geometry geometry, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS)
    Transforms the given geometry to the specified Coordinate Reference System (CRS).
    static org.locationtech.jts.geom.Geometry
    transform(org.locationtech.jts.geom.Geometry geometry, org.opengis.referencing.operation.CoordinateOperation operation, boolean validate)
    Transforms the given geometry using the given coordinate operation.
    static org.locationtech.jts.geom.Geometry
    transform(org.locationtech.jts.geom.Geometry geometry, org.opengis.referencing.operation.MathTransform transform)
    Transforms the given geometry using the given math transform.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • getCoordinateReferenceSystem

      public static org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem(org.locationtech.jts.geom.Geometry source) throws org.opengis.util.FactoryException
      Gets the Coordinate Reference System (CRS) from the given geometry. This method expects the CRS to be stored in one the following ways:
      • Geometry user data is an instance of CoordinateReferenceSystem.
      • user data is a (@link Map} with a value for the "CRS" key.
      • Geometry SRID is strictly positive, in which case it is interpreted as an EPSG code.
      If none of the above is valid, null is returned.
      Parameters:
      source - the geometry from which to get the CRS, or null.
      Returns:
      the coordinate reference system, or null if none.
      Throws:
      org.opengis.util.FactoryException - if the CRS cannot be created from the SRID code.
    • transform

      public static org.locationtech.jts.geom.Geometry transform(org.locationtech.jts.geom.Geometry geometry, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException
      Transforms the given geometry to the specified Coordinate Reference System (CRS). If the given CRS or the given geometry is null or is the same than current CRS, then the geometry is returned unchanged. If the geometry has no Coordinate Reference System, then the geometry is returned unchanged.

      This operation may be slow! If many geometries need to be transformed, it is better to fetch the CoordinateOperation only once, then invoke

      invalid reference
      #transform(Geometry, CoordinateOperation)
      for each geometry. Alternatively, the geometries can be stored in a single geometry collection in order to invoke this method only once.

      Parameters:
      geometry - the geometry to transform, or null.
      targetCRS - the target coordinate reference system, or null.
      Returns:
      the transformed geometry, or the same geometry if it is already in target CRS.
      Throws:
      org.opengis.util.FactoryException - if transformation to the target CRS cannot be constructed.
      org.opengis.referencing.operation.TransformException - if the given geometry cannot be transformed.
    • transform

      public static org.locationtech.jts.geom.Geometry transform(org.locationtech.jts.geom.Geometry geometry, org.opengis.referencing.operation.CoordinateOperation operation, boolean validate) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException
      Transforms the given geometry using the given coordinate operation. If the geometry or the operation is null, then the geometry is returned unchanged. If the source CRS is not equals to the geometry CRS and validate is true, then a new operation is inferred.
      Parameters:
      geometry - the geometry to transform, or null.
      operation - the coordinate operation to apply, or null.
      validate - whether to validate the operation source CRS.
      Returns:
      the transformed geometry, or the same geometry if it is already in target CRS.
      Throws:
      org.opengis.util.FactoryException - if transformation to the target CRS cannot be found.
      org.opengis.referencing.operation.TransformException - if the given geometry cannot be transformed.
    • transform

      public static org.locationtech.jts.geom.Geometry transform(org.locationtech.jts.geom.Geometry geometry, org.opengis.referencing.operation.MathTransform transform) throws org.opengis.referencing.operation.TransformException
      Transforms the given geometry using the given math transform. If the geometry or the transform is null or identity, then the geometry is returned unchanged.
      Parameters:
      geometry - the geometry to transform, or null.
      transform - the transform to apply, or null.
      Returns:
      the transformed geometry, or the same geometry if it is already in target CRS.
      Throws:
      org.opengis.referencing.operation.TransformException - if the given geometry cannot be transformed.
    • asShape

      public static Shape asShape(org.locationtech.jts.geom.Geometry geometry)
      Returns a view of the given JTS geometry as a Java2D shape.
      Parameters:
      geometry - the geometry to view as a shape, not null.
      Returns:
      the Java2D shape view.
    • fromAWT

      public static org.locationtech.jts.geom.Geometry fromAWT(org.locationtech.jts.geom.GeometryFactory factory, Shape shape, double flatness)
      Converts a Java2D shape to a JTS geometry. If the given shape is a view created by asShape(Geometry), then the original geometry is returned. Otherwise a new geometry is created with a copy (not a view) of the shape coordinates.
      Parameters:
      factory - factory to use for creating the geometry, or null for the default.
      shape - the Java2D shape to convert. Cannot be null.
      flatness - the maximum distance that line segments are allowed to deviate from curves.
      Returns:
      JTS geometry with shape coordinates. Never null but can be empty.