|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectJTS
public final class JTS
JTS Geometry utility methods, bringing Geotools to JTS.
Offers geotools based services such as reprojection.
Responsibilities:
Method Summary | |
---|---|
static ReferencedEnvelope |
bounds(Geometry geometry,
CoordinateReferenceSystem crs)
Replacement for geometry.getEnvelopeInternal() that returns ReferencedEnvelope or ReferencedEnvelope3D as appropriate for the provided CRS. |
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 List<Polygon> |
makeValid(Polygon polygon,
boolean removeHoles)
Given a potentially invalid polygon it rebuilds it as a list of valid polygons, eventually removing the holes |
static double |
orthodromicDistance(Coordinate p1,
Coordinate p2,
CoordinateReferenceSystem crs)
Computes the orthodromic distance between two points. |
static Geometry |
removeCollinearVertices(Geometry g)
Removes collinear vertices from the provided Geometry . |
static Geometry |
removeCollinearVertices(Geometry geometry,
int minPoints)
Removes collinear vertices from the provided Geometry if the number of point exceeds the requested minPoints. |
static Geometry |
shapeToGeometry(Shape shape,
GeometryFactory factory)
Deprecated. Please use toGeometry(Shape) or
toGeometry(Shape, GeometryFactory) |
static Geometry |
smooth(Geometry geom,
double fit)
Creates a smoothed copy of the input Geometry. |
static Geometry |
smooth(Geometry geom,
double fit,
GeometryFactory factory)
Creates a smoothed copy of the input Geometry. |
static DirectPosition |
toDirectPosition(Coordinate point,
CoordinateReferenceSystem crs)
Creates a DirectPosition from the provided point. |
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 DefaultGeographicCRS.WGS84 . |
static Geometry |
toGeographic(Geometry geom,
CoordinateReferenceSystem crs)
Transforms the geometry from its current crs to DefaultGeographicCRS.WGS84 . |
static ReferencedEnvelope |
toGeographic(ReferencedEnvelope envelope)
Transforms the envelope to DefaultGeographicCRS.WGS84 . |
static Polygon |
toGeometry(BoundingBox bbox)
Converts a BoundingBox to a JTS polygon. |
static Polygon |
toGeometry(BoundingBox bbox,
GeometryFactory factory)
Converts a BoundingBox to a JTS polygon using the given JTS geometry factory. |
static Polygon |
toGeometry(BoundingBox bbox,
GeometryFactory factory,
int npoints)
Convert the provided bbox to a polygon, sampling a set number of points along each side. |
static Point |
toGeometry(DirectPosition position)
Create a Point from a ISO Geometry DirectPosition. |
static Point |
toGeometry(DirectPosition position,
GeometryFactory factory)
Create a Point from a ISO Geometry DirectPosition. |
static Polygon |
toGeometry(Envelope env)
Converts an envelope to a JTS polygon. |
static Polygon |
toGeometry(Envelope env,
GeometryFactory factory)
Converts an envelope to a JTS polygon using the given JTS geometry factory. |
static Polygon |
toGeometry(ReferencedEnvelope bbox)
Converts a ReferencedEnvelope to a JTS polygon. |
static Geometry |
toGeometry(Shape shape)
Converts an arbitrary Java2D shape into a JTS geometry. |
static Geometry |
toGeometry(Shape shape,
GeometryFactory factory)
Converts an arbitrary Java2D shape into a JTS geometry. |
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 ReferencedEnvelope |
transformTo2D(ReferencedEnvelope sourceEnvelope,
CoordinateReferenceSystem targetCRS,
boolean lenient,
int npoints)
Transform from 3D down to 2D. |
static ReferencedEnvelope3D |
transformTo3D(ReferencedEnvelope sourceEnvelope,
CoordinateReferenceSystem targetCRS,
boolean lenient,
int npoints)
Transform from D up to 3D. |
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 |
---|
public static Envelope transform(Envelope envelope, MathTransform transform) throws TransformException
ReferencedEnvelope.transform(CoordinateReferenceSystem, boolean)
instead.
envelope
- The envelope to transform.transform
- The transform to use.
TransformException
- if at least one coordinate can't be transformed.public static Envelope transform(Envelope sourceEnvelope, Envelope targetEnvelope, MathTransform transform, int npoints) throws TransformException
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.
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 rectangle.
targetEnvelope
if it was non-null, or a new envelope otherwise. In all case,
the returned envelope fully contains the transformed envelope.
TransformException
- if a coordinate can't be transformed.public static ReferencedEnvelope3D transformTo3D(ReferencedEnvelope sourceEnvelope, CoordinateReferenceSystem targetCRS, boolean lenient, int npoints) throws TransformException, OperationNotFoundException, FactoryException
This method transforms each ordinate into WGS84, manually converts this to WGS84_3D with the addition of a Double.NaN, and then transforms to the final 3D position.
sourceEnvelope
- targetEnvelope
- transform
- npoints
-
TransformException
FactoryException
- If operationis unavailable from source CRS to WGS84, to from WGS84_3D to targetCRS
OperationNotFoundException
public static ReferencedEnvelope transformTo2D(ReferencedEnvelope sourceEnvelope, CoordinateReferenceSystem targetCRS, boolean lenient, int npoints) throws TransformException, OperationNotFoundException, FactoryException
This method transforms each ordinate into WGS84, manually converts this to WGS84_3D with the addition of a Double.NaN, and then transforms to the final 3D position.
sourceEnvelope
- targetEnvelope
- transform
- npoints
-
TransformException
OperationNotFoundException
FactoryException
public static Geometry transform(Geometry geom, MathTransform transform) throws MismatchedDimensionException, TransformException
geom
- The geom to transformtransform
- the transform to use during the transformation.
MismatchedDimensionException
- if the geometry doesn't have the expected dimension for the specified transform.
TransformException
- if a point can't be transformed.public static Coordinate transform(Coordinate source, Coordinate dest, MathTransform transform) throws TransformException
source
- the source coordinate that will be transformeddest
- the coordinate that will be set. May be null or the source coordinate (or new
coordinate of course).
TransformException
- if the coordinate can't be transformed.public static Envelope toGeographic(Envelope envelope, CoordinateReferenceSystem crs) throws TransformException
DefaultGeographicCRS.WGS84
. If the
specified envelope is already in WGS84, then it is returned unchanged.
The method CRS.equalsIgnoreMetadata(Object, Object)
is used to compare the numeric values
and axis order (so CRS.decode("CRS.84")
or CRS.decode("4326",true)
provide an appropriate match).
envelope
- The envelope to transform.crs
- The CRS the envelope is currently in.
DefaultGeographicCRS.WGS84
.
TransformException
- If at least one coordinate can't be transformed.public static ReferencedEnvelope toGeographic(ReferencedEnvelope envelope) throws TransformException
DefaultGeographicCRS.WGS84
.
This method will transform to DefaultGeographicCRS.WGS84_3D
if necessary
(and then drop the height axis).
This method is identical to calling: envelope.transform(DefaultGeographicCRS.WGS84,true)
envelope
- The envelope to transform
TransformException
public static void xform(MathTransform transform, double[] src, double[] dest) throws TransformException
transform
- The math transform to apply.src
- The source coordinates.dest
- The destination array for transformed coordinates.
TransformException
- if this method failed to transform any of the points.public static double orthodromicDistance(Coordinate p1, Coordinate p2, CoordinateReferenceSystem crs) throws TransformException
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.
p1
- First pointp2
- Second pointcrs
- Reference system the two points are in.
TransformException
- if the coordinates can't be transformed from the specified CRS to a
geographic CRS.public static DirectPosition toDirectPosition(Coordinate point, CoordinateReferenceSystem crs)
point
- crs
-
public static void copy(Coordinate point, double[] ordinates)
NaN
.
point
- The source coordinate.ordinates
- The destination array.public static Geometry shapeToGeometry(Shape shape, GeometryFactory factory)
toGeometry(Shape)
or
toGeometry(Shape, GeometryFactory)
LineString
, LinearRing
or MultiLineString
.
shape
- The Java2D shape to create.factory
- The JTS factory to use for creating geometry.
public static Geometry toGeometry(Shape shape)
LineString
, LinearRing
or MultiLineString
.
shape
- the input shape
IllegalArgumentException
- if shape
is null
public static Geometry toGeometry(Shape shape, GeometryFactory factory)
LineString
, LinearRing
or MultiLineString
.
shape
- the input shapefactory
- the JTS factory to use to create the geometry
IllegalArgumentException
- if either shape
or factory
is null
public static Envelope2D getEnvelope2D(Envelope envelope, CoordinateReferenceSystem crs) throws MismatchedDimensionException
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.
envelope
- The JTS envelope to convert.crs
- The coordinate reference system for the specified envelope.
MismatchedDimensionException
- if a two-dimensional envelope can't be created from an envelope with the
specified CRS.public static Point toGeometry(DirectPosition position)
position
-
public static Point toGeometry(DirectPosition position, GeometryFactory factory)
position
- factory
- Optional GeometryFactory
public static Polygon toGeometry(Envelope env)
The resulting polygon contains an outer ring with vertices: (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1)
envelope
- The original envelope.
IllegalArgumentException
- if env
is null
public static Polygon toGeometry(Envelope env, GeometryFactory factory)
The resulting polygon contains an outer ring with vertices: (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1)
envelope
- The original envelope.
IllegalArgumentException
- if either env
or factory
is null
public static ReferencedEnvelope toEnvelope(Geometry geom)
geom
- Provided Geometry
public static Polygon toGeometry(ReferencedEnvelope bbox)
ReferencedEnvelope
to a JTS polygon.
The resulting polygon contains an outer ring with vertices: (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1)
envelope
- The original envelope.
IllegalArgumentException
- if bbox
is null
public static Polygon toGeometry(BoundingBox bbox, GeometryFactory factory, int npoints)
bbox
- bounding box being converted to a Polygonfactory
- geometry factory used to create the polygonnpoints
- number of points to sample along each edge
public static Geometry toGeographic(Geometry geom, CoordinateReferenceSystem crs) throws TransformException
DefaultGeographicCRS.WGS84
. If the
specified geometry is already in WGS84, then it is returned unchanged.
The method CRS.equalsIgnoreMetadata(Object, Object)
is used to compare the numeric values
and axis order (so CRS.decode("CRS.84")
or CRS.decode("4326",true)
provide an appropriate match).
geom
- The geometry to transform.crs
- The CRS the geometry is currently in.
DefaultGeographicCRS.WGS84
.
TransformException
- If at least one coordinate can't be transformed.public static Polygon toGeometry(BoundingBox bbox)
BoundingBox
to a JTS polygon.
The resulting polygon contains an outer ring with vertices: (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1)
envelope
- The original envelope.
IllegalArgumentException
- if bbox
is null
public static Polygon toGeometry(BoundingBox bbox, GeometryFactory factory)
BoundingBox
to a JTS polygon using the given JTS geometry factory.
The resulting polygon contains an outer ring with vertices: (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1)
envelope
- The original envelope.
IllegalArgumentException
- if either bbox
or factory
is null
public static void checkCoordinatesRange(Geometry geom, CoordinateReferenceSystem crs) throws PointOutsideEnvelopeException
PointOutsideEnvelopeException
is thrown
geom
- the geometry to checkthe
- crs that defines the are of validity (must not be null)
PointOutsideEnvelopeException
public static Geometry smooth(Geometry geom, double fit)
The fit
parameter controls how tightly the smoothed lines conform to the input line
segments, with a value of 1 being tightest and 0 being loosest. Values outside this range
will be adjusted up or down as required.
The input Geometry can be a simple type (e.g. LineString, Polygon), a multi-type (e.g. MultiLineString, MultiPolygon) or a GeometryCollection. The returned object will be of the same type.
geom
- the input geometryfit
- tightness of fit from 0 (loose) to 1 (tight)
geom
IllegalArgumentException
- if geom
is null
public static Geometry smooth(Geometry geom, double fit, GeometryFactory factory)
The fit
parameter controls how tightly the smoothed lines conform to the input line
segments, with a value of 1 being tightest and 0 being loosest. Values outside this range
will be adjusted up or down as required.
The input Geometry can be a simple type (e.g. LineString, Polygon), a multi-type (e.g. MultiLineString, MultiPolygon) or a GeometryCollection. The returned object will be of the same type.
geom
- the input geometryfit
- tightness of fit from 0 (loose) to 1 (tight)factory
- the GeometryFactory to use for creating smoothed objects
geom
IllegalArgumentException
- if either geom
or factory
is null
public static ReferencedEnvelope bounds(Geometry geometry, CoordinateReferenceSystem crs)
geometry
- crs
-
public static Geometry removeCollinearVertices(Geometry g)
Geometry
.
For the moment this implementation only accepts, Polygon
, LineString
and MultiPolygon
It will throw an exception if the
geometry is not one of those types
g
- the instance of a Geometry
to remove collinear vertices from.
Geometry
without collinear vertices.public static Geometry removeCollinearVertices(Geometry geometry, int minPoints)
Geometry
if the number of point exceeds the requested minPoints.
For the moment this implementation only accepts, Polygon
, LineString
and MultiPolygon
It will throw an exception if the
geometry is not one of those types
geometry
- the instance of a Geometry
to remove collinear vertices from.minPoints
- perform removal of collinear points if num of vertices exceeds minPoints.
Geometry
without collinear vertices.public static List<Polygon> makeValid(Polygon polygon, boolean removeHoles)
polygon
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |