org.geotools.geometry.jts
Class JTS

Object
  extended by JTS

public final class JTS
extends Object

JTS Geometry utility methods, bringing Geotools to JTS.

Offers geotools based services such as reprojection.

Responsibilities:

Since:
2.2
Author:
Jody Garnett, Martin Desruisseaux, Simone Giannecchini, GeoSolutions.
Module:
modules/library/api (gt-api.jar)

Method Summary
static void checkCoordinatesRange(Geometry geom, CoordinateReferenceSystem crs)
          Checks a Geometry coordinates are within the area of validity of the specified reference system.
static void copy(Coordinate point, double[] ordinates)
          Copies the ordinates values from the specified JTS coordinates to the specified array.
static Envelope2D getEnvelope2D(Envelope envelope, CoordinateReferenceSystem crs)
          Converts a JTS 2D envelope in an Envelope2D for interoperability with the referencing package.
static double orthodromicDistance(Coordinate p1, Coordinate p2, CoordinateReferenceSystem crs)
          Computes the orthodromic distance between two points.
static Geometry shapeToGeometry(Shape shape, GeometryFactory factory)
          Converts an arbitrary Java2D shape into a JTS geometry.
static ReferencedEnvelope toEnvelope(Geometry geom)
          Create a ReferencedEnvelope from the provided geometry, we will do our best to guess the CoordinateReferenceSystem making use of getUserData() and getSRID() as needed.
static Envelope toGeographic(Envelope envelope, CoordinateReferenceSystem crs)
          Transforms the envelope from its current crs to WGS84 coordinate reference system.
static Polygon toGeometry(BoundingBox e)
          Converts a BoundingBox to a polygon.
static Polygon toGeometry(Envelope e)
          Converts an envelope to a polygon.
static Coordinate transform(Coordinate source, Coordinate dest, MathTransform transform)
          Transforms the coordinate using the provided math transform.
static Envelope transform(Envelope sourceEnvelope, Envelope targetEnvelope, MathTransform transform, int npoints)
          Transforms the densified envelope using the specified math transform.
static Envelope transform(Envelope envelope, MathTransform transform)
          Transforms the envelope using the specified math transform.
static Geometry transform(Geometry geom, MathTransform transform)
          Transforms the geometry using the default transformer.
static void xform(MathTransform transform, double[] src, double[] dest)
          Like a transform but eXtreme!
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

transform

public static Envelope transform(Envelope envelope,
                                 MathTransform transform)
                          throws TransformException
Transforms the envelope using the specified math transform. Note that this method can not handle the case where the envelope contains the North or South pole, or when it cross the ±180� longitude, because math transforms do not carry suffisient informations. For a more robust envelope transformation, use ReferencedEnvelope.transform(CoordinateReferenceSystem, boolean) instead.

Parameters:
envelope - The envelope to transform.
transform - The transform to use.
Returns:
The transformed Envelope
Throws:
TransformException - if at least one coordinate can't be transformed.

transform

public static Envelope transform(Envelope sourceEnvelope,
                                 Envelope targetEnvelope,
                                 MathTransform transform,
                                 int npoints)
                          throws TransformException
Transforms the densified envelope using the specified math transform. The envelope is densified (extra points put around the outside edge) to provide a better new envelope for high deformed situations.

If an optional target envelope is provided, this envelope will be expanded with the transformation result. It will not be nullified before the expansion.

Note that this method can not handle the case where the envelope contains the North or South pole, or when it cross the ±180� longitude, because math transforms do not carry suffisient informations. For a more robust envelope transformation, use ReferencedEnvelope.transform(CoordinateReferenceSystem, boolean, int) instead.

Parameters:
sourceEnvelope - The envelope to transform.
targetEnvelope - An envelope to expand with the transformation result, or null for returning an new envelope.
transform - The transform to use.
npoints - Densification of each side of the rectange.
Returns:
targetEnvelope if it was non-null, or a new envelope otherwise. In all case, the returned envelope fully contains the transformed envelope.
Throws:
TransformException - if a coordinate can't be transformed.

transform

public static Geometry transform(Geometry geom,
                                 MathTransform transform)
                          throws MismatchedDimensionException,
                                 TransformException
Transforms the geometry using the default transformer.

Parameters:
geom - The geom to transform
transform - the transform to use during the transformation.
Returns:
the transformed geometry. It will be a new geometry.
Throws:
MismatchedDimensionException - if the geometry doesn't have the expected dimension for the specified transform.
TransformException - if a point can't be transformed.

transform

public static Coordinate transform(Coordinate source,
                                   Coordinate dest,
                                   MathTransform transform)
                            throws TransformException
Transforms the coordinate using the provided math transform.

Parameters:
source - the source coordinate that will be transformed
dest - the coordinate that will be set. May be null or the source coordinate (or new coordinate of course).
Returns:
the destination coordinate if not null or a new Coordinate.
Throws:
TransformException - if the coordinate can't be transformed.

toGeographic

public static Envelope toGeographic(Envelope envelope,
                                    CoordinateReferenceSystem crs)
                             throws TransformException
Transforms the envelope from its current crs to WGS84 coordinate reference system. If the specified envelope is already in WGS84, then it is returned unchanged.

Parameters:
envelope - The envelope to transform.
crs - The CRS the envelope is currently in.
Returns:
The envelope transformed to be in WGS84 CRS.
Throws:
TransformException - If at least one coordinate can't be transformed.

xform

public static void xform(MathTransform transform,
                         double[] src,
                         double[] dest)
                  throws TransformException
Like a transform but eXtreme! Transforms an array of coordinates using the provided math transform. Each coordinate is transformed separately. In case of a transform exception then the new value of the coordinate is the last coordinate correctly transformed.

Parameters:
transform - The math transform to apply.
src - The source coordinates.
dest - The destination array for transformed coordinates.
Throws:
TransformException - if this method failed to transform any of the points.

orthodromicDistance

public static double orthodromicDistance(Coordinate p1,
                                         Coordinate p2,
                                         CoordinateReferenceSystem crs)
                                  throws TransformException
Computes the orthodromic distance between two points. This method:

  1. Transforms both points to geographic coordinates (latitude,longitude).
  2. Computes the orthodromic distance between the two points using ellipsoidal calculations.

The real work is performed by GeodeticCalculator. This convenience method simply manages a pool of pre-defined geodetic calculators for the given coordinate reference system in order to avoid repetitive object creation. If a large amount of orthodromic distances need to be computed, direct use of GeodeticCalculator provides better performance than this convenience method.

Parameters:
p1 - First point
p2 - Second point
crs - Reference system the two points are in.
Returns:
Orthodromic distance between the two points, in meters.
Throws:
TransformException - if the coordinates can't be transformed from the specified CRS to a geographic CRS.

copy

public static void copy(Coordinate point,
                        double[] ordinates)
Copies the ordinates values from the specified JTS coordinates to the specified array. The destination array can have any length. Only the relevant field of the source coordinate will be copied. If the array length is greater than 3, then all extra dimensions will be set to NaN.

Parameters:
point - The source coordinate.
ordinates - The destination array.

shapeToGeometry

public static Geometry shapeToGeometry(Shape shape,
                                       GeometryFactory factory)
Converts an arbitrary Java2D shape into a JTS geometry. The created JTS geometry may be any of LineString, LinearRing or MultiLineString.

Parameters:
shape - The Java2D shape to create.
factory - The JTS factory to use for creating geometry.
Returns:
The JTS geometry.

getEnvelope2D

public static Envelope2D getEnvelope2D(Envelope envelope,
                                       CoordinateReferenceSystem crs)
                                throws MismatchedDimensionException
Converts a JTS 2D envelope in an Envelope2D for interoperability with the referencing package.

If the provided envelope is a ReferencedEnvelope we check that the provided CRS and the implicit CRS are similar.

Parameters:
envelope - The JTS envelope to convert.
crs - The coordinate reference system for the specified envelope.
Returns:
The GeoAPI envelope.
Throws:
MismatchedDimensionException - if a two-dimensional envelope can't be created from an envelope with the specified CRS.
Since:
2.3

toGeometry

public static Polygon toGeometry(Envelope e)
Converts an envelope to a polygon.

The resulting polygon contains an outer ring with verticies: (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1)

Parameters:
envelope - The original envelope.
Returns:
The envelope as a polygon.
Since:
2.4

toEnvelope

public static ReferencedEnvelope toEnvelope(Geometry geom)
Create a ReferencedEnvelope from the provided geometry, we will do our best to guess the CoordinateReferenceSystem making use of getUserData() and getSRID() as needed.

Parameters:
geom - Provided Geometry
Returns:
RefernecedEnveleope describing the bounds of the provided Geometry

toGeometry

public static Polygon toGeometry(BoundingBox e)
Converts a BoundingBox to a polygon.

The resulting polygon contains an outer ring with verticies: (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1)

Parameters:
envelope - The original envelope.
Returns:
The envelope as a polygon.
Since:
2.4

checkCoordinatesRange

public static void checkCoordinatesRange(Geometry geom,
                                         CoordinateReferenceSystem crs)
                                  throws PointOutsideEnvelopeException
Checks a Geometry coordinates are within the area of validity of the specified reference system. If a coordinate falls outside the area of validity a PointOutsideEnvelopeException is thrown

Parameters:
geom - the geometry to check
the - crs that defines the are of validity (must not be null)
Throws:
PointOutsideEnvelopeException
Since:
2.4


Copyright © 1996-2010 Geotools. All Rights Reserved.