Class ShapeWriter
- java.lang.Object
-
- org.locationtech.jts.awt.ShapeWriter
-
public class ShapeWriter extends java.lang.Object
WritesGeometry
s into Java2DShape
objects of the appropriate type. This supports rendering geometries using Java2D. The ShapeWriter allows supplying aPointTransformation
class, to transform coordinates from model space into view space. This is useful if a client is providing its own transformation logic, rather than relying on Java2D AffineTransforms.The writer supports removing duplicate consecutive points (via the
setRemoveDuplicatePoints(boolean)
method) as well as true decimation (via thesetDecimation(double)
method. Enabling one of these strategies can substantially improve rendering speed for large geometries. It is only necessary to enable one strategy. Using decimation is preferred, but this requires determining a distance below which input geometry vertices can be considered unique (which may not always be feasible). If neither strategy is enabled, all vertices of the input Geometry will be represented in the output Shape.
-
-
Field Summary
Fields Modifier and Type Field Description private double
decimationDistance
static PointShapeFactory
DEFAULT_POINT_FACTORY
The point shape factory used by default.static PointTransformation
DEFAULT_POINT_TRANSFORMATION
The point transformation used by default.private boolean
doRemoveDuplicatePoints
If true, decimation will be used to reduce the number of vertices by removing consecutive duplicates.private PointShapeFactory
pointFactory
private PointTransformation
pointTransformer
private java.awt.geom.Point2D
transPoint
Cache a Point2D object to use to transfer coordinates into shape
-
Constructor Summary
Constructors Constructor Description ShapeWriter()
Creates a new ShapeWriter with the default (identity) point transformation.ShapeWriter(PointTransformation pointTransformer)
Creates a new ShapeWriter with a specified point transformation and the default point shape factory.ShapeWriter(PointTransformation pointTransformer, PointShapeFactory pointFactory)
Creates a new ShapeWriter with a specified point transformation and point shape factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
appendRing(PolygonShape poly, Coordinate[] coords)
void
setDecimation(double decimationDistance)
Sets the decimation distance used to determine whether vertices of the input geometry are considered to be duplicate and thus removed.void
setRemoveDuplicatePoints(boolean doRemoveDuplicatePoints)
Sets whether duplicate consecutive points should be eliminated.java.awt.Shape
toShape(Geometry geometry)
Creates aShape
representing aGeometry
, according to the specified PointTransformation and PointShapeFactory (if relevant).private java.awt.Shape
toShape(GeometryCollection gc)
private java.awt.geom.GeneralPath
toShape(LineString lineString)
private java.awt.geom.GeneralPath
toShape(MultiLineString mls)
private java.awt.Shape
toShape(Point point)
private java.awt.Shape
toShape(Polygon p)
private java.awt.geom.Point2D
transformPoint(Coordinate model)
private java.awt.geom.Point2D
transformPoint(Coordinate model, java.awt.geom.Point2D view)
-
-
-
Field Detail
-
DEFAULT_POINT_TRANSFORMATION
public static final PointTransformation DEFAULT_POINT_TRANSFORMATION
The point transformation used by default.
-
DEFAULT_POINT_FACTORY
public static final PointShapeFactory DEFAULT_POINT_FACTORY
The point shape factory used by default.
-
pointTransformer
private PointTransformation pointTransformer
-
pointFactory
private PointShapeFactory pointFactory
-
transPoint
private java.awt.geom.Point2D transPoint
Cache a Point2D object to use to transfer coordinates into shape
-
doRemoveDuplicatePoints
private boolean doRemoveDuplicatePoints
If true, decimation will be used to reduce the number of vertices by removing consecutive duplicates.
-
decimationDistance
private double decimationDistance
-
-
Constructor Detail
-
ShapeWriter
public ShapeWriter(PointTransformation pointTransformer, PointShapeFactory pointFactory)
Creates a new ShapeWriter with a specified point transformation and point shape factory.- Parameters:
pointTransformer
- a transformation from model to view space to usepointFactory
- the PointShapeFactory to use
-
ShapeWriter
public ShapeWriter(PointTransformation pointTransformer)
Creates a new ShapeWriter with a specified point transformation and the default point shape factory.- Parameters:
pointTransformer
- a transformation from model to view space to use
-
ShapeWriter
public ShapeWriter()
Creates a new ShapeWriter with the default (identity) point transformation.
-
-
Method Detail
-
setRemoveDuplicatePoints
public void setRemoveDuplicatePoints(boolean doRemoveDuplicatePoints)
Sets whether duplicate consecutive points should be eliminated. This can reduce the size of the generated Shapes and improve rendering speed, especially in situations where a transform reduces the extent of the geometry.The default is false.
- Parameters:
doDecimation
- whether decimation is to be used
-
setDecimation
public void setDecimation(double decimationDistance)
Sets the decimation distance used to determine whether vertices of the input geometry are considered to be duplicate and thus removed. The distance is axis distance, not Euclidean distance. The distance is specified in the input geometry coordinate system (NOT the transformed output coordinate system).When rendering to a screen image, a suitably small distance should be used to avoid obvious rendering defects. A distance equivalent to the equivalent of 1.5 pixels or less is recommended (and perhaps even smaller to avoid any chance of visible artifacts).
The default distance is 0.0, which disables decimation.
- Parameters:
decimationDistance
- the distance below which vertices are considered to be duplicates
-
toShape
public java.awt.Shape toShape(Geometry geometry)
Creates aShape
representing aGeometry
, according to the specified PointTransformation and PointShapeFactory (if relevant).Note that Shapes do not preserve information about which elements in heterogeneous collections are 1D and which are 2D. For example, a GeometryCollection containing a ring and a disk will render as two disks if Graphics.fill is used, or as two rings if Graphics.draw is used. To avoid this issue use separate shapes for the components.
- Parameters:
geometry
- the geometry to convert- Returns:
- a Shape representing the geometry
-
toShape
private java.awt.Shape toShape(Polygon p)
-
appendRing
private void appendRing(PolygonShape poly, Coordinate[] coords)
-
toShape
private java.awt.Shape toShape(GeometryCollection gc)
-
toShape
private java.awt.geom.GeneralPath toShape(MultiLineString mls)
-
toShape
private java.awt.geom.GeneralPath toShape(LineString lineString)
-
toShape
private java.awt.Shape toShape(Point point)
-
transformPoint
private java.awt.geom.Point2D transformPoint(Coordinate model)
-
transformPoint
private java.awt.geom.Point2D transformPoint(Coordinate model, java.awt.geom.Point2D view)
-
-