Package org.locationtech.jts.awt
Class ShapeReader
- java.lang.Object
-
- org.locationtech.jts.awt.ShapeReader
-
public class ShapeReader extends java.lang.Object
Converts a Java2DShape
or the more generalPathIterator
into aGeometry
.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 Summary
Fields Modifier and Type Field Description private GeometryFactory
geometryFactory
private static java.awt.geom.AffineTransform
INVERT_Y
-
Constructor Summary
Constructors Constructor Description ShapeReader(GeometryFactory geometryFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
isHole(Coordinate[] pts)
private static Coordinate[]
nextCoordinateArray(java.awt.geom.PathIterator pathIt)
Geometry
read(java.awt.geom.PathIterator pathIt)
Converts a flat path to aGeometry
.static Geometry
read(java.awt.geom.PathIterator pathIt, GeometryFactory geomFact)
Converts a flat path to aGeometry
.static Geometry
read(java.awt.Shape shp, double flatness, GeometryFactory geomFact)
Converts a Shape to a Geometry, flattening it first.static java.util.List
toCoordinates(java.awt.geom.PathIterator pathIt)
Extracts the points of the paths in a flatPathIterator
into a list of Coordinate arrays.
-
-
-
Field Detail
-
INVERT_Y
private static final java.awt.geom.AffineTransform INVERT_Y
-
geometryFactory
private GeometryFactory geometryFactory
-
-
Constructor Detail
-
ShapeReader
public ShapeReader(GeometryFactory geometryFactory)
-
-
Method Detail
-
read
public static Geometry read(java.awt.geom.PathIterator pathIt, GeometryFactory geomFact)
Converts a flat path to aGeometry
.- Parameters:
pathIt
- the path to convertgeomFact
- the GeometryFactory to use- Returns:
- a Geometry representing the path
-
read
public static Geometry read(java.awt.Shape shp, double flatness, GeometryFactory geomFact)
Converts a Shape to a Geometry, flattening it first.- Parameters:
shp
- the Java2D shapeflatness
- the flatness parameter to usegeomFact
- the GeometryFactory to use- Returns:
- a Geometry representing the shape
-
read
public Geometry read(java.awt.geom.PathIterator pathIt)
Converts a flat path to aGeometry
.- Parameters:
pathIt
- the path to convert- Returns:
- a Geometry representing the path
-
isHole
private boolean isHole(Coordinate[] pts)
-
toCoordinates
public static java.util.List toCoordinates(java.awt.geom.PathIterator pathIt)
Extracts the points of the paths in a flatPathIterator
into a list of Coordinate arrays.- Parameters:
pathIt
- a path iterator- Returns:
- a List of Coordinate arrays
- Throws:
java.lang.IllegalArgumentException
- if a non-linear segment type is encountered
-
nextCoordinateArray
private static Coordinate[] nextCoordinateArray(java.awt.geom.PathIterator pathIt)
-
-