Class JTS
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
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Shape
asShape
(org.locationtech.jts.geom.Geometry geometry) Returns a view of the given JTS geometry as a Java2D shape.(package private) static void
copyMetadata
(org.locationtech.jts.geom.Geometry source, org.locationtech.jts.geom.Geometry target) Copies coordinate reference system information from the given source geometry to the target geometry.private static org.opengis.referencing.operation.CoordinateOperation
findOperation
(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS, org.locationtech.jts.geom.Geometry areaOfInterest) Finds an operation between the given CRS valid in the given area of interest.static org.locationtech.jts.geom.Geometry
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.(package private) static boolean
isSameCRS
(org.locationtech.jts.geom.Geometry first, org.locationtech.jts.geom.Geometry second) Returnstrue
if the two geometries use the same CRS, based on very cheap comparison.(package private) static void
setCoordinateReferenceSystem
(org.locationtech.jts.geom.Geometry target, org.opengis.referencing.crs.CoordinateReferenceSystem crs) Sets the Coordinate Reference System (CRS) in the specified 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.
-
Field Details
-
CRS_KEY
Key used in user data map for storing an instance ofCoordinateReferenceSystem
.- See Also:
-
-
Constructor Details
-
JTS
private JTS()Do not allow instantiation of this class.
-
-
Method Details
-
isSameCRS
static boolean isSameCRS(org.locationtech.jts.geom.Geometry first, org.locationtech.jts.geom.Geometry second) Returnstrue
if the two geometries use the same CRS, based on very cheap comparison. A value offalse
does not necessarily means that the CRS are different, but it means that a more expansive comparison is required. If CRS are specified by SRID codes, then this method assumes that the two SRID codes are defined by the same authority (e.g. EPSG).If both CRS are undefined (null), then they are considered the same.
- Parameters:
first
- the first geometry.second
- the second geometry.- Returns:
true
if the two geometries use equivalent CRS, orfalse
in case of doubt.
-
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.
null
is returned.- Parameters:
source
- the geometry from which to get the CRS, ornull
.- Returns:
- the coordinate reference system, or
null
if none. - Throws:
org.opengis.util.FactoryException
- if the CRS cannot be created from the SRID code.
- Geometry user data is an instance of
-
setCoordinateReferenceSystem
static void setCoordinateReferenceSystem(org.locationtech.jts.geom.Geometry target, org.opengis.referencing.crs.CoordinateReferenceSystem crs) Sets the Coordinate Reference System (CRS) in the specified geometry. This method overwrite any previous user data; it should be invoked only when the geometry is known to not store any other information. In current Apache SIS usage, this method is invoked only for newly created geometries.This method also sets the JTS SRID to EPSG code if such code can be found. For performance reasons this method does not perform a full scan of EPSG database if the CRS does not provide an EPSG code.
- Parameters:
target
- the geometry where to store coordinate reference system information.crs
- the CRS to store, ornull
.
-
copyMetadata
static void copyMetadata(org.locationtech.jts.geom.Geometry source, org.locationtech.jts.geom.Geometry target) Copies coordinate reference system information from the given source geometry to the target geometry. Current implementation copies only CRS information, but future implementations could copy some other values if they may apply to the target geometry as well. -
findOperation
private static org.opengis.referencing.operation.CoordinateOperation findOperation(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS, org.locationtech.jts.geom.Geometry areaOfInterest) throws org.opengis.util.FactoryException Finds an operation between the given CRS valid in the given area of interest. This method does not verify the CRS of the given geometry.- Parameters:
sourceCRS
- the CRS of source coordinates.targetCRS
- the CRS of target coordinates.areaOfInterest
- the area of interest.- Returns:
- the mathematical operation from
sourceCRS
totargetCRS
. - Throws:
org.opengis.util.FactoryException
- if the operation cannot be created.
-
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 invokeinvalid 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 andvalidate
istrue
, 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, ornull
for 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.
-