Class ShapeBuilder<T extends org.locationtech.spatial4j.shape.Shape,E extends ShapeBuilder<T,E>>
- java.lang.Object
-
- org.elasticsearch.common.geo.builders.ShapeBuilder<T,E>
-
- All Implemented Interfaces:
NamedWriteable
,Writeable
,ToXContent
,ToXContentObject
- Direct Known Subclasses:
CircleBuilder
,EnvelopeBuilder
,GeometryCollectionBuilder
,LineStringBuilder
,MultiLineStringBuilder
,MultiPointBuilder
,MultiPolygonBuilder
,PointBuilder
,PolygonBuilder
public abstract class ShapeBuilder<T extends org.locationtech.spatial4j.shape.Shape,E extends ShapeBuilder<T,E>> extends java.lang.Object implements NamedWriteable, ToXContentObject
Basic class for building GeoJSON shapes like Polygons, Linestrings, etc
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ShapeBuilder.Edge
This helper class implements a linked list forCoordinate
.static class
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 protected static boolean
AUTO_INDEX_JTS_GEOMETRY
protected static boolean
AUTO_VALIDATE_JTS_GEOMETRY
protected java.util.List<org.locationtech.jts.geom.Coordinate>
coordinates
static double
DATELINE
static org.locationtech.jts.geom.GeometryFactory
FACTORY
protected static org.elasticsearch.common.geo.builders.ShapeBuilder.IntersectionOrder
INTERSECTION_ORDER
protected static org.apache.logging.log4j.Logger
LOGGER
protected static boolean
MULTI_POLYGON_MAY_OVERLAP
It's possible that some geometries in a MULTI* shape might overlap.static org.locationtech.spatial4j.context.jts.JtsSpatialContext
SPATIAL_CONTEXT
protected boolean
wrapdateline
We're expecting some geometries might cross the dateline.static org.locationtech.jts.geom.Coordinate
ZERO_ZERO
coordinate at [0.0, 0.0]-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ShapeBuilder()
default ctorprotected
ShapeBuilder(java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)
ctor from list of coordinatesprotected
ShapeBuilder(StreamInput in)
ctor from serialized stream input
-
Method Summary
Modifier and Type Method Description abstract java.lang.Object
buildLucene()
build lucene geometry.abstract T
buildS4J()
Create a new Shape from this builder.protected java.lang.StringBuilder
contentToWKT()
E
coordinate(double longitude, double latitude)
Add a new coordinate to the collectionE
coordinate(org.locationtech.jts.geom.Coordinate coordinate)
Add a new coordinate to the collectionprotected static java.lang.StringBuilder
coordinateListToWKT(java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)
protected org.locationtech.jts.geom.Coordinate[]
coordinates(boolean closed)
Copy all coordinate to a new ArrayE
coordinates(java.util.Collection<? extends org.locationtech.jts.geom.Coordinate> coordinates)
Add a collection of coordinates to the collectionE
coordinates(org.locationtech.jts.geom.Coordinate... coordinates)
Add a array of coordinates to the collectionprotected XContentBuilder
coordinatesToXcontent(XContentBuilder builder, boolean closed)
builds an array of coordinates to aXContentBuilder
protected static boolean
debugEnabled()
boolean
equals(java.lang.Object o)
java.lang.String
getWriteableName()
Returns the name of the writeable objectint
hashCode()
protected static double
intersection(org.locationtech.jts.geom.Coordinate p1, org.locationtech.jts.geom.Coordinate p2, double dateline)
Calculate the intersection of a line segment and a vertical dateline.protected static int
intersections(double dateline, ShapeBuilder.Edge[] edges)
Calculate all intersections of line segments and a vertical line.protected org.locationtech.spatial4j.shape.jts.JtsGeometry
jtsGeometry(org.locationtech.jts.geom.Geometry geom)
abstract int
numDimensions()
tracks number of dimensions for this shapestatic ShapeBuilder
parse(XContentParser parser)
Deprecated.this method will be removed in a future version; use ShapeParser.parse insteadprotected static org.locationtech.jts.geom.Coordinate
readFromStream(StreamInput in)
protected static org.locationtech.jts.geom.Coordinate
shift(org.locationtech.jts.geom.Coordinate coordinate, double dateline)
java.lang.String
toString()
java.lang.String
toWKT()
protected static XContentBuilder
toXContent(XContentBuilder builder, org.locationtech.jts.geom.Coordinate coordinate)
abstract GeoShapeType
type()
get the shapes typeprotected static void
writeCoordinateTo(org.locationtech.jts.geom.Coordinate coordinate, StreamOutput out)
void
writeTo(StreamOutput out)
Write this into the StreamOutput.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContent
toXContent
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
LOGGER
protected static final org.apache.logging.log4j.Logger LOGGER
-
coordinates
protected final java.util.List<org.locationtech.jts.geom.Coordinate> coordinates
-
DATELINE
public static final double DATELINE
- See Also:
- Constant Field Values
-
ZERO_ZERO
public static final org.locationtech.jts.geom.Coordinate ZERO_ZERO
coordinate at [0.0, 0.0]
-
SPATIAL_CONTEXT
public static final org.locationtech.spatial4j.context.jts.JtsSpatialContext SPATIAL_CONTEXT
-
FACTORY
public static final org.locationtech.jts.geom.GeometryFactory FACTORY
-
wrapdateline
protected final boolean wrapdateline
We're expecting some geometries might cross the dateline.
-
MULTI_POLYGON_MAY_OVERLAP
protected static final boolean MULTI_POLYGON_MAY_OVERLAP
It's possible that some geometries in a MULTI* shape might overlap. With the possible exception of GeometryCollection, this normally isn't allowed.- See Also:
- Constant Field Values
-
AUTO_VALIDATE_JTS_GEOMETRY
protected static final boolean AUTO_VALIDATE_JTS_GEOMETRY
- See Also:
JtsGeometry.validate()
, Constant Field Values
-
AUTO_INDEX_JTS_GEOMETRY
protected static final boolean AUTO_INDEX_JTS_GEOMETRY
- See Also:
JtsGeometry.index()
, Constant Field Values
-
INTERSECTION_ORDER
protected static final org.elasticsearch.common.geo.builders.ShapeBuilder.IntersectionOrder INTERSECTION_ORDER
-
-
Constructor Detail
-
ShapeBuilder
protected ShapeBuilder()
default ctor
-
ShapeBuilder
protected ShapeBuilder(java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)
ctor from list of coordinates
-
ShapeBuilder
protected ShapeBuilder(StreamInput in) throws java.io.IOException
ctor from serialized stream input- Throws:
java.io.IOException
-
-
Method Detail
-
readFromStream
protected static org.locationtech.jts.geom.Coordinate readFromStream(StreamInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:Writeable
Write this into the StreamOutput.
-
writeCoordinateTo
protected static void writeCoordinateTo(org.locationtech.jts.geom.Coordinate coordinate, StreamOutput out) throws java.io.IOException
- Throws:
java.io.IOException
-
coordinate
public E coordinate(double longitude, double latitude)
Add a new coordinate to the collection- Parameters:
longitude
- longitude of the coordinatelatitude
- latitude of the coordinate- Returns:
- this
-
coordinate
public E coordinate(org.locationtech.jts.geom.Coordinate coordinate)
Add a new coordinate to the collection- Parameters:
coordinate
- coordinate of the point- Returns:
- this
-
coordinates
public E coordinates(org.locationtech.jts.geom.Coordinate... coordinates)
Add a array of coordinates to the collection- Parameters:
coordinates
- array ofCoordinate
s to add- Returns:
- this
-
coordinates
public E coordinates(java.util.Collection<? extends org.locationtech.jts.geom.Coordinate> coordinates)
Add a collection of coordinates to the collection- Parameters:
coordinates
- array ofCoordinate
s to add- Returns:
- this
-
coordinates
protected org.locationtech.jts.geom.Coordinate[] coordinates(boolean closed)
Copy all coordinate to a new Array- Parameters:
closed
- if set to true the first point of the array is repeated as last element- Returns:
- Array of coordinates
-
jtsGeometry
protected org.locationtech.spatial4j.shape.jts.JtsGeometry jtsGeometry(org.locationtech.jts.geom.Geometry geom)
-
buildS4J
public abstract T buildS4J()
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- Returns:
- new
Shape
defined by the builder
-
buildLucene
public abstract java.lang.Object buildLucene()
build lucene geometry.- Returns:
- GeoPoint, double[][], Line, Line[], Polygon, Polygon[], Rectangle, Object[]
-
shift
protected static org.locationtech.jts.geom.Coordinate shift(org.locationtech.jts.geom.Coordinate coordinate, double dateline)
-
type
public abstract GeoShapeType type()
get the shapes type- Returns:
- type of the shape
-
numDimensions
public abstract int numDimensions()
tracks number of dimensions for this shape
-
intersection
protected static final double intersection(org.locationtech.jts.geom.Coordinate p1, org.locationtech.jts.geom.Coordinate p2, double dateline)
Calculate the intersection of a line segment and a vertical dateline.- Parameters:
p1
- start-point of the line segmentp2
- end-point of the line segmentdateline
- x-coordinate of the vertical dateline- Returns:
- position of the intersection in the open range (0..1] if the line
segment intersects with the line segment. Otherwise this method
returns
Double.NaN
-
intersections
protected static int intersections(double dateline, ShapeBuilder.Edge[] edges)
Calculate all intersections of line segments and a vertical line. The Array of edges will be ordered asc by the y-coordinate of the intersections of edges.- Parameters:
dateline
- x-coordinate of the datelineedges
- set of edges that may intersect with the dateline- Returns:
- number of intersecting edges
-
contentToWKT
protected java.lang.StringBuilder contentToWKT()
-
toWKT
public java.lang.String toWKT()
-
coordinateListToWKT
protected static java.lang.StringBuilder coordinateListToWKT(java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)
-
debugEnabled
protected static final boolean debugEnabled()
-
parse
@Deprecated public static ShapeBuilder parse(XContentParser parser) throws java.io.IOException
Deprecated.this method will be removed in a future version; use ShapeParser.parse instead- Throws:
java.io.IOException
-
toXContent
protected static XContentBuilder toXContent(XContentBuilder builder, org.locationtech.jts.geom.Coordinate coordinate) throws java.io.IOException
- Throws:
java.io.IOException
-
coordinatesToXcontent
protected XContentBuilder coordinatesToXcontent(XContentBuilder builder, boolean closed) throws java.io.IOException
builds an array of coordinates to aXContentBuilder
- Parameters:
builder
- builder to useclosed
- repeat the first point at the end of the array if it's not already defines as last element of the array- Returns:
- the builder
- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getWriteableName
public java.lang.String getWriteableName()
Description copied from interface:NamedWriteable
Returns the name of the writeable object- Specified by:
getWriteableName
in interfaceNamedWriteable
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-