Package org.locationtech.jts.util
Class GeometricShapeFactory
- java.lang.Object
-
- org.locationtech.jts.util.GeometricShapeFactory
-
public class GeometricShapeFactory extends Object
Computes various kinds of common geometric shapes. Provides various ways of specifying the location and extent and rotations of the generated shapes, as well as number of line segments used to form them.Example of usage:
GeometricShapeFactory gsf = new GeometricShapeFactory(); gsf.setSize(100); gsf.setNumPoints(100); gsf.setBase(new Coordinate(100, 100)); gsf.setRotation(0.5); Polygon rect = gsf.createRectangle();
- Version:
- 1.7
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classGeometricShapeFactory.Dimensions
-
Field Summary
Fields Modifier and Type Field Description protected GeometricShapeFactory.Dimensionsdimprotected GeometryFactorygeomFactprotected intnPtsprotected PrecisionModelprecModelprotected doublerotationAngleDefault is no rotation.
-
Constructor Summary
Constructors Constructor Description GeometricShapeFactory()Create a shape factory which will create shapes using the defaultGeometryFactory.GeometricShapeFactory(GeometryFactory geomFact)Create a shape factory which will create shapes using the givenGeometryFactory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Coordinatecoord(double x, double y)protected CoordinatecoordTrans(double x, double y, Coordinate trans)LineStringcreateArc(double startAng, double angExtent)Creates an elliptical arc, as aLineString.PolygoncreateArcPolygon(double startAng, double angExtent)Creates an elliptical arc polygon.PolygoncreateCircle()Creates a circular or ellipticalPolygon.PolygoncreateEllipse()Creates an ellipticalPolygon.PolygoncreateRectangle()Creates a rectangularPolygon.PolygoncreateSquircle()Creates a squircularPolygon.PolygoncreateSupercircle(double power)Creates a supercircularPolygonof a given positive power.protected Geometryrotate(Geometry geom)voidsetBase(Coordinate base)Sets the location of the shape by specifying the base coordinate (which in most cases is the lower left point of the envelope containing the shape).voidsetCentre(Coordinate centre)Sets the location of the shape by specifying the centre of the shape's bounding boxvoidsetEnvelope(Envelope env)voidsetHeight(double height)Sets the height of the shape.voidsetNumPoints(int nPts)Sets the total number of points in the createdGeometry.voidsetRotation(double radians)Sets the rotation angle to use for the shape.voidsetSize(double size)Sets the size of the extent of the shape in both x and y directions.voidsetWidth(double width)Sets the width of the shape.
-
-
-
Field Detail
-
geomFact
protected GeometryFactory geomFact
-
precModel
protected PrecisionModel precModel
-
dim
protected GeometricShapeFactory.Dimensions dim
-
nPts
protected int nPts
-
rotationAngle
protected double rotationAngle
Default is no rotation.
-
-
Constructor Detail
-
GeometricShapeFactory
public GeometricShapeFactory()
Create a shape factory which will create shapes using the defaultGeometryFactory.
-
GeometricShapeFactory
public GeometricShapeFactory(GeometryFactory geomFact)
Create a shape factory which will create shapes using the givenGeometryFactory.- Parameters:
geomFact- the factory to use
-
-
Method Detail
-
setEnvelope
public void setEnvelope(Envelope env)
-
setBase
public void setBase(Coordinate base)
Sets the location of the shape by specifying the base coordinate (which in most cases is the lower left point of the envelope containing the shape).- Parameters:
base- the base coordinate of the shape
-
setCentre
public void setCentre(Coordinate centre)
Sets the location of the shape by specifying the centre of the shape's bounding box- Parameters:
centre- the centre coordinate of the shape
-
setNumPoints
public void setNumPoints(int nPts)
Sets the total number of points in the createdGeometry. The created geometry will have no more than this number of points, unless more are needed to create a valid geometry.
-
setSize
public void setSize(double size)
Sets the size of the extent of the shape in both x and y directions.- Parameters:
size- the size of the shape's extent
-
setWidth
public void setWidth(double width)
Sets the width of the shape.- Parameters:
width- the width of the shape
-
setHeight
public void setHeight(double height)
Sets the height of the shape.- Parameters:
height- the height of the shape
-
setRotation
public void setRotation(double radians)
Sets the rotation angle to use for the shape. The rotation is applied relative to the centre of the shape.- Parameters:
radians- the rotation angle in radians.
-
createRectangle
public Polygon createRectangle()
Creates a rectangularPolygon.- Returns:
- a rectangular Polygon
-
createCircle
public Polygon createCircle()
Creates a circular or ellipticalPolygon.- Returns:
- a circle or ellipse
-
createEllipse
public Polygon createEllipse()
Creates an ellipticalPolygon. If the supplied envelope is square the result will be a circle.- Returns:
- an ellipse or circle
-
createSupercircle
public Polygon createSupercircle(double power)
Creates a supercircularPolygonof a given positive power.- Returns:
- a supercircle
-
createArc
public LineString createArc(double startAng, double angExtent)
Creates an elliptical arc, as aLineString. The arc is always created in a counter-clockwise direction. This can easily be reversed if required by using {#link LineString.reverse()}- Parameters:
startAng- start angle in radiansangExtent- size of angle in radians- Returns:
- an elliptical arc
-
createArcPolygon
public Polygon createArcPolygon(double startAng, double angExtent)
Creates an elliptical arc polygon. The polygon is formed from the specified arc of an ellipse and the two radii connecting the endpoints to the centre of the ellipse.- Parameters:
startAng- start angle in radiansangExtent- size of angle in radians- Returns:
- an elliptical arc polygon
-
coord
protected Coordinate coord(double x, double y)
-
coordTrans
protected Coordinate coordTrans(double x, double y, Coordinate trans)
-
-