Class ShapeConverter

java.lang.Object
org.apache.sis.internal.feature.jts.ShapeConverter
Direct Known Subclasses:
ShapeConverter.Double, ShapeConverter.Float

abstract class ShapeConverter extends Object
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 Classes
    Modifier and Type
    Class
    Description
    private static final class 
    A converter of Java2D Shape to a JTS Geometry storing coordinates as double values.
    private static final class 
    A converter of Java2D Shape to a JTS Geometry storing coordinates as float values.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private 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 the float[] or double[] 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

    Constructors
    Constructor
    Description
    ShapeConverter(org.locationtech.jts.geom.GeometryFactory factory, PathIterator iterator, boolean isFloat)
    Creates a new converter from Java2D shape to JTS geometry.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) abstract void
    Stores the single point obtained by the last call to currentSegment().
    private org.locationtech.jts.geom.Geometry
    Iterates over all coordinates given by the iterator and stores them in a JTS geometry.
    (package private) 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.
    (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 resets length 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DIMENSION

      private static final int DIMENSION
      Number of dimensions of geometries built by this class.
      See Also:
    • INITIAL_CAPACITY

      private static final int INITIAL_CAPACITY
      Initial number of coordinate values that the buffer can hold. The buffer capacity will be expanded as needed.
      See Also:
    • POINT

      private static final int POINT
      Bit 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 LINESTRING
      Bit 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 POLYGON
      Bit mask of the kind of geometric objects created. Used for detecting if all objects are of the same type.
      See Also:
    • geometries

      private final List<org.locationtech.jts.geom.Geometry> 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 factory
      The JTS factory for creating geometry. May be user-specified. Note that the CoordinateSequenceFactory is ignored;
    • iterator

      protected final PathIterator iterator
      Iterator over the coordinates of the Java2D shape to convert to a JTS geometry.
    • length

      protected int length
      Number of values in the float[] or double[] array stored by sub-class.
    • geometryType

      private int geometryType
      Bitmask combination of the type of all geometries built. This is a combination of POINT, LINESTRING and/or POLYGON.
  • 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, or null for automatic.
      iterator - iterator over the coordinates of the Java2D shape to convert to a JTS geometry.
      isFloat - whether to store coordinates as float instead of double.
  • 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, or null for the default.
      shape - the Java2D shape to convert. Cannot be null.
      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 two PathIterator.currentSegment(…) methods, depending on the precision of floating-point values.
    • addPoint

      abstract void addPoint()
      Stores the single point obtained by the last call to currentSegment(). As a consequence, length is increased by 2.
    • toSequence

      abstract PackedCoordinateSequence toSequence(boolean close)
      Returns a copy of current coordinate values as a JTS coordinate sequence. The number of values to copy in a new array is length. The copy is wrapped in a PackedCoordinateSequence.
      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 the iterator 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 resets length to 0 in preparation for the next geometry.
      Parameters:
      isRing - whether the geometry should be a closed polygon.