Package org.apache.lucene.geo
Class Polygon
- java.lang.Object
-
- 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 withdouble[]
coordinates, or usefromGeoJSON(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
-
-
Field Summary
Fields Modifier and Type Field Description private Polygon[]
holes
double
maxLat
maximum latitude of this polygon's bounding box areadouble
maxLon
maximum longitude of this polygon's bounding box areadouble
minLat
minimum latitude of this polygon's bounding box areadouble
minLon
minimum longitude of this polygon's bounding box areaprivate double[]
polyLats
private double[]
polyLons
private GeoUtils.WindingOrder
windingOrder
winding order of the vertices
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
static Polygon[]
fromGeoJSON(java.lang.String geojson)
Parses a standard GeoJSON polygon string.(package private) Polygon
getHole(int i)
Polygon[]
getHoles()
Returns a copy of the internal holes arraydouble
getPolyLat(int vertex)
Returns latitude value at given indexdouble[]
getPolyLats()
Returns a copy of the internal latitude arraydouble
getPolyLon(int vertex)
Returns longitude value at given indexdouble[]
getPolyLons()
Returns a copy of the internal longitude arrayGeoUtils.WindingOrder
getWindingOrder()
Returns the winding order (CW, COLINEAR, CCW) for the polygon shellint
hashCode()
int
numHoles()
returns the number of holes for the polygonint
numPoints()
returns the number of vertex pointsprotected Component2D
toComponent2D()
get aComponent2D
from this geometryjava.lang.String
toGeoJSON()
prints polygons as geojsonjava.lang.String
toString()
static java.lang.String
verticesToGeoJSON(double[] lats, double[] lons)
-
Methods inherited from class org.apache.lucene.geo.LatLonGeometry
create
-
-
-
-
Field Detail
-
polyLats
private final double[] polyLats
-
polyLons
private final double[] polyLons
-
holes
private final Polygon[] holes
-
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
-
windingOrder
private final GeoUtils.WindingOrder windingOrder
winding order of the vertices
-
-
Constructor Detail
-
Polygon
public Polygon(double[] polyLats, double[] polyLons, Polygon... holes)
Creates a new Polygon from the supplied latitude/longitude array, and optionally any holes.
-
-
Method Detail
-
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
-
getHole
Polygon getHole(int i)
-
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:LatLonGeometry
get aComponent2D
from this geometry- Specified by:
toComponent2D
in classLatLonGeometry
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
verticesToGeoJSON
public static java.lang.String verticesToGeoJSON(double[] lats, double[] lons)
-
toGeoJSON
public java.lang.String toGeoJSON()
prints polygons as geojson
-
fromGeoJSON
public static Polygon[] fromGeoJSON(java.lang.String geojson) throws java.text.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.- Throws:
java.text.ParseException
-
-