Package org.locationtech.jts.geom
Class GeometryFactory
java.lang.Object
org.locationtech.jts.geom.GeometryFactory
- All Implemented Interfaces:
Serializable
Supplies a set of utility methods for building Geometry objects from lists
of Coordinates.
Note that the factory constructor methods do not change the input coordinates in any way. In particular, they are not rounded to the supplied PrecisionModel. It is assumed that input Coordinates meet the given precision.
Instances of this class are thread-safe.
- Version:
- 1.7
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a GeometryFactory that generates Geometries having a floating PrecisionModel and a spatial-reference ID of 0.GeometryFactory
(CoordinateSequenceFactory coordinateSequenceFactory) Constructs a GeometryFactory that generates Geometries having the given CoordinateSequence implementation, a double-precision floating PrecisionModel and a spatial-reference ID of 0.GeometryFactory
(PrecisionModel precisionModel) Constructs a GeometryFactory that generates Geometries having the givenPrecisionModel
and the default CoordinateSequence implementation.GeometryFactory
(PrecisionModel precisionModel, int SRID) Constructs a GeometryFactory that generates Geometries having the givenPrecisionModel
and spatial-reference ID, and the default CoordinateSequence implementation.GeometryFactory
(PrecisionModel precisionModel, int SRID, CoordinateSequenceFactory coordinateSequenceFactory) Constructs a GeometryFactory that generates Geometries having the given PrecisionModel, spatial-reference ID, and CoordinateSequence implementation. -
Method Summary
Modifier and TypeMethodDescriptionbuildGeometry
(Collection geomList) Build an appropriateGeometry
,MultiGeometry
, orGeometryCollection
to contain theGeometry
s in it.createEmpty
(int dimension) Creates an empty atomic geometry of the given dimension.Creates a deep copy of the inputGeometry
.Constructs an emptyGeometryCollection
geometry.createGeometryCollection
(Geometry[] geometries) Creates a GeometryCollection using the given Geometries; a null or empty array will create an empty GeometryCollection.Constructs an emptyLinearRing
geometry.createLinearRing
(Coordinate[] coordinates) Creates aLinearRing
using the givenCoordinate
s.createLinearRing
(CoordinateSequence coordinates) Creates aLinearRing
using the givenCoordinateSequence
.Constructs an emptyLineString
geometry.createLineString
(Coordinate[] coordinates) Creates a LineString using the given Coordinates.createLineString
(CoordinateSequence coordinates) Creates a LineString using the given CoordinateSequence.Constructs an emptyMultiLineString
geometry.createMultiLineString
(LineString[] lineStrings) Creates a MultiLineString using the given LineStrings; a null or empty array will create an empty MultiLineString.Constructs an emptyMultiPoint
geometry.createMultiPoint
(Coordinate[] coordinates) Deprecated.createMultiPoint
(CoordinateSequence coordinates) Creates aMultiPoint
using the points in the givenCoordinateSequence
.createMultiPoint
(Point[] point) Creates aMultiPoint
using the givenPoint
s.createMultiPointFromCoords
(Coordinate[] coordinates) Creates aMultiPoint
using the givenCoordinate
s.Constructs an emptyMultiPolygon
geometry.createMultiPolygon
(Polygon[] polygons) Creates a MultiPolygon using the given Polygons; a null or empty array will create an empty Polygon.Constructs an emptyPoint
geometry.createPoint
(Coordinate coordinate) Creates a Point using the given Coordinate.createPoint
(CoordinateSequence coordinates) Creates a Point using the given CoordinateSequence; a null or empty CoordinateSequence will create an empty Point.static Point
createPointFromInternalCoord
(Coordinate coord, Geometry exemplar) Constructs an emptyPolygon
geometry.createPolygon
(Coordinate[] shell) Constructs aPolygon
with the given exterior boundary.createPolygon
(CoordinateSequence shell) Constructs aPolygon
with the given exterior boundary.createPolygon
(LinearRing shell) Constructs aPolygon
with the given exterior boundary.createPolygon
(LinearRing shell, LinearRing[] holes) Constructs aPolygon
with the given exterior boundary and interior boundaries.Returns the PrecisionModel that Geometries created by this factory will be associated with.int
getSRID()
Gets the SRID value defined for this factory.toGeometry
(Envelope envelope) Creates aGeometry
with the same extent as the given envelope.static Geometry[]
toGeometryArray
(Collection geometries) Converts theList
to an array.static LinearRing[]
toLinearRingArray
(Collection linearRings) Converts theList
to an array.static LineString[]
toLineStringArray
(Collection lineStrings) Converts theList
to an array.static MultiLineString[]
toMultiLineStringArray
(Collection multiLineStrings) Converts theList
to an array.static MultiPoint[]
toMultiPointArray
(Collection multiPoints) Converts theList
to an array.static MultiPolygon[]
toMultiPolygonArray
(Collection multiPolygons) Converts theList
to an array.static Point[]
toPointArray
(Collection points) Converts theList
to an array.static Polygon[]
toPolygonArray
(Collection polygons) Converts theList
to an array.
-
Constructor Details
-
GeometryFactory
public GeometryFactory(PrecisionModel precisionModel, int SRID, CoordinateSequenceFactory coordinateSequenceFactory) Constructs a GeometryFactory that generates Geometries having the given PrecisionModel, spatial-reference ID, and CoordinateSequence implementation. -
GeometryFactory
Constructs a GeometryFactory that generates Geometries having the given CoordinateSequence implementation, a double-precision floating PrecisionModel and a spatial-reference ID of 0. -
GeometryFactory
Constructs a GeometryFactory that generates Geometries having the givenPrecisionModel
and the default CoordinateSequence implementation.- Parameters:
precisionModel
- the PrecisionModel to use
-
GeometryFactory
Constructs a GeometryFactory that generates Geometries having the givenPrecisionModel
and spatial-reference ID, and the default CoordinateSequence implementation.- Parameters:
precisionModel
- the PrecisionModel to useSRID
- the SRID to use
-
GeometryFactory
public GeometryFactory()Constructs a GeometryFactory that generates Geometries having a floating PrecisionModel and a spatial-reference ID of 0.
-
-
Method Details
-
createPointFromInternalCoord
-
toPointArray
Converts theList
to an array.- Parameters:
points
- theList
of Points to convert- Returns:
- the
List
in array format
-
toGeometryArray
Converts theList
to an array.- Parameters:
geometries
- the list ofGeometry's
to convert- Returns:
- the
List
in array format
-
toLinearRingArray
Converts theList
to an array.- Parameters:
linearRings
- theList
of LinearRings to convert- Returns:
- the
List
in array format
-
toLineStringArray
Converts theList
to an array.- Parameters:
lineStrings
- theList
of LineStrings to convert- Returns:
- the
List
in array format
-
toPolygonArray
Converts theList
to an array.- Parameters:
polygons
- theList
of Polygons to convert- Returns:
- the
List
in array format
-
toMultiPolygonArray
Converts theList
to an array.- Parameters:
multiPolygons
- theList
of MultiPolygons to convert- Returns:
- the
List
in array format
-
toMultiLineStringArray
Converts theList
to an array.- Parameters:
multiLineStrings
- theList
of MultiLineStrings to convert- Returns:
- the
List
in array format
-
toMultiPointArray
Converts theList
to an array.- Parameters:
multiPoints
- theList
of MultiPoints to convert- Returns:
- the
List
in array format
-
toGeometry
Creates aGeometry
with the same extent as the given envelope. The Geometry returned is guaranteed to be valid. To provide this behaviour, the following cases occur:If the
Envelope
is:- null : returns an empty
Point
- a point : returns a non-empty
Point
- a line : returns a two-point
LineString
- a rectangle : returns a
Polygon
whose points are (minx, miny), (minx, maxy), (maxx, maxy), (maxx, miny), (minx, miny).
- Parameters:
envelope
- theEnvelope
to convert- Returns:
- an empty
Point
(for nullEnvelope
s), aPoint
(when min x = max x and min y = max y) or aPolygon
(in all other cases)
- null : returns an empty
-
getPrecisionModel
Returns the PrecisionModel that Geometries created by this factory will be associated with.- Returns:
- the PrecisionModel for this factory
-
createPoint
Constructs an emptyPoint
geometry.- Returns:
- an empty Point
-
createPoint
Creates a Point using the given Coordinate. A null Coordinate creates an empty Geometry.- Parameters:
coordinate
- a Coordinate, or null- Returns:
- the created Point
-
createPoint
Creates a Point using the given CoordinateSequence; a null or empty CoordinateSequence will create an empty Point.- Parameters:
coordinates
- a CoordinateSequence (possibly empty), or null- Returns:
- the created Point
-
createMultiLineString
Constructs an emptyMultiLineString
geometry.- Returns:
- an empty MultiLineString
-
createMultiLineString
Creates a MultiLineString using the given LineStrings; a null or empty array will create an empty MultiLineString.- Parameters:
lineStrings
- LineStrings, each of which may be empty but not null- Returns:
- the created MultiLineString
-
createGeometryCollection
Constructs an emptyGeometryCollection
geometry.- Returns:
- an empty GeometryCollection
-
createGeometryCollection
Creates a GeometryCollection using the given Geometries; a null or empty array will create an empty GeometryCollection.- Parameters:
geometries
- an array of Geometries, each of which may be empty but not null, or null- Returns:
- the created GeometryCollection
-
createMultiPolygon
Constructs an emptyMultiPolygon
geometry.- Returns:
- an empty MultiPolygon
-
createMultiPolygon
Creates a MultiPolygon using the given Polygons; a null or empty array will create an empty Polygon. The polygons must conform to the assertions specified in the OpenGIS Simple Features Specification for SQL.- Parameters:
polygons
- Polygons, each of which may be empty but not null- Returns:
- the created MultiPolygon
-
createLinearRing
Constructs an emptyLinearRing
geometry.- Returns:
- an empty LinearRing
-
createLinearRing
Creates aLinearRing
using the givenCoordinate
s. A null or empty array creates an empty LinearRing. The points must form a closed and simple linestring.- Parameters:
coordinates
- an array without null elements, or an empty array, or null- Returns:
- the created LinearRing
- Throws:
IllegalArgumentException
- if the ring is not closed, or has too few points
-
createLinearRing
Creates aLinearRing
using the givenCoordinateSequence
. A null or empty array creates an empty LinearRing. The points must form a closed and simple linestring.- Parameters:
coordinates
- a CoordinateSequence (possibly empty), or null- Returns:
- the created LinearRing
- Throws:
IllegalArgumentException
- if the ring is not closed, or has too few points
-
createMultiPoint
Constructs an emptyMultiPoint
geometry.- Returns:
- an empty MultiPoint
-
createMultiPoint
Creates aMultiPoint
using the givenPoint
s. A null or empty array will create an empty MultiPoint.- Parameters:
point
- an array of Points (without null elements), or an empty array, ornull
- Returns:
- a MultiPoint object
-
createMultiPoint
Deprecated.Creates aMultiPoint
using the givenCoordinate
s. A null or empty array will create an empty MultiPoint.- Parameters:
coordinates
- an array (without null elements), or an empty array, ornull
- Returns:
- a MultiPoint object
-
createMultiPointFromCoords
Creates aMultiPoint
using the givenCoordinate
s. A null or empty array will create an empty MultiPoint.- Parameters:
coordinates
- an array (without null elements), or an empty array, ornull
- Returns:
- a MultiPoint object
-
createMultiPoint
Creates aMultiPoint
using the points in the givenCoordinateSequence
. Anull
or empty CoordinateSequence creates an empty MultiPoint.- Parameters:
coordinates
- a CoordinateSequence (possibly empty), ornull
- Returns:
- a MultiPoint geometry
-
createPolygon
Constructs aPolygon
with the given exterior boundary and interior boundaries.- Parameters:
shell
- the outer boundary of the newPolygon
, ornull
or an emptyLinearRing
if the empty geometry is to be created.holes
- the inner boundaries of the newPolygon
, ornull
or emptyLinearRing
s if the empty geometry is to be created.- Throws:
IllegalArgumentException
- if a ring is invalid
-
createPolygon
Constructs aPolygon
with the given exterior boundary.- Parameters:
shell
- the outer boundary of the newPolygon
, ornull
or an emptyLinearRing
if the empty geometry is to be created.- Throws:
IllegalArgumentException
- if the boundary ring is invalid
-
createPolygon
Constructs aPolygon
with the given exterior boundary.- Parameters:
shell
- the outer boundary of the newPolygon
, ornull
or an emptyLinearRing
if the empty geometry is to be created.- Throws:
IllegalArgumentException
- if the boundary ring is invalid
-
createPolygon
Constructs aPolygon
with the given exterior boundary.- Parameters:
shell
- the outer boundary of the newPolygon
, ornull
or an emptyLinearRing
if the empty geometry is to be created.- Throws:
IllegalArgumentException
- if the boundary ring is invalid
-
createPolygon
Constructs an emptyPolygon
geometry.- Returns:
- an empty polygon
-
buildGeometry
Build an appropriateGeometry
,MultiGeometry
, orGeometryCollection
to contain theGeometry
s in it. For example:
- If
geomList
contains a singlePolygon
, thePolygon
is returned. - If
geomList
contains severalPolygon
s, aMultiPolygon
is returned. - If
geomList
contains somePolygon
s and someLineString
s, aGeometryCollection
is returned. - If
geomList
is empty, an emptyGeometryCollection
is returned
- Parameters:
geomList
- theGeometry
s to combine- Returns:
- a
Geometry
of the "smallest", "most type-specific" class that can contain the elements ofgeomList
.
- If
-
createLineString
Constructs an emptyLineString
geometry.- Returns:
- an empty LineString
-
createLineString
Creates a LineString using the given Coordinates. A null or empty array creates an empty LineString.- Parameters:
coordinates
- an array without null elements, or an empty array, or null
-
createLineString
Creates a LineString using the given CoordinateSequence. A null or empty CoordinateSequence creates an empty LineString.- Parameters:
coordinates
- a CoordinateSequence (possibly empty), or null
-
createEmpty
Creates an empty atomic geometry of the given dimension. If passed a dimension of -1 will create an emptyGeometryCollection
.- Parameters:
dimension
- the required dimension (-1, 0, 1 or 2)- Returns:
- an empty atomic geometry of given dimension
-
createGeometry
Creates a deep copy of the inputGeometry
. TheCoordinateSequenceFactory
defined for this factory is used to copy theCoordinateSequence
s of the input geometry.This is a convenient way to change the CoordinateSequence used to represent a geometry, or to change the factory used for a geometry.
Geometry.copy()
can also be used to make a deep copy, but it does not allow changing the CoordinateSequence type.- Returns:
- a deep copy of the input geometry, using the CoordinateSequence type of this factory
- See Also:
-
getSRID
public int getSRID()Gets the SRID value defined for this factory.- Returns:
- the factory SRID value
-
getCoordinateSequenceFactory
-
createMultiPointFromCoords(org.locationtech.jts.geom.Coordinate[])
instead