Package org.geotools.geometry.jts
Class GeometryBuilder
- Object
-
- GeometryBuilder
-
public class GeometryBuilder extends Object
A builder forGeometry
objects. Primarily intended to support fluent programming in test code.Features include:
- Both 2D and 3D coordinate dimensions are supported (assuming the provided
CoordinateSequenceFactory
supports them) - Sequences of ordinate values can be supplied in a number of ways
- Rings do not need to be explicitly closed; a closing point will be supplied if needed
- Empty geometries of all types can be created
- Composite geometries are validated to ensure they have a consistent GeometryFactory and
coordinate sequence dimension
Examples of intended usage are:
GeometryBuilder gb = new GeometryBuilder(geomFact); LineString line = gb.linestring(1,2, 3,4); Polygon poly = gb.polygon(0,0, 0,1, 1,1, 1,0); Polygon box = gb.box(0,0, 1,1); Polygon hexagon = gb.circle(0,0, 1,1, 6); Polygon polyhole = gb.polygon(gb.linearring(0,0, 0,10, 10,10, 10,0), gb.linearring(1,1, 1,9, 9,9, 9,1))
- Author:
- Martin Davis - OpenGeo
- Both 2D and 3D coordinate dimensions are supported (assuming the provided
-
-
Constructor Summary
Constructors Constructor Description GeometryBuilder()
Create a new instance using the defaultGeometryFactory
.GeometryBuilder(GeometryFactory geomFact)
Creates a new instance using a provided GeometryFactory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Polygon
box(double x1, double y1, double x2, double y2)
Creates a rectangular 2D Polygon from X and Y bounds.Polygon
boxZ(double x1, double y1, double x2, double y2, double z)
Creates a rectangular 3D Polygon from X and Y bounds.Polygon
circle(double x, double y, double radius, int nsides)
Creates a circular Polygon with a given center, radius and number of sides.Polygon
ellipse(double x1, double y1, double x2, double y2, int nsides)
Creates an elliptical Polygon from a bounding box with a given number of sides.GeometryCollection
geometryCollection(Geometry... geoms)
Creates a GeometryCollection from a set of GeometrysLinearRing
linearRing()
Creates an empty 2D LinearRingLinearRing
linearRing(double... ord)
Creates a 2D LinearRing.LinearRing
linearRingZ()
Creates an empty 3D LinearRingLinearRing
linearRingZ(double... ord)
Creates a 3D LinearRing.LineString
lineString()
Creates an empty 2D LineStringLineString
lineString(double... ord)
Creates a 2D LineString.LineString
lineStringZ()
Creates an empty 3D LineStringLineString
lineStringZ(double... ord)
Creates a 3D LineString.MultiLineString
multiLineString(LineString... lines)
Creates a MultiLineString from a set of LineStringsMultiPoint
multiPoint(double x1, double y1, double x2, double y2)
Creates a MultiPoint with 2 2D Points.MultiPoint
multiPointZ(double x1, double y1, double z1, double x2, double y2, double z2)
Creates a MultiPoint with 2 3D Points.MultiPolygon
multiPolygon(Polygon... polys)
Creates a MultiPolygon from a set of Polygons.Point
point()
Creates an empty PointPoint
point(double x)
Creates a 1D Point.Point
point(double x, double y)
Creates a 2D Point.Point
pointZ()
Creates an empty Point with coordinate dimension = 3.Point
pointZ(double x, double y, double z)
Creates a 3D Point.Polygon
polygon()
Creates an empty 2D Polygon.Polygon
polygon(double... ord)
Creates a Polygon from a list of XY coordinates.Polygon
polygon(LinearRing shell)
Creates a Polygon from an exterior ring.Polygon
polygon(LinearRing shell, LinearRing hole)
Creates a Polygon with a hole from an exterior ring and an interior ring.Polygon
polygon(Polygon shell, Polygon hole)
Creates a Polygon with a hole from an exterior ring and an interior ring supplied by the rings of Polygons.Polygon
polygonZ()
Creates an empty 3D Polygon.Polygon
polygonZ(double... ord)
Creates a Polygon from a list of XYZ coordinates.
-
-
-
Constructor Detail
-
GeometryBuilder
public GeometryBuilder()
Create a new instance using the defaultGeometryFactory
.
-
GeometryBuilder
public GeometryBuilder(GeometryFactory geomFact)
Creates a new instance using a provided GeometryFactory.- Parameters:
geomFact
- the factory to use
-
-
Method Detail
-
point
public Point point()
Creates an empty Point- Returns:
- an empty Point
-
pointZ
public Point pointZ()
Creates an empty Point with coordinate dimension = 3.- Returns:
- an empty Point
-
point
public Point point(double x)
Creates a 1D Point.- Parameters:
x
- the X ordinate- Returns:
- a Point
-
point
public Point point(double x, double y)
Creates a 2D Point.- Parameters:
x
- the X ordinatey
- the Y ordinate- Returns:
- a Point
-
pointZ
public Point pointZ(double x, double y, double z)
Creates a 3D Point.- Parameters:
x
- the X ordinatey
- the Y ordinatez
- the Z ordinate- Returns:
- a Point
-
lineString
public LineString lineString()
Creates an empty 2D LineString- Returns:
- an empty LineString
-
lineStringZ
public LineString lineStringZ()
Creates an empty 3D LineString- Returns:
- an empty LineString
-
lineString
public LineString lineString(double... ord)
Creates a 2D LineString.- Parameters:
ord
- the XY ordinates- Returns:
- a LineString
-
lineStringZ
public LineString lineStringZ(double... ord)
Creates a 3D LineString.- Parameters:
ord
- the XYZ ordinates- Returns:
- a LineString
-
linearRing
public LinearRing linearRing()
Creates an empty 2D LinearRing- Returns:
- an empty LinearRing
-
linearRingZ
public LinearRing linearRingZ()
Creates an empty 3D LinearRing- Returns:
- an empty LinearRing
-
linearRing
public LinearRing linearRing(double... ord)
Creates a 2D LinearRing. If the supplied coordinate list is not closed, a closing coordinate is added.- Returns:
- a LinearRing
-
linearRingZ
public LinearRing linearRingZ(double... ord)
Creates a 3D LinearRing. If the supplied coordinate list is not closed, a closing coordinate is added.- Parameters:
ord
- the XYZ ordinates- Returns:
- a LinearRing
-
polygon
public Polygon polygon()
Creates an empty 2D Polygon.- Returns:
- an empty Polygon
-
polygonZ
public Polygon polygonZ()
Creates an empty 3D Polygon.- Returns:
- an empty Polygon
-
polygon
public Polygon polygon(double... ord)
Creates a Polygon from a list of XY coordinates.- Parameters:
ord
- a list of XY ordinates- Returns:
- a Polygon
-
polygonZ
public Polygon polygonZ(double... ord)
Creates a Polygon from a list of XYZ coordinates.- Parameters:
ord
- a list of XYZ ordinates- Returns:
- a Polygon
-
polygon
public Polygon polygon(LinearRing shell)
Creates a Polygon from an exterior ring. The coordinate dimension of the Polygon is the dimension of the LinearRing.- Parameters:
shell
- the exterior ring- Returns:
- a Polygon
-
polygon
public Polygon polygon(LinearRing shell, LinearRing hole)
Creates a Polygon with a hole from an exterior ring and an interior ring.- Parameters:
shell
- the exterior ringhole
- the interior ring- Returns:
- a Polygon with a hole
-
polygon
public Polygon polygon(Polygon shell, Polygon hole)
Creates a Polygon with a hole from an exterior ring and an interior ring supplied by the rings of Polygons.- Parameters:
shell
- the exterior ringhole
- the interior ring- Returns:
- a Polygon with a hole
-
box
public Polygon box(double x1, double y1, double x2, double y2)
Creates a rectangular 2D Polygon from X and Y bounds.- Parameters:
x1
- the lower X boundy1
- the lower Y boundx2
- the upper X boundy2
- the upper Y bound- Returns:
- a 2D Polygon
-
boxZ
public Polygon boxZ(double x1, double y1, double x2, double y2, double z)
Creates a rectangular 3D Polygon from X and Y bounds.- Parameters:
x1
- the lower X boundy1
- the lower Y boundx2
- the upper X boundy2
- the upper Y boundz
- the Z value for all coordinates- Returns:
- a 3D Polygon
-
ellipse
public Polygon ellipse(double x1, double y1, double x2, double y2, int nsides)
Creates an elliptical Polygon from a bounding box with a given number of sides.- Returns:
- a 2D Polygon
-
circle
public Polygon circle(double x, double y, double radius, int nsides)
Creates a circular Polygon with a given center, radius and number of sides.- Parameters:
x
- the center X ordinatey
- the center Y ordinateradius
- the radiusnsides
- the number of sides- Returns:
- a 2D Polygon
-
multiPoint
public MultiPoint multiPoint(double x1, double y1, double x2, double y2)
Creates a MultiPoint with 2 2D Points.- Parameters:
x1
- the X ordinate of the first pointy1
- the Y ordinate of the first pointx2
- the X ordinate of the second pointy2
- the Y ordinate of the second point- Returns:
- A MultiPoint
-
multiPointZ
public MultiPoint multiPointZ(double x1, double y1, double z1, double x2, double y2, double z2)
Creates a MultiPoint with 2 3D Points.- Parameters:
x1
- the X ordinate of the first pointy1
- the Y ordinate of the first pointz1
- the Z ordinate of the first pointx2
- the X ordinate of the second pointy2
- the Y ordinate of the second pointz2
- the Z ordinate of the second point- Returns:
- A 3D MultiPoint
-
multiLineString
public MultiLineString multiLineString(LineString... lines)
Creates a MultiLineString from a set of LineStrings- Parameters:
lines
- the component LineStrings- Returns:
- a MultiLineString
-
multiPolygon
public MultiPolygon multiPolygon(Polygon... polys)
Creates a MultiPolygon from a set of Polygons.- Parameters:
polys
- the component polygons- Returns:
- A MultiPolygon
-
geometryCollection
public GeometryCollection geometryCollection(Geometry... geoms)
Creates a GeometryCollection from a set of Geometrys- Parameters:
geoms
- the component Geometrys- Returns:
- a GeometryCollection
-
-