public class PolyUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
containsLocation(double latitude,
double longitude,
java.util.List<LatLng> polygon,
boolean geodesic)
Computes whether the given point lies inside the specified polygon.
|
static boolean |
containsLocation(LatLng point,
java.util.List<LatLng> polygon,
boolean geodesic) |
static java.util.List<LatLng> |
decode(java.lang.String encodedPath)
Decodes an encoded path string into a sequence of LatLngs.
|
static double |
distanceToLine(LatLng p,
LatLng start,
LatLng end)
Computes the distance on the sphere between the point p and the line segment start to end.
|
static java.lang.String |
encode(java.util.List<LatLng> path)
Encodes a sequence of LatLngs into an encoded path string.
|
static boolean |
isClosedPolygon(java.util.List<LatLng> poly)
Returns true if the provided list of points is a closed polygon (i.e., the first and last
points are the same), and false if it is not
|
static boolean |
isLocationOnEdge(LatLng point,
java.util.List<LatLng> polygon,
boolean geodesic)
Same as
isLocationOnEdge(LatLng, List, boolean, double)
with a default tolerance of 0.1 meters. |
static boolean |
isLocationOnEdge(LatLng point,
java.util.List<LatLng> polygon,
boolean geodesic,
double tolerance)
Computes whether the given point lies on or near the edge of a polygon, within a specified
tolerance in meters.
|
static boolean |
isLocationOnPath(LatLng point,
java.util.List<LatLng> polyline,
boolean geodesic)
|
static boolean |
isLocationOnPath(LatLng point,
java.util.List<LatLng> polyline,
boolean geodesic,
double tolerance)
Computes whether the given point lies on or near a polyline, within a specified
tolerance in meters.
|
static int |
locationIndexOnEdgeOrPath(LatLng point,
java.util.List<LatLng> poly,
boolean closed,
boolean geodesic,
double toleranceEarth)
Computes whether (and where) a given point lies on or near a polyline, within a specified tolerance.
|
static int |
locationIndexOnPath(LatLng point,
java.util.List<LatLng> polyline,
boolean geodesic)
|
static int |
locationIndexOnPath(LatLng point,
java.util.List<LatLng> poly,
boolean geodesic,
double tolerance)
Computes whether (and where) a given point lies on or near a polyline, within a specified tolerance.
|
static java.util.List<LatLng> |
simplify(java.util.List<LatLng> poly,
double tolerance)
Simplifies the given poly (polyline or polygon) using the Douglas-Peucker decimation
algorithm.
|
public static boolean containsLocation(LatLng point, java.util.List<LatLng> polygon, boolean geodesic)
public static boolean containsLocation(double latitude, double longitude, java.util.List<LatLng> polygon, boolean geodesic)
public static boolean isLocationOnEdge(LatLng point, java.util.List<LatLng> polygon, boolean geodesic, double tolerance)
public static boolean isLocationOnEdge(LatLng point, java.util.List<LatLng> polygon, boolean geodesic)
isLocationOnEdge(LatLng, List, boolean, double)
with a default tolerance of 0.1 meters.public static boolean isLocationOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic, double tolerance)
public static boolean isLocationOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic)
isLocationOnPath(LatLng, List, boolean, double)
with a default tolerance of 0.1 meters.
public static int locationIndexOnPath(LatLng point, java.util.List<LatLng> poly, boolean geodesic, double tolerance)
point
- our needlepoly
- our haystackgeodesic
- the polyline is composed of great circle segments if geodesic
is true, and of Rhumb segments otherwisetolerance
- tolerance (in meters)public static int locationIndexOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic)
locationIndexOnPath(LatLng, List, boolean, double)
with a default tolerance of 0.1 meters.
public static int locationIndexOnEdgeOrPath(LatLng point, java.util.List<LatLng> poly, boolean closed, boolean geodesic, double toleranceEarth)
point
- our needlepoly
- our haystackclosed
- whether the polyline should be considered closed by a segment connecting the last point back to the first onegeodesic
- the polyline is composed of great circle segments if geodesic
is true, and of Rhumb segments otherwisetoleranceEarth
- tolerance (in meters)public static java.util.List<LatLng> simplify(java.util.List<LatLng> poly, double tolerance)
When the providing a polygon as input, the first and last point of the list MUST have the same latitude and longitude (i.e., the polygon must be closed). If the input polygon is not closed, the resulting polygon may not be fully simplified.
The time complexity of Douglas-Peucker is O(n^2), so take care that you do not call this algorithm too frequently in your code.
poly
- polyline or polygon to be simplified. Polygon should be closed (i.e.,
first and last points should have the same latitude and longitude).tolerance
- in meters. Increasing the tolerance will result in fewer points in the
simplified poly.public static boolean isClosedPolygon(java.util.List<LatLng> poly)
poly
- polyline or polygonpublic static double distanceToLine(LatLng p, LatLng start, LatLng end)
p
- the point to be measuredstart
- the beginning of the line segmentend
- the end of the line segmentpublic static java.util.List<LatLng> decode(java.lang.String encodedPath)
public static java.lang.String encode(java.util.List<LatLng> path)