Package org.apache.lucene.geo

# Class Polygon

java.lang.Object
org.apache.lucene.geo.Geometry
org.apache.lucene.geo.LatLonGeometry
org.apache.lucene.geo.Polygon

public final class Polygon extends LatLonGeometry
Represents a closed polygon on the earth's surface. You can either construct the Polygon directly yourself with `double[]` coordinates, or use `fromGeoJSON(java.lang.String)` if you have a polygon already encoded as a GeoJSON string.

NOTES:

1. Coordinates must be in clockwise order, except for holes. Holes must be in counter-clockwise order.
2. The polygon must be closed: the first and last coordinates need to have the same values.
3. The polygon must not be self-crossing, otherwise may result in unexpected behavior.
4. All latitude/longitude values must be in decimal degrees.
5. Polygons cannot cross the 180th meridian. Instead, use two polygons: one on each side.
6. For more advanced GeoSpatial indexing and query operations see the `spatial-extras` module

WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `final double`
  `maxLat`
  maximum latitude of this polygon's bounding box area
  `final double`
  `maxLon`
  maximum longitude of this polygon's bounding box area
  `final double`
  `minLat`
  minimum latitude of this polygon's bounding box area
  `final double`
  `minLon`
  minimum longitude of this polygon's bounding box area

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Polygon(double[] polyLats, double[] polyLons, Polygon... holes)`
  Creates a new Polygon from the supplied latitude/longitude array, and optionally any holes.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  `static Polygon[]`
  `fromGeoJSON(String geojson)`
  Parses a standard GeoJSON polygon string.
  `Polygon[]`
  `getHoles()`
  Returns a copy of the internal holes array
  `double`
  `getPolyLat(int vertex)`
  Returns latitude value at given index
  `double[]`
  `getPolyLats()`
  Returns a copy of the internal latitude array
  `double`
  `getPolyLon(int vertex)`
  Returns longitude value at given index
  `double[]`
  `getPolyLons()`
  Returns a copy of the internal longitude array
  `GeoUtils.WindingOrder`
  `getWindingOrder()`
  Returns the winding order (CW, COLINEAR, CCW) for the polygon shell
  `int`
  `hashCode()`
  `int`
  `numHoles()`
  returns the number of holes for the polygon
  `int`
  `numPoints()`
  returns the number of vertex points
  `protected Component2D`
  `toComponent2D()`
  get a Component2D from the geometry object
  `String`
  `toGeoJSON()`
  prints polygons as geojson
  `String`
  `toString()`
  `static String`
  `verticesToGeoJSON(double[] lats, double[] lons)`

  ### Methods inherited from class org.apache.lucene.geo.LatLonGeometry

  `create`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### minLat

    public final double minLat
    minimum latitude of this polygon's bounding box area

  - ### maxLat

    public final double maxLat
    maximum latitude of this polygon's bounding box area

  - ### minLon

    public final double minLon
    minimum longitude of this polygon's bounding box area

  - ### maxLon

    public final double maxLon
    maximum longitude of this polygon's bounding box area

- ## Constructor Details

  - ### Polygon

    public Polygon(double[] polyLats, double[] polyLons, Polygon... holes)
    Creates a new Polygon from the supplied latitude/longitude array, and optionally any holes.

- ## Method Details

  - ### numPoints

    public int numPoints()
    returns the number of vertex points

  - ### getPolyLats

    public double[] getPolyLats()
    Returns a copy of the internal latitude array

  - ### getPolyLat

    public double getPolyLat(int vertex)
    Returns latitude value at given index

  - ### getPolyLons

    public double[] getPolyLons()
    Returns a copy of the internal longitude array

  - ### getPolyLon

    public double getPolyLon(int vertex)
    Returns longitude value at given index

  - ### getHoles

    public Polygon[] getHoles()
    Returns a copy of the internal holes array

  - ### getWindingOrder

    public GeoUtils.WindingOrder getWindingOrder()
    Returns the winding order (CW, COLINEAR, CCW) for the polygon shell

  - ### numHoles

    public int numHoles()
    returns the number of holes for the polygon

  - ### toComponent2D

    protected Component2D toComponent2D()
    Description copied from class: `Geometry`
    get a Component2D from the geometry object
    Specified by:
      `toComponent2D` in class `Geometry`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### verticesToGeoJSON

    public static String verticesToGeoJSON(double[] lats, double[] lons)

  - ### toGeoJSON

    public String toGeoJSON()
    prints polygons as geojson

  - ### fromGeoJSON

    public static Polygon[] fromGeoJSON(String geojson) throws ParseException
    Parses a standard GeoJSON polygon string. The type of the incoming GeoJSON object must be a Polygon or MultiPolygon, optionally embedded under a "type: Feature". A Polygon will return as a length 1 array, while a MultiPolygon will be 1 or more in length.

    See the GeoJSON specification.

    Throws:
      `ParseException`