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 classprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intNumber of dimensions of geometries built by this class.private final org.locationtech.jts.geom.GeometryFactoryThe JTS factory for creating geometry.private final List<org.locationtech.jts.geom.Geometry>All geometries that are component of a multi-geometries.private intBitmask combination of the type of all geometries built.private static final intInitial number of coordinate values that the buffer can hold.protected final PathIteratorIterator over the coordinates of the Java2D shape to convert to a JTS geometry.protected intNumber of values in thefloat[]ordouble[]array stored by sub-class.private static final intBit mask of the kind of geometric objects created.private static final intBit mask of the kind of geometric objects created.private static final intBit 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 voidaddPoint()Stores the single point obtained by the last call tocurrentSegment().private org.locationtech.jts.geom.Geometrybuild()Iterates over all coordinates given by theiteratorand stores them in a JTS geometry.(package private) static org.locationtech.jts.geom.GeometryConverts a Java2D Shape to a JTS geometry.(package private) abstract intReturns the coordinates and type of the current path segment in the iteration.private voidflush(boolean isRing) Copies current coordinates in a new JTS geometry, then resetslengthto 0 in preparation for the next geometry.(package private) abstract PackedCoordinateSequencetoSequence(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 theCoordinateSequenceFactoryis 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,LINESTRINGand/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, ornullfor automatic.iterator- iterator over the coordinates of the Java2D shape to convert to a JTS geometry.isFloat- whether to store coordinates asfloatinstead 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, ornullfor 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,lengthis 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 theiteratorand 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 resetslengthto 0 in preparation for the next geometry.- Parameters:
isRing- whether the geometry should be a closed polygon.
-