Class Factory
java.lang.Object
org.apache.sis.internal.feature.Geometries<org.locationtech.jts.geom.Geometry>
org.apache.sis.internal.feature.jts.Factory
- All Implemented Interfaces:
Serializable
The factory of geometry objects backed by Java Topology Suite (JTS).
- Since:
- 0.7
- Version:
- 1.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.locationtech.jts.geom.GeometryFactory
The factory to use for creating JTS geometries.private final org.locationtech.jts.geom.GeometryFactory
The factory to use for creating JTS geometries.static final Factory
The singleton instance of this factory.private static final long
For cross-version compatibility.Fields inherited from class org.apache.sis.internal.feature.Geometries
BIDIMENSIONAL, library, pointClass, polygonClass, polylineClass, rootClass, TRIDIMENSIONAL
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGeometryWrapper<org.locationtech.jts.geom.Geometry>
castOrWrap
(Object geometry) Returns a wrapper for the given<G>
orGeometryWrapper<G>
geometry.private <G extends org.locationtech.jts.geom.Geometry>
org.locationtech.jts.geom.GeometrycreateFromComponents
(G[] geometries, Function<G, org.locationtech.jts.geom.CoordinateSequence> csGetter, BiFunction<org.locationtech.jts.geom.GeometryFactory, G[], org.locationtech.jts.geom.Geometry> builder) Creates a geometry from an array of components, which may be single or double-precision.GeometryWrapper<org.locationtech.jts.geom.Geometry>
createFromComponents
(GeometryType type, Object components) Creates a geometry from components.GeometryWrapper<org.locationtech.jts.geom.Geometry>
createMultiPolygon
(Object[] geometries) Creates a multi-polygon from an array of JTSPolygon
orLinearRing
.createPoint
(double x, double y) Creates a two-dimensional point from the given coordinates.createPoint
(double x, double y, double z) Creates a three-dimensional point from the given coordinates.createPoint
(float x, float y) Single-precision variant ofcreatePoint(double, double)
.org.locationtech.jts.geom.Geometry
createPolyline
(boolean polygon, int dimension, Vector... coordinates) Creates a polyline from the given coordinate values.protected GeometryWrapper<org.locationtech.jts.geom.Geometry>
createWrapper
(org.locationtech.jts.geom.Geometry geometry) Creates a wrapper for the given geometry instance.final org.locationtech.jts.geom.GeometryFactory
factory
(boolean isFloat) Returns the geometry factory to use for the given precision.Class<?>
getGeometryClass
(GeometryType type) Returns the geometry class of the given instance.(package private) static boolean
isFloat
(boolean previous, org.locationtech.jts.geom.Point geometry) Returnstrue
ifprevious
istrue
and the given point uses single-precision.(package private) static boolean
isFloat
(org.locationtech.jts.geom.CoordinateSequence cs) Returnstrue
if the given sequence stores coordinates as single-precision floating point values.GeometryWrapper<org.locationtech.jts.geom.Geometry>
parseWKB
(ByteBuffer data) Reads the given Well Known Binary (WKB).GeometryWrapper<org.locationtech.jts.geom.Geometry>
Parses the given Well Known Text (WKT).protected Object
Invoked at deserialization time for obtaining the unique instance of thisGeometries
class.(package private) final org.locationtech.jts.geom.Geometry
toGeometry
(List<org.locationtech.jts.geom.Geometry> lines, boolean polygon, boolean isFloat) Returns the given list of polygons or line strings as a single geometry.(package private) final void
toLineString
(List<org.locationtech.jts.geom.Coordinate> coordinates, List<org.locationtech.jts.geom.Geometry> addTo, boolean polygon, boolean isFloat) Makes a line string or linear ring from the given coordinates, and adds the line string to the given list.Methods inherited from class org.apache.sis.internal.feature.Geometries
createPoint, implementation, implementation, isKnownType, mergePolylines, supportSinglePrecision, toGeometry2D, unsupported, unsupported, unwrap, wrap
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
INSTANCE
The singleton instance of this factory.- See Also:
-
factory
private final transient org.locationtech.jts.geom.GeometryFactory factoryThe factory to use for creating JTS geometries. Set to a factory using double-precision (factory
) or single-precision (fctry32
) floating point numbers and a spatial-reference ID of 0.Not serialized because
readResolve()
will replace byINSTANCE
.- See Also:
-
fctry32
private final transient org.locationtech.jts.geom.GeometryFactory fctry32The factory to use for creating JTS geometries. Set to a factory using double-precision (factory
) or single-precision (fctry32
) floating point numbers and a spatial-reference ID of 0.Not serialized because
readResolve()
will replace byINSTANCE
.- See Also:
-
-
Constructor Details
-
Factory
private Factory()Creates the singleton instance.
-
-
Method Details
-
readResolve
Invoked at deserialization time for obtaining the unique instance of thisGeometries
class.- Returns:
INSTANCE
.- Throws:
ObjectStreamException
- if the object state is invalid.
-
getGeometryClass
Returns the geometry class of the given instance.- Overrides:
getGeometryClass
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
type
- type of geometry for which the class is desired.- Returns:
- implementation class for the geometry of the specified type.
-
castOrWrap
Returns a wrapper for the given<G>
orGeometryWrapper<G>
geometry.- Specified by:
castOrWrap
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
geometry
- the geometry instance to wrap (can benull
).- Returns:
- a wrapper for the given geometry implementation, or
null
. - Throws:
ClassCastException
- if the given geometry is not an instance of valid type.- See Also:
-
createWrapper
protected GeometryWrapper<org.locationtech.jts.geom.Geometry> createWrapper(org.locationtech.jts.geom.Geometry geometry) Creates a wrapper for the given geometry instance.- Specified by:
createWrapper
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
geometry
- the geometry to wrap.- Returns:
- wrapper for the given geometry.
- See Also:
-
isFloat
static boolean isFloat(org.locationtech.jts.geom.CoordinateSequence cs) Returnstrue
if the given sequence stores coordinates as single-precision floating point values. -
isFloat
static boolean isFloat(boolean previous, org.locationtech.jts.geom.Point geometry) Returnstrue
ifprevious
istrue
and the given point uses single-precision. This is a convenience method for less distraction in code using it.- Parameters:
previous
- previous value ofisFloat
boolean.geometry
- the geometry to combine with previous value.- Returns:
- new value of
isFloat
boolean.
-
factory
public final org.locationtech.jts.geom.GeometryFactory factory(boolean isFloat) Returns the geometry factory to use for the given precision.- Parameters:
isFloat
-true
for single-precision, orfalse
for double-precision (default).- Returns:
- the JTS geometry factory for the given precision.
- See Also:
-
createPoint
Single-precision variant ofcreatePoint(double, double)
.- Overrides:
createPoint
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
x
- the first coordinate value.y
- the second coordinate value.- Returns:
- the point for the given coordinate values.
- See Also:
-
createPoint
Creates a two-dimensional point from the given coordinates.- Specified by:
createPoint
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
x
- the first coordinate value.y
- the second coordinate value.- Returns:
- the point for the given coordinate values.
- See Also:
-
createPoint
Creates a three-dimensional point from the given coordinates.- Specified by:
createPoint
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
x
- the first coordinate value.y
- the second coordinate value.z
- the third coordinate value.- Returns:
- the point for the given coordinate values.
- See Also:
-
createPolyline
public org.locationtech.jts.geom.Geometry createPolyline(boolean polygon, int dimension, Vector... coordinates) Creates a polyline from the given coordinate values. EachDouble.NaN
coordinate value starts a new path.- Specified by:
createPolyline
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
polygon
- whether to return the path as a polygon instead of polyline.dimension
- the number of dimensions (2 or 3).coordinates
- sequence of (x,y) or (x,y,z) tuples.- Returns:
- the geometric object for the given points.
- Throws:
UnsupportedOperationException
- if this operation is not implemented for the given number of dimensions.
-
createMultiPolygon
Creates a multi-polygon from an array of JTSPolygon
orLinearRing
. If some geometries are actually linear rings, they will be converted to polygons.- Specified by:
createMultiPolygon
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
geometries
- the polygons or linear rings to put in a multi-polygons.- Returns:
- the multi-polygon.
- Throws:
ClassCastException
- if an element in the array is not a JTS geometry.IllegalArgumentException
- if an element is a non-closed linear string.
-
toLineString
final void toLineString(List<org.locationtech.jts.geom.Coordinate> coordinates, List<org.locationtech.jts.geom.Geometry> addTo, boolean polygon, boolean isFloat) Makes a line string or linear ring from the given coordinates, and adds the line string to the given list. If thepolygon
argument istrue
, then this method creates polygons instead of line strings. If the given coordinates list is empty, then this method does nothing. This method does not modify the given coordinates list. -
toGeometry
final org.locationtech.jts.geom.Geometry toGeometry(List<org.locationtech.jts.geom.Geometry> lines, boolean polygon, boolean isFloat) Returns the given list of polygons or line strings as a single geometry.- Parameters:
lines
- the polygons or lines strings.- Returns:
true
if the given list containsPolygon
instances, orfalse
if it containsLineString
instances.- Throws:
ArrayStoreException
- if the geometries in the given list are not instances of the type specified by thepolygon
argument.
-
createFromComponents
private <G extends org.locationtech.jts.geom.Geometry> org.locationtech.jts.geom.Geometry createFromComponents(G[] geometries, Function<G, org.locationtech.jts.geom.CoordinateSequence> csGetter, BiFunction<org.locationtech.jts.geom.GeometryFactory, G[], org.locationtech.jts.geom.Geometry> builder) Creates a geometry from an array of components, which may be single or double-precision. If all components use single-precision, then the returned geometry will use single-precision too.We have to use generic type because JTS does not provide an
Geometry.getCoordinateSequence()
abstract method. -
createFromComponents
public GeometryWrapper<org.locationtech.jts.geom.Geometry> createFromComponents(GeometryType type, Object components) Creates a geometry from components. The expectedcomponents
type depend on the target geometry type:- If
type
is a multi-geometry, then the components shall be an array ofPoint
,Geometry
,LineString
orPolygon
elements, depending on the desired target type. - Otherwise the components shall be an array or collection of
Point
orCoordinate
instances, or a JTS-specificCoordinateSequence
.
- Specified by:
createFromComponents
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
type
- type of geometry to create.components
- the components. Valid classes depend on the type of geometry to create.- Returns:
- geometry built from the given components.
- Throws:
ClassCastException
- if the given object is not an array or a collection of supported geometry components.
- If
-
parseWKT
public GeometryWrapper<org.locationtech.jts.geom.Geometry> parseWKT(String wkt) throws org.locationtech.jts.io.ParseException Parses the given Well Known Text (WKT).- Specified by:
parseWKT
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
wkt
- the Well Known Text to parse.- Returns:
- the geometry object for the given WKT.
- Throws:
org.locationtech.jts.io.ParseException
- if the WKT cannot be parsed.- See Also:
-
parseWKB
public GeometryWrapper<org.locationtech.jts.geom.Geometry> parseWKB(ByteBuffer data) throws org.locationtech.jts.io.ParseException Reads the given Well Known Binary (WKB). This implementation does not change the buffer position.- Specified by:
parseWKB
in classGeometries<org.locationtech.jts.geom.Geometry>
- Parameters:
data
- the sequence of bytes to parse.- Returns:
- the geometry object for the given WKB.
- Throws:
org.locationtech.jts.io.ParseException
- if the WKB cannot be parsed.
-