Class ShapeBuilder<T extends org.locationtech.spatial4j.shape.Shape,​G extends org.elasticsearch.geometry.Geometry,​E extends ShapeBuilder<T,​G,​E>>

java.lang.Object
org.elasticsearch.common.geo.builders.ShapeBuilder<T,​G,​E>
All Implemented Interfaces:
NamedWriteable, Writeable, org.elasticsearch.common.xcontent.ToXContent, org.elasticsearch.common.xcontent.ToXContentObject
Direct Known Subclasses:
CircleBuilder, EnvelopeBuilder, GeometryCollectionBuilder, LineStringBuilder, MultiLineStringBuilder, MultiPointBuilder, MultiPolygonBuilder, PointBuilder, PolygonBuilder

public abstract class ShapeBuilder<T extends org.locationtech.spatial4j.shape.Shape,​G extends org.elasticsearch.geometry.Geometry,​E extends ShapeBuilder<T,​G,​E>> extends Object implements NamedWriteable, org.elasticsearch.common.xcontent.ToXContentObject
Basic class for building GeoJSON shapes like Polygons, Linestrings, etc
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
    This helper class implements a linked list for Coordinate.

    Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent

    org.elasticsearch.common.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.common.xcontent.ToXContent.MapParams, org.elasticsearch.common.xcontent.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
     
    protected static boolean
     
    protected List<org.locationtech.jts.geom.Coordinate>
     
    static double
     
    static org.locationtech.jts.geom.GeometryFactory
     
    protected static org.elasticsearch.common.geo.builders.ShapeBuilder.IntersectionOrder
     
    protected static org.apache.logging.log4j.Logger
     
    protected static boolean
    It's possible that some geometries in a MULTI* shape might overlap.
    static org.locationtech.spatial4j.context.jts.JtsSpatialContext
     
    protected boolean
    We're expecting some geometries might cross the dateline.
    static org.locationtech.jts.geom.Coordinate
    coordinate at [0.0, 0.0]

    Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent

    EMPTY_PARAMS
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    default ctor
    protected
    ShapeBuilder​(List<org.locationtech.jts.geom.Coordinate> coordinates)
    ctor from list of coordinates
    protected
    ctor from serialized stream input
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract G
    build lucene geometry.
    abstract T
    Create a new Shape from this builder.
    protected StringBuilder
     
    coordinate​(double longitude, double latitude)
    Add a new coordinate to the collection
    coordinate​(org.locationtech.jts.geom.Coordinate coordinate)
    Add a new coordinate to the collection
    protected static StringBuilder
    coordinateListToWKT​(List<org.locationtech.jts.geom.Coordinate> coordinates)
     
    protected org.locationtech.jts.geom.Coordinate[]
    coordinates​(boolean closed)
    Copy all coordinate to a new Array
    coordinates​(Collection<? extends org.locationtech.jts.geom.Coordinate> coordinates)
    Add a collection of coordinates to the collection
    coordinates​(org.locationtech.jts.geom.Coordinate... coordinates)
    Add a array of coordinates to the collection
    protected org.elasticsearch.common.xcontent.XContentBuilder
    coordinatesToXcontent​(org.elasticsearch.common.xcontent.XContentBuilder builder, boolean closed)
    builds an array of coordinates to a XContentBuilder
    protected static boolean
     
    boolean
    equals​(Object o)
     
    Returns the name of the writeable object
    int
     
    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
    tracks number of dimensions for this shape
    protected static org.locationtech.jts.geom.Coordinate
     
    protected static org.locationtech.jts.geom.Coordinate
    shift​(org.locationtech.jts.geom.Coordinate coordinate, double dateline)
     
     
     
    protected static org.elasticsearch.common.xcontent.XContentBuilder
    toXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.locationtech.jts.geom.Coordinate coordinate)
     
    abstract GeoShapeType
    get the shapes type
    protected static void
    writeCoordinateTo​(org.locationtech.jts.geom.Coordinate coordinate, StreamOutput out)
     
    void
    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 Details

    • LOGGER

      protected static final org.apache.logging.log4j.Logger LOGGER
    • coordinates

      protected final 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 Details

    • ShapeBuilder

      protected ShapeBuilder()
      default ctor
    • ShapeBuilder

      protected ShapeBuilder(List<org.locationtech.jts.geom.Coordinate> coordinates)
      ctor from list of coordinates
    • ShapeBuilder

      protected ShapeBuilder(StreamInput in) throws IOException
      ctor from serialized stream input
      Throws:
      IOException
  • Method Details

    • readFromStream

      protected static org.locationtech.jts.geom.Coordinate readFromStream(StreamInput in) throws IOException
      Throws:
      IOException
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • writeCoordinateTo

      protected static void writeCoordinateTo(org.locationtech.jts.geom.Coordinate coordinate, StreamOutput out) throws IOException
      Throws:
      IOException
    • coordinate

      public E coordinate(double longitude, double latitude)
      Add a new coordinate to the collection
      Parameters:
      longitude - longitude of the coordinate
      latitude - 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 of Coordinates to add
      Returns:
      this
    • coordinates

      public E coordinates(Collection<? extends org.locationtech.jts.geom.Coordinate> coordinates)
      Add a collection of coordinates to the collection
      Parameters:
      coordinates - array of Coordinates 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
    • buildGeometry

      public abstract G buildGeometry()
      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 segment
      p2 - end-point of the line segment
      dateline - 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 dateline
      edges - set of edges that may intersect with the dateline
      Returns:
      number of intersecting edges
    • contentToWKT

      protected StringBuilder contentToWKT()
    • toWKT

      public String toWKT()
    • coordinateListToWKT

      protected static StringBuilder coordinateListToWKT(List<org.locationtech.jts.geom.Coordinate> coordinates)
    • debugEnabled

      protected static final boolean debugEnabled()
    • toXContent

      protected static org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.locationtech.jts.geom.Coordinate coordinate) throws IOException
      Throws:
      IOException
    • coordinatesToXcontent

      protected org.elasticsearch.common.xcontent.XContentBuilder coordinatesToXcontent(org.elasticsearch.common.xcontent.XContentBuilder builder, boolean closed) throws IOException
      builds an array of coordinates to a XContentBuilder
      Parameters:
      builder - builder to use
      closed - 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:
      IOException
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getWriteableName

      public String getWriteableName()
      Description copied from interface: NamedWriteable
      Returns the name of the writeable object
      Specified by:
      getWriteableName in interface NamedWriteable
    • toString

      public String toString()
      Overrides:
      toString in class Object