Package org.locationtech.jts.geom
Class GeometryFactory
- java.lang.Object
-
- org.locationtech.jts.geom.GeometryFactory
-
- All Implemented Interfaces:
Serializable
public class GeometryFactory extends Object implements 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.
- Version:
- 1.7
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GeometryFactory()Constructs 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 givenPrecisionModeland the default CoordinateSequence implementation.GeometryFactory(PrecisionModel precisionModel, int SRID)Constructs a GeometryFactory that generates Geometries having the givenPrecisionModeland 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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description GeometrybuildGeometry(Collection geomList)Build an appropriateGeometry,MultiGeometry, orGeometryCollectionto contain theGeometrys in it.GeometrycreateGeometry(Geometry g)Creates a deep copy of the inputGeometry.GeometryCollectioncreateGeometryCollection()GeometryCollectioncreateGeometryCollection(Geometry[] geometries)Creates a GeometryCollection using the given Geometries; a null or empty array will create an empty GeometryCollection.LinearRingcreateLinearRing()LinearRingcreateLinearRing(Coordinate[] coordinates)Creates aLinearRingusing the givenCoordinates.LinearRingcreateLinearRing(CoordinateSequence coordinates)Creates aLinearRingusing the givenCoordinateSequence.LineStringcreateLineString()LineStringcreateLineString(Coordinate[] coordinates)Creates a LineString using the given Coordinates.LineStringcreateLineString(CoordinateSequence coordinates)Creates a LineString using the given CoordinateSequence.MultiLineStringcreateMultiLineString()MultiLineStringcreateMultiLineString(LineString[] lineStrings)Creates a MultiLineString using the given LineStrings; a null or empty array will create an empty MultiLineString.MultiPointcreateMultiPoint()MultiPointcreateMultiPoint(Coordinate[] coordinates)Deprecated.MultiPointcreateMultiPoint(CoordinateSequence coordinates)Creates aMultiPointusing the points in the givenCoordinateSequence.MultiPointcreateMultiPoint(Point[] point)Creates aMultiPointusing the givenPoints.MultiPointcreateMultiPointFromCoords(Coordinate[] coordinates)Creates aMultiPointusing the givenCoordinates.MultiPolygoncreateMultiPolygon()MultiPolygoncreateMultiPolygon(Polygon[] polygons)Creates a MultiPolygon using the given Polygons; a null or empty array will create an empty Polygon.PointcreatePoint()PointcreatePoint(Coordinate coordinate)Creates a Point using the given Coordinate.PointcreatePoint(CoordinateSequence coordinates)Creates a Point using the given CoordinateSequence; a null or empty CoordinateSequence will create an empty Point.static PointcreatePointFromInternalCoord(Coordinate coord, Geometry exemplar)PolygoncreatePolygon()PolygoncreatePolygon(Coordinate[] shell)Constructs aPolygonwith the given exterior boundary.PolygoncreatePolygon(CoordinateSequence shell)Constructs aPolygonwith the given exterior boundary.PolygoncreatePolygon(LinearRing shell)Constructs aPolygonwith the given exterior boundary.PolygoncreatePolygon(LinearRing shell, LinearRing[] holes)Constructs aPolygonwith the given exterior boundary and interior boundaries.CoordinateSequenceFactorygetCoordinateSequenceFactory()PrecisionModelgetPrecisionModel()Returns the PrecisionModel that Geometries created by this factory will be associated with.intgetSRID()Gets the SRID value defined for this factory.GeometrytoGeometry(Envelope envelope)Creates aGeometrywith the same extent as the given envelope.static Geometry[]toGeometryArray(Collection geometries)Converts theListto an array.static LinearRing[]toLinearRingArray(Collection linearRings)Converts theListto an array.static LineString[]toLineStringArray(Collection lineStrings)Converts theListto an array.static MultiLineString[]toMultiLineStringArray(Collection multiLineStrings)Converts theListto an array.static MultiPoint[]toMultiPointArray(Collection multiPoints)Converts theListto an array.static MultiPolygon[]toMultiPolygonArray(Collection multiPolygons)Converts theListto an array.static Point[]toPointArray(Collection points)Converts theListto an array.static Polygon[]toPolygonArray(Collection polygons)Converts theListto an array.
-
-
-
Constructor Detail
-
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
public 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
public GeometryFactory(PrecisionModel precisionModel)
Constructs a GeometryFactory that generates Geometries having the givenPrecisionModeland the default CoordinateSequence implementation.- Parameters:
precisionModel- the PrecisionModel to use
-
GeometryFactory
public GeometryFactory(PrecisionModel precisionModel, int SRID)
Constructs a GeometryFactory that generates Geometries having the givenPrecisionModeland 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 Detail
-
createPointFromInternalCoord
public static Point createPointFromInternalCoord(Coordinate coord, Geometry exemplar)
-
toPointArray
public static Point[] toPointArray(Collection points)
Converts theListto an array.- Parameters:
points- theListof Points to convert- Returns:
- the
Listin array format
-
toGeometryArray
public static Geometry[] toGeometryArray(Collection geometries)
Converts theListto an array.- Parameters:
geometries- the list ofGeometry'sto convert- Returns:
- the
Listin array format
-
toLinearRingArray
public static LinearRing[] toLinearRingArray(Collection linearRings)
Converts theListto an array.- Parameters:
linearRings- theListof LinearRings to convert- Returns:
- the
Listin array format
-
toLineStringArray
public static LineString[] toLineStringArray(Collection lineStrings)
Converts theListto an array.- Parameters:
lineStrings- theListof LineStrings to convert- Returns:
- the
Listin array format
-
toPolygonArray
public static Polygon[] toPolygonArray(Collection polygons)
Converts theListto an array.- Parameters:
polygons- theListof Polygons to convert- Returns:
- the
Listin array format
-
toMultiPolygonArray
public static MultiPolygon[] toMultiPolygonArray(Collection multiPolygons)
Converts theListto an array.- Parameters:
multiPolygons- theListof MultiPolygons to convert- Returns:
- the
Listin array format
-
toMultiLineStringArray
public static MultiLineString[] toMultiLineStringArray(Collection multiLineStrings)
Converts theListto an array.- Parameters:
multiLineStrings- theListof MultiLineStrings to convert- Returns:
- the
Listin array format
-
toMultiPointArray
public static MultiPoint[] toMultiPointArray(Collection multiPoints)
Converts theListto an array.- Parameters:
multiPoints- theListof MultiPoints to convert- Returns:
- the
Listin array format
-
toGeometry
public Geometry toGeometry(Envelope envelope)
Creates aGeometrywith 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
Envelopeis:- null : returns an empty
Point - a point : returns a non-empty
Point - a line : returns a two-point
LineString - a rectangle : returns a
Polygonwhose points are (minx, miny), (minx, maxy), (maxx, maxy), (maxx, miny), (minx, miny).
- Parameters:
envelope- theEnvelopeto convert- Returns:
- an empty
Point(for nullEnvelopes), aPoint(when min x = max x and min y = max y) or aPolygon(in all other cases)
- null : returns an empty
-
getPrecisionModel
public PrecisionModel getPrecisionModel()
Returns the PrecisionModel that Geometries created by this factory will be associated with.- Returns:
- the PrecisionModel for this factory
-
createPoint
public Point createPoint()
-
createPoint
public Point createPoint(Coordinate coordinate)
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
public Point createPoint(CoordinateSequence coordinates)
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
public MultiLineString createMultiLineString()
-
createMultiLineString
public MultiLineString createMultiLineString(LineString[] lineStrings)
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
public GeometryCollection createGeometryCollection()
-
createGeometryCollection
public GeometryCollection createGeometryCollection(Geometry[] geometries)
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
public MultiPolygon createMultiPolygon()
-
createMultiPolygon
public MultiPolygon createMultiPolygon(Polygon[] polygons)
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
public LinearRing createLinearRing()
-
createLinearRing
public LinearRing createLinearRing(Coordinate[] coordinates)
Creates aLinearRingusing the givenCoordinates. 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
public LinearRing createLinearRing(CoordinateSequence coordinates)
Creates aLinearRingusing 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
public MultiPoint createMultiPoint()
-
createMultiPoint
public MultiPoint createMultiPoint(Point[] point)
Creates aMultiPointusing the givenPoints. 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
public MultiPoint createMultiPoint(Coordinate[] coordinates)
Deprecated.Creates aMultiPointusing the givenCoordinates. 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
public MultiPoint createMultiPointFromCoords(Coordinate[] coordinates)
Creates aMultiPointusing the givenCoordinates. 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
public MultiPoint createMultiPoint(CoordinateSequence coordinates)
Creates aMultiPointusing the points in the givenCoordinateSequence. Anullor empty CoordinateSequence creates an empty MultiPoint.- Parameters:
coordinates- a CoordinateSequence (possibly empty), ornull- Returns:
- a MultiPoint geometry
-
createPolygon
public Polygon createPolygon(LinearRing shell, LinearRing[] holes)
Constructs aPolygonwith the given exterior boundary and interior boundaries.- Parameters:
shell- the outer boundary of the newPolygon, ornullor an emptyLinearRingif the empty geometry is to be created.holes- the inner boundaries of the newPolygon, ornullor emptyLinearRings if the empty geometry is to be created.- Throws:
IllegalArgumentException- if a ring is invalid
-
createPolygon
public Polygon createPolygon(CoordinateSequence shell)
Constructs aPolygonwith the given exterior boundary.- Parameters:
shell- the outer boundary of the newPolygon, ornullor an emptyLinearRingif the empty geometry is to be created.- Throws:
IllegalArgumentException- if the boundary ring is invalid
-
createPolygon
public Polygon createPolygon(Coordinate[] shell)
Constructs aPolygonwith the given exterior boundary.- Parameters:
shell- the outer boundary of the newPolygon, ornullor an emptyLinearRingif the empty geometry is to be created.- Throws:
IllegalArgumentException- if the boundary ring is invalid
-
createPolygon
public Polygon createPolygon(LinearRing shell)
Constructs aPolygonwith the given exterior boundary.- Parameters:
shell- the outer boundary of the newPolygon, ornullor an emptyLinearRingif the empty geometry is to be created.- Throws:
IllegalArgumentException- if the boundary ring is invalid
-
createPolygon
public Polygon createPolygon()
-
buildGeometry
public Geometry buildGeometry(Collection geomList)
Build an appropriateGeometry,MultiGeometry, orGeometryCollectionto contain theGeometrys in it. For example:
- If
geomListcontains a singlePolygon, thePolygonis returned. - If
geomListcontains severalPolygons, aMultiPolygonis returned. - If
geomListcontains somePolygons and someLineStrings, aGeometryCollectionis returned. - If
geomListis empty, an emptyGeometryCollectionis returned
- Parameters:
geomList- theGeometrys to combine- Returns:
- a
Geometryof the "smallest", "most type-specific" class that can contain the elements ofgeomList.
- If
-
createLineString
public LineString createLineString()
-
createLineString
public LineString createLineString(Coordinate[] coordinates)
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
public LineString createLineString(CoordinateSequence coordinates)
Creates a LineString using the given CoordinateSequence. A null or empty CoordinateSequence creates an empty LineString.- Parameters:
coordinates- a CoordinateSequence (possibly empty), or null
-
createGeometry
public Geometry createGeometry(Geometry g)
Creates a deep copy of the inputGeometry. TheCoordinateSequenceFactorydefined for this factory is used to copy theCoordinateSequences 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:
Geometry.copy()
-
getSRID
public int getSRID()
Gets the SRID value defined for this factory.- Returns:
- the factory SRID value
-
getCoordinateSequenceFactory
public CoordinateSequenceFactory getCoordinateSequenceFactory()
-
-