Package org.apache.lucene.geo
Class Polygon
java.lang.Object
org.apache.lucene.geo.LatLonGeometry
org.apache.lucene.geo.Polygon
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:
- Coordinates must be in clockwise order, except for holes. Holes must be in counter-clockwise order.
- The polygon must be closed: the first and last coordinates need to have the same values.
- The polygon must not be self-crossing, otherwise may result in unexpected behavior.
- All latitude/longitude values must be in decimal degrees.
- Polygons cannot cross the 180th meridian. Instead, use two polygons: one on each side.
- 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
Modifier and TypeFieldDescriptionfinal double
maximum latitude of this polygon's bounding box areafinal double
maximum longitude of this polygon's bounding box areafinal double
minimum latitude of this polygon's bounding box areafinal double
minimum longitude of this polygon's bounding box area -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
static Polygon[]
fromGeoJSON
(String geojson) Parses a standard GeoJSON polygon string.Polygon[]
getHoles()
Returns a copy of the internal holes arraydouble
getPolyLat
(int vertex) Returns latitude value at given indexdouble[]
Returns a copy of the internal latitude arraydouble
getPolyLon
(int vertex) Returns longitude value at given indexdouble[]
Returns a copy of the internal longitude arrayReturns the winding order (CW, COLINEAR, CCW) for the polygon shellint
hashCode()
int
numHoles()
returns the number of holes for the polygonint
returns the number of vertex pointsprotected Component2D
get aComponent2D
from this geometryprints polygons as geojsontoString()
static String
verticesToGeoJSON
(double[] lats, double[] lons) Methods inherited from class org.apache.lucene.geo.LatLonGeometry
create
-
Field Details
-
minLat
public final double minLatminimum latitude of this polygon's bounding box area -
maxLat
public final double maxLatmaximum latitude of this polygon's bounding box area -
minLon
public final double minLonminimum longitude of this polygon's bounding box area -
maxLon
public final double maxLonmaximum longitude of this polygon's bounding box area
-
-
Constructor Details
-
Polygon
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
Returns a copy of the internal holes array -
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
Description copied from class:LatLonGeometry
get aComponent2D
from this geometry- Specified by:
toComponent2D
in classLatLonGeometry
-
hashCode
public int hashCode() -
equals
-
toString
-
verticesToGeoJSON
-
toGeoJSON
prints polygons as geojson -
fromGeoJSON
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.- Throws:
ParseException
-