Class ShapeConverter
java.lang.Object
org.apache.sis.internal.feature.jts.ShapeConverter
- Direct Known Subclasses:
ShapeConverter.Double
,ShapeConverter.Float
Converts a Java2D
Shape
to a JTS Geometry
.
Two subclasses exist depending on whether the geometries will store
coordinates as float
or double
floating point numbers.- Since:
- 1.2
- Version:
- 1.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
Number of dimensions of geometries built by this class.private final org.locationtech.jts.geom.GeometryFactory
The JTS factory for creating geometry.private final List
<org.locationtech.jts.geom.Geometry> All geometries that are component of a multi-geometries.private int
Bitmask combination of the type of all geometries built.private static final int
Initial number of coordinate values that the buffer can hold.protected final PathIterator
Iterator over the coordinates of the Java2D shape to convert to a JTS geometry.protected int
Number of values in thefloat[]
ordouble[]
array stored by sub-class.private static final int
Bit mask of the kind of geometric objects created.private static final int
Bit mask of the kind of geometric objects created.private static final int
Bit mask of the kind of geometric objects created. -
Constructor Summary
ConstructorsConstructorDescriptionShapeConverter
(org.locationtech.jts.geom.GeometryFactory factory, PathIterator iterator, boolean isFloat) Creates a new converter from Java2D shape to JTS geometry. -
Method Summary
Modifier and TypeMethodDescription(package private) abstract void
addPoint()
Stores the single point obtained by the last call tocurrentSegment()
.private org.locationtech.jts.geom.Geometry
build()
Iterates over all coordinates given by theiterator
and stores them in a JTS geometry.(package private) static org.locationtech.jts.geom.Geometry
Converts a Java2D Shape to a JTS geometry.(package private) abstract int
Returns the coordinates and type of the current path segment in the iteration.private void
flush
(boolean isRing) Copies current coordinates in a new JTS geometry, then resetslength
to 0 in preparation for the next geometry.(package private) abstract PackedCoordinateSequence
toSequence
(boolean close) Returns a copy of current coordinate values as a JTS coordinate sequence.
-
Field Details
-
DIMENSION
private static final int DIMENSIONNumber of dimensions of geometries built by this class.- See Also:
-
INITIAL_CAPACITY
private static final int INITIAL_CAPACITYInitial number of coordinate values that the buffer can hold. The buffer capacity will be expanded as needed.- See Also:
-
POINT
private static final int POINTBit mask of the kind of geometric objects created. Used for detecting if all objects are of the same type.- See Also:
-
LINESTRING
private static final int LINESTRINGBit mask of the kind of geometric objects created. Used for detecting if all objects are of the same type.- See Also:
-
POLYGON
private static final int POLYGONBit mask of the kind of geometric objects created. Used for detecting if all objects are of the same type.- See Also:
-
geometries
All geometries that are component of a multi-geometries. The above masks tell if the geometry can be built as a multi-line strings or multi-points. -
factory
private final org.locationtech.jts.geom.GeometryFactory factoryThe JTS factory for creating geometry. May be user-specified. Note that theCoordinateSequenceFactory
is ignored; -
iterator
Iterator over the coordinates of the Java2D shape to convert to a JTS geometry. -
length
protected int lengthNumber of values in thefloat[]
ordouble[]
array stored by sub-class. -
geometryType
private int geometryTypeBitmask combination of the type of all geometries built. This is a combination ofPOINT
,LINESTRING
and/orPOLYGON
.
-
-
Constructor Details
-
ShapeConverter
ShapeConverter(org.locationtech.jts.geom.GeometryFactory factory, PathIterator iterator, boolean isFloat) Creates a new converter from Java2D shape to JTS geometry.- Parameters:
factory
- the JTS factory for creating geometry, ornull
for automatic.iterator
- iterator over the coordinates of the Java2D shape to convert to a JTS geometry.isFloat
- whether to store coordinates asfloat
instead ofdouble
.
-
-
Method Details
-
create
static org.locationtech.jts.geom.Geometry create(org.locationtech.jts.geom.GeometryFactory factory, Shape shape, double flatness) Converts a Java2D Shape to a JTS geometry. Coordinates are copies; this is not a view.- Parameters:
factory
- factory to use for creating the geometry, ornull
for the default.shape
- the Java2D shape to convert. Cannot benull
.flatness
- the maximum distance that line segments are allowed to deviate from curves.- Returns:
- JTS geometry with shape coordinates. Never null but can be empty.
-
currentSegment
abstract int currentSegment()Returns the coordinates and type of the current path segment in the iteration. This method delegate to one of the twoPathIterator.currentSegment(…)
methods, depending on the precision of floating-point values. -
addPoint
abstract void addPoint()Stores the single point obtained by the last call tocurrentSegment()
. As a consequence,length
is increased by 2. -
toSequence
Returns a copy of current coordinate values as a JTS coordinate sequence. The number of values to copy in a new array islength
. The copy is wrapped in aPackedCoordinateSequence
.- Parameters:
close
- whether to ensure that the first point is repeated as the last point.- Returns:
- a JTS coordinate sequence containing a copy of current coordinate values.
-
build
private org.locationtech.jts.geom.Geometry build()Iterates over all coordinates given by theiterator
and stores them in a JTS geometry. The path shall contain only straight lines; curves are not supported. -
flush
private void flush(boolean isRing) Copies current coordinates in a new JTS geometry, then resetslength
to 0 in preparation for the next geometry.- Parameters:
isRing
- whether the geometry should be a closed polygon.
-