Elasticsearch geometry library providing core geometric shapes and spatial utility classes for geometric computations and operations.
—
The Elasticsearch Geo library provides fundamental geometric shapes for representing spatial data. All geometry types implement the base Geometry interface and support both 2D and 3D coordinates with optional altitude values.
Represents a single point in space with longitude/latitude coordinates and optional altitude.
/**
* Creates a 2D point with longitude and latitude coordinates
* @param x longitude in decimal degrees
* @param y latitude in decimal degrees
*/
public Point(double x, double y)
/**
* Creates a 3D point with longitude, latitude, and altitude
* @param x longitude in decimal degrees
* @param y latitude in decimal degrees
* @param z altitude in meters
*/
public Point(double x, double y, double z)
// Coordinate getters
public double getX() // longitude
public double getY() // latitude
public double getZ() // altitude
public double getLon() // alias for getX()
public double getLat() // alias for getY()
public double getAlt() // alias for getZ()
// Empty point constant
public static final Point EMPTYRepresents a circular area defined by a center point and radius in meters.
/**
* Creates a 2D circle with center coordinates and radius
* @param x center longitude in decimal degrees
* @param y center latitude in decimal degrees
* @param radiusMeters radius in meters (must be positive)
* @throws IllegalArgumentException if radius is negative
*/
public Circle(double x, double y, double radiusMeters)
/**
* Creates a 3D circle with center coordinates, altitude, and radius
* @param x center longitude in decimal degrees
* @param y center latitude in decimal degrees
* @param z center altitude in meters
* @param radiusMeters radius in meters (must be positive)
*/
public Circle(double x, double y, double z, double radiusMeters)
// Center coordinate getters
public double getX() // center longitude
public double getY() // center latitude
public double getZ() // center altitude
public double getLon() // alias for getX()
public double getLat() // alias for getY()
public double getAlt() // alias for getZ()
// Radius getter
public double getRadiusMeters()
// Empty circle constant
public static final Circle EMPTYRepresents a rectangular bounding box defined by minimum and maximum coordinates.
/**
* Creates a 2D rectangle with coordinate bounds
* @param minX minimum longitude
* @param maxX maximum longitude
* @param maxY maximum latitude
* @param minY minimum latitude
* @throws IllegalArgumentException if maxY < minY
*/
public Rectangle(double minX, double maxX, double maxY, double minY)
/**
* Creates a 3D rectangle with coordinate and altitude bounds
* @param minX minimum longitude
* @param maxX maximum longitude
* @param maxY maximum latitude
* @param minY minimum latitude
* @param minZ minimum altitude
* @param maxZ maximum altitude
* @throws IllegalArgumentException if maxY < minY or only one Z value specified
*/
public Rectangle(double minX, double maxX, double maxY, double minY, double minZ, double maxZ)
// Boundary getters
public double getMinX() // minimum longitude
public double getMaxX() // maximum longitude
public double getMinY() // minimum latitude
public double getMaxY() // maximum latitude
public double getMinZ() // minimum altitude
public double getMaxZ() // maximum altitude
// Alternative boundary getters
public double getMinLon() // alias for getMinX()
public double getMaxLon() // alias for getMaxX()
public double getMinLat() // alias for getMinY()
public double getMaxLat() // alias for getMaxY()
public double getMinAlt() // alias for getMinZ()
public double getMaxAlt() // alias for getMaxZ()
// Empty rectangle constant
public static final Rectangle EMPTYRepresents a line string composed of multiple connected points.
/**
* Creates a 2D line from coordinate arrays
* @param x array of longitude coordinates
* @param y array of latitude coordinates
* @throws IllegalArgumentException if arrays are null, different lengths, or less than 2 points
*/
public Line(double[] x, double[] y)
/**
* Creates a 3D line from coordinate arrays
* @param x array of longitude coordinates
* @param y array of latitude coordinates
* @param z array of altitude coordinates (can be null)
* @throws IllegalArgumentException if coordinate arrays have different lengths
*/
public Line(double[] x, double[] y, double[] z)
// Point access methods
public int length() // number of points in line
public double getX(int i) // longitude of point at index i
public double getY(int i) // latitude of point at index i
public double getZ(int i) // altitude of point at index i (NaN if no Z values)
public double getLon(int i) // alias for getX(int)
public double getLat(int i) // alias for getY(int)
public double getAlt(int i) // alias for getZ(int)
// Array getters (returns cloned arrays)
public double[] getX() // array of longitude coordinates
public double[] getY() // array of latitude coordinates
public double[] getZ() // array of altitude coordinates (null if no Z values)
public double[] getLons() // alias for getX()
public double[] getLats() // alias for getY()
public double[] getAlts() // alias for getZ()
// Empty line constant
public static final Line EMPTYRepresents a closed line where the first and last points are identical, used as polygon boundaries.
/**
* Creates a 2D linear ring from coordinate arrays
* @param x array of longitude coordinates (first and last must be equal)
* @param y array of latitude coordinates (first and last must be equal)
* @throws IllegalArgumentException if ring is not closed or has less than 2 points
*/
public LinearRing(double[] x, double[] y)
/**
* Creates a 3D linear ring from coordinate arrays
* @param x array of longitude coordinates (first and last must be equal)
* @param y array of latitude coordinates (first and last must be equal)
* @param z array of altitude coordinates (first and last must be equal, can be null)
* @throws IllegalArgumentException if ring is not closed
*/
public LinearRing(double[] x, double[] y, double[] z)
// Inherits all methods from Line class
// Additional validation ensures ring closure
// Empty linear ring constant
public static final LinearRing EMPTYRepresents a polygon with an outer ring and optional holes (inner rings).
/**
* Creates a polygon with only an outer boundary
* @param polygon outer boundary as LinearRing
*/
public Polygon(LinearRing polygon)
/**
* Creates a polygon with outer boundary and holes
* @param polygon outer boundary as LinearRing
* @param holes list of holes as LinearRings (cannot be null)
* @throws IllegalArgumentException if holes is null or rings have different dimensions
*/
public Polygon(LinearRing polygon, List<LinearRing> holes)
// Structure access methods
public LinearRing getPolygon() // gets outer ring
public int getNumberOfHoles() // number of holes
public LinearRing getHole(int i) // gets hole by index
// @throws IllegalArgumentException if index is out of bounds
// Empty polygon constant
public static final Polygon EMPTYAll geometry types implement these base interface methods:
/**
* Returns the shape type of this geometry
* @return ShapeType enum value (POINT, CIRCLE, POLYGON, etc.)
*/
ShapeType type()
/**
* Accepts a visitor for type-safe processing
* @param visitor the geometry visitor
* @return result from visitor processing
* @throws E exception type from visitor
*/
<T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E
/**
* Checks if geometry represents an empty/null geometry
* @return true if geometry is empty
*/
boolean isEmpty()
/**
* Checks if geometry has altitude/Z dimension
* @return true if geometry includes Z coordinates
*/
boolean hasZ()
/**
* Alias for hasZ() method
* @return true if geometry includes altitude values
*/
boolean hasAlt()import org.elasticsearch.geometry.*;
// Create various geometry types
Point point = new Point(-73.935242, 40.730610);
Circle circle = new Circle(-73.935242, 40.730610, 1000.0);
// Create polygon from coordinate arrays
double[] lons = {-74.0, -73.9, -73.9, -74.0, -74.0};
double[] lats = {40.7, 40.7, 40.8, 40.8, 40.7};
LinearRing ring = new LinearRing(lons, lats);
Polygon polygon = new Polygon(ring);
// Check geometry properties
boolean hasAltitude = point.hasZ(); // false for 2D point
ShapeType type = circle.type(); // ShapeType.CIRCLE
boolean empty = polygon.isEmpty(); // false
// Access coordinates
double lat = point.getLat(); // 40.730610
double radius = circle.getRadiusMeters(); // 1000.0
int vertices = ring.length(); // 5Install with Tessl CLI
npx tessl i tessl/maven-org-elasticsearch--elasticsearch-geo