Class PolygonBuilder
- java.lang.Object
-
- org.elasticsearch.common.geo.builders.ShapeBuilder<org.locationtech.spatial4j.shape.jts.JtsGeometry,PolygonBuilder>
-
- org.elasticsearch.common.geo.builders.PolygonBuilder
-
- All Implemented Interfaces:
NamedWriteable
,Writeable
,ToXContent
,ToXContentObject
public class PolygonBuilder extends ShapeBuilder<org.locationtech.spatial4j.shape.jts.JtsGeometry,PolygonBuilder>
ThePolygonBuilder
implements the groundwork to create polygons. This contains Methods to wrap polygons at the dateline and building shapes from the data held by the builder.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.elasticsearch.common.geo.builders.ShapeBuilder
ShapeBuilder.Edge, ShapeBuilder.Orientation
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static GeoShapeType
TYPE
-
Fields inherited from class org.elasticsearch.common.geo.builders.ShapeBuilder
AUTO_INDEX_JTS_GEOMETRY, AUTO_VALIDATE_JTS_GEOMETRY, coordinates, DATELINE, FACTORY, INTERSECTION_ORDER, LOGGER, MULTI_POLYGON_MAY_OVERLAP, SPATIAL_CONTEXT, wrapdateline, ZERO_ZERO
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description PolygonBuilder(CoordinatesBuilder coordinates)
PolygonBuilder(CoordinatesBuilder coordinates, ShapeBuilder.Orientation orientation)
PolygonBuilder(LineStringBuilder lineString, ShapeBuilder.Orientation orientation)
PolygonBuilder(LineStringBuilder lineString, ShapeBuilder.Orientation orientation, boolean coerce)
PolygonBuilder(StreamInput in)
Read from a stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.locationtech.spatial4j.shape.jts.JtsGeometry
build()
Create a new Shape from this builder.org.locationtech.jts.geom.Geometry
buildGeometry(org.locationtech.jts.geom.GeometryFactory factory, boolean fixDateline)
PolygonBuilder
close()
Close the shell of the polygonprotected java.lang.StringBuilder
contentToWKT()
org.locationtech.jts.geom.Coordinate[][][]
coordinates()
The coordinates setup by the builder will be assembled to a polygon.protected XContentBuilder
coordinatesArray(XContentBuilder builder, ToXContent.Params params)
boolean
equals(java.lang.Object obj)
int
hashCode()
PolygonBuilder
hole(LineStringBuilder hole)
Add a new hole to the polygonPolygonBuilder
hole(LineStringBuilder hole, boolean coerce)
Add a new hole to the polygonjava.util.List<LineStringBuilder>
holes()
protected static org.locationtech.jts.geom.LinearRing
linearRing(org.locationtech.jts.geom.GeometryFactory factory, java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)
protected static org.locationtech.jts.geom.MultiPolygon
multipolygon(org.locationtech.jts.geom.GeometryFactory factory, org.locationtech.jts.geom.Coordinate[][][] polygons)
Create a Multipolygon from a set of coordinates.int
numDimensions()
tracks number of dimensions for this shapeShapeBuilder.Orientation
orientation()
protected static org.locationtech.jts.geom.Polygon
polygon(org.locationtech.jts.geom.GeometryFactory factory, org.locationtech.jts.geom.Coordinate[][] polygon)
LineStringBuilder
shell()
org.locationtech.jts.geom.Polygon
toPolygon()
protected org.locationtech.jts.geom.Polygon
toPolygon(org.locationtech.jts.geom.GeometryFactory factory)
XContentBuilder
toXContent(XContentBuilder builder, ToXContent.Params params)
GeoShapeType
type()
get the shapes typeprotected void
validateHole(LineStringBuilder shell, LineStringBuilder hole)
Validates only 1 vertex is tangential (shared) between the interior and exterior of a polygonvoid
writeTo(StreamOutput out)
Write this into the StreamOutput.-
Methods inherited from class org.elasticsearch.common.geo.builders.ShapeBuilder
coordinate, coordinate, coordinateListToWKT, coordinates, coordinates, coordinates, coordinatesToXcontent, debugEnabled, getWriteableName, intersection, intersections, jtsGeometry, parse, readFromStream, shift, toString, toWKT, toXContent, writeCoordinateTo
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
TYPE
public static final GeoShapeType TYPE
-
-
Constructor Detail
-
PolygonBuilder
public PolygonBuilder(LineStringBuilder lineString, ShapeBuilder.Orientation orientation, boolean coerce)
-
PolygonBuilder
public PolygonBuilder(LineStringBuilder lineString, ShapeBuilder.Orientation orientation)
-
PolygonBuilder
public PolygonBuilder(CoordinatesBuilder coordinates, ShapeBuilder.Orientation orientation)
-
PolygonBuilder
public PolygonBuilder(CoordinatesBuilder coordinates)
-
PolygonBuilder
public PolygonBuilder(StreamInput in) throws java.io.IOException
Read from a stream.- Throws:
java.io.IOException
-
-
Method Detail
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:Writeable
Write this into the StreamOutput.- Specified by:
writeTo
in interfaceWriteable
- Overrides:
writeTo
in classShapeBuilder<org.locationtech.spatial4j.shape.jts.JtsGeometry,PolygonBuilder>
- Throws:
java.io.IOException
-
orientation
public ShapeBuilder.Orientation orientation()
-
hole
public PolygonBuilder hole(LineStringBuilder hole)
Add a new hole to the polygon- Parameters:
hole
- linear ring defining the hole- Returns:
- this
-
hole
public PolygonBuilder hole(LineStringBuilder hole, boolean coerce)
Add a new hole to the polygon- Parameters:
hole
- linear ring defining the holecoerce
- if set to true, it will try to close the hole by adding starting point as end point- Returns:
- this
-
holes
public java.util.List<LineStringBuilder> holes()
- Returns:
- the list of holes defined for this polygon
-
shell
public LineStringBuilder shell()
- Returns:
- the list of points of the shell for this polygon
-
close
public PolygonBuilder close()
Close the shell of the polygon
-
validateHole
protected void validateHole(LineStringBuilder shell, LineStringBuilder hole)
Validates only 1 vertex is tangential (shared) between the interior and exterior of a polygon
-
coordinates
public org.locationtech.jts.geom.Coordinate[][][] coordinates()
The coordinates setup by the builder will be assembled to a polygon. The result will consist of a set of polygons. Each of these components holds a list of linestrings defining the polygon: the first set of coordinates will be used as the shell of the polygon. The others are defined to holes within the polygon. This Method also wraps the polygons at the dateline. In order to this fact the result may contains more polygons and less holes than defined in the builder it self.- Returns:
- coordinates of the polygon
-
build
public org.locationtech.spatial4j.shape.jts.JtsGeometry build()
Description copied from class:ShapeBuilder
Create a new Shape from this builder. Since calling this method could change the defined shape. (by inserting new coordinates or change the position of points) the builder looses its validity. So this method should only be called once on a builder- Specified by:
build
in classShapeBuilder<org.locationtech.spatial4j.shape.jts.JtsGeometry,PolygonBuilder>
- Returns:
- new
Shape
defined by the builder
-
coordinatesArray
protected XContentBuilder coordinatesArray(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Throws:
java.io.IOException
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Throws:
java.io.IOException
-
buildGeometry
public org.locationtech.jts.geom.Geometry buildGeometry(org.locationtech.jts.geom.GeometryFactory factory, boolean fixDateline)
-
toPolygon
public org.locationtech.jts.geom.Polygon toPolygon()
-
toPolygon
protected org.locationtech.jts.geom.Polygon toPolygon(org.locationtech.jts.geom.GeometryFactory factory)
-
linearRing
protected static org.locationtech.jts.geom.LinearRing linearRing(org.locationtech.jts.geom.GeometryFactory factory, java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)
-
type
public GeoShapeType type()
Description copied from class:ShapeBuilder
get the shapes type- Specified by:
type
in classShapeBuilder<org.locationtech.spatial4j.shape.jts.JtsGeometry,PolygonBuilder>
- Returns:
- type of the shape
-
numDimensions
public int numDimensions()
Description copied from class:ShapeBuilder
tracks number of dimensions for this shape- Specified by:
numDimensions
in classShapeBuilder<org.locationtech.spatial4j.shape.jts.JtsGeometry,PolygonBuilder>
-
polygon
protected static org.locationtech.jts.geom.Polygon polygon(org.locationtech.jts.geom.GeometryFactory factory, org.locationtech.jts.geom.Coordinate[][] polygon)
-
multipolygon
protected static org.locationtech.jts.geom.MultiPolygon multipolygon(org.locationtech.jts.geom.GeometryFactory factory, org.locationtech.jts.geom.Coordinate[][][] polygons)
Create a Multipolygon from a set of coordinates. Each primary array contains a polygon which in turn contains an array of linestrings. These line Strings are represented as an array of coordinates. The first linestring will be the shell of the polygon the others define holes within the polygon.- Parameters:
factory
-GeometryFactory
to usepolygons
- definition of polygons- Returns:
- a new Multipolygon
-
contentToWKT
protected java.lang.StringBuilder contentToWKT()
- Overrides:
contentToWKT
in classShapeBuilder<org.locationtech.spatial4j.shape.jts.JtsGeometry,PolygonBuilder>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classShapeBuilder<org.locationtech.spatial4j.shape.jts.JtsGeometry,PolygonBuilder>
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classShapeBuilder<org.locationtech.spatial4j.shape.jts.JtsGeometry,PolygonBuilder>
-
-