Class ShapeReader

java.lang.Object
org.locationtech.jts.awt.ShapeReader

public class ShapeReader extends Object
Converts a Java2D Shape or the more general PathIterator into a Geometry.

The coordinate system for Java2D is typically screen coordinates, which has the Y axis inverted relative to the usual JTS coordinate system. This is rectified during conversion.

PathIterators to be converted are expected to be linear or flat. That is, they should contain only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE segment types. Any other segment types will cause an exception.

  • Field Details

  • Constructor Details

  • Method Details

    • read

      public static Geometry read(PathIterator pathIt, GeometryFactory geomFact)
      Converts a flat path to a Geometry.
      Parameters:
      pathIt - the path to convert
      geomFact - the GeometryFactory to use
      Returns:
      a Geometry representing the path
    • read

      public static Geometry read(Shape shp, double flatness, GeometryFactory geomFact)
      Converts a Shape to a Geometry, flattening it first.
      Parameters:
      shp - the Java2D shape
      flatness - the flatness parameter to use
      geomFact - the GeometryFactory to use
      Returns:
      a Geometry representing the shape
    • read

      public Geometry read(PathIterator pathIt)
      Converts a flat path to a Geometry.
      Parameters:
      pathIt - the path to convert
      Returns:
      a Geometry representing the path
    • isHole

      private boolean isHole(Coordinate[] pts)
    • toCoordinates

      public static List toCoordinates(PathIterator pathIt)
      Extracts the points of the paths in a flat PathIterator into a list of Coordinate arrays.
      Parameters:
      pathIt - a path iterator
      Returns:
      a List of Coordinate arrays
      Throws:
      IllegalArgumentException - if a non-linear segment type is encountered
    • nextCoordinateArray

      private static Coordinate[] nextCoordinateArray(PathIterator pathIt)