Class JTS
java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.feature.jts.JTS
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic ShapeasShape(org.locationtech.jts.geom.Geometry geometry) Returns a view of the given JTS geometry as a Java2D shape.static org.locationtech.jts.geom.GeometryConverts a Java2D shape to a JTS geometry.static org.opengis.referencing.crs.CoordinateReferenceSystemgetCoordinateReferenceSystem(org.locationtech.jts.geom.Geometry source) Gets the Coordinate Reference System (CRS) from the given geometry.static org.locationtech.jts.geom.Geometrytransform(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.Geometrytransform(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.Geometrytransform(org.locationtech.jts.geom.Geometry geometry, org.opengis.referencing.operation.MathTransform transform) Transforms the given geometry using the given math transform.
-
Field Details
-
CRS_KEY
Key used in user data map for storing an instance ofCoordinateReferenceSystem.- See Also:
-
-
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.
nullis returned.- Parameters:
source- the geometry from which to get the CRS, ornull.- Returns:
- the coordinate reference system, or
nullif none. - Throws:
org.opengis.util.FactoryException- if the CRS cannot be created from the SRID code.
- Geometry user data is an instance of
-
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
CoordinateOperationonly once, then invokefor each geometry. Alternatively, the geometries can be stored in a single geometry collection in order to invoke this method only once.invalid reference
#transform(Geometry, CoordinateOperation)- Parameters:
geometry- the geometry to transform, ornull.targetCRS- the target coordinate reference system, ornull.- 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 andvalidateistrue, then a new operation is inferred.- Parameters:
geometry- the geometry to transform, ornull.operation- the coordinate operation to apply, ornull.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, ornull.transform- the transform to apply, ornull.- 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
Returns a view of the given JTS geometry as a Java2D shape.- Parameters:
geometry- the geometry to view as a shape, notnull.- 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 byasShape(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, ornullfor the default.shape- the Java2D shape to convert. Cannot benull.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.
-