Package 

Class PolyUtil

    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final static double DEFAULT_TOLERANCE
    • Method Summary

      Modifier and Type Method Description
      static boolean containsLocation(LatLng point, List<LatLng> polygon, boolean geodesic)
      static boolean containsLocation(double latitude, double longitude, List<LatLng> polygon, boolean geodesic) Computes whether the given point lies inside the specified polygon.The polygon is always considered closed, regardless of whether the last point equalsthe first or not.Inside is defined as not containing the South Pole -- the South Pole is always outside.The polygon is formed of great circle segments if geodesic is true, and of rhumb(loxodromic) segments otherwise.
      static boolean isLocationOnEdge(LatLng point, List<LatLng> polygon, boolean geodesic, double tolerance) Computes whether the given point lies on or near the edge of a polygon, within a specifiedtolerance in meters.
      static boolean isLocationOnEdge(LatLng point, List<LatLng> polygon, boolean geodesic) Same as isLocationOnEdge with a default tolerance of 0.1 meters.
      static boolean isLocationOnPath(LatLng point, List<LatLng> polyline, boolean geodesic, double tolerance) Computes whether the given point lies on or near a polyline, within a specifiedtolerance in meters.
      static boolean isLocationOnPath(LatLng point, List<LatLng> polyline, boolean geodesic) Same as isLocationOnPathwith a default tolerance of 0.1 meters.
      static int locationIndexOnPath(LatLng point, List<LatLng> poly, boolean geodesic, double tolerance) Computes whether (and where) a given point lies on or near a polyline, within a specified tolerance.The polyline is not closed -- the closing segment between the first point and the last point is not included.
      static int locationIndexOnPath(LatLng point, List<LatLng> polyline, boolean geodesic) Same as locationIndexOnPathwith a default tolerance of 0.1 meters.
      static int locationIndexOnEdgeOrPath(LatLng point, 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.If closed, the closing segment between the last and first points of the polyline is not considered.
      static List<LatLng> simplify(List<LatLng> poly, double tolerance) Simplifies the given poly (polyline or polygon) using the Douglas-Peucker decimationalgorithm.
      static boolean isClosedPolygon(List<LatLng> poly) Returns true if the provided list of points is a closed polygon (i.e.
      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 List<LatLng> decode(String encodedPath) Decodes an encoded path string into a sequence of LatLngs.
      static String encode(List<LatLng> path) Encodes a sequence of LatLngs into an encoded path string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • containsLocation

         static boolean containsLocation(LatLng point, List<LatLng> polygon, boolean geodesic)
      • containsLocation

         static boolean containsLocation(double latitude, double longitude, List<LatLng> polygon, boolean geodesic)

        Computes whether the given point lies inside the specified polygon.The polygon is always considered closed, regardless of whether the last point equalsthe first or not.Inside is defined as not containing the South Pole -- the South Pole is always outside.The polygon is formed of great circle segments if geodesic is true, and of rhumb(loxodromic) segments otherwise.

      • isLocationOnEdge

         static boolean isLocationOnEdge(LatLng point, List<LatLng> polygon, boolean geodesic, double tolerance)

        Computes whether the given point lies on or near the edge of a polygon, within a specifiedtolerance in meters. The polygon edge is composed of great circle segments if geodesicis true, and of Rhumb segments otherwise. The polygon edge is implicitly closed -- theclosing segment between the first point and the last point is included.

      • isLocationOnPath

         static boolean isLocationOnPath(LatLng point, List<LatLng> polyline, boolean geodesic, double tolerance)

        Computes whether the given point lies on or near a polyline, within a specifiedtolerance in meters. The polyline is composed of great circle segments if geodesicis true, and of Rhumb segments otherwise. The polyline is not closed -- the closingsegment between the first point and the last point is not included.

      • locationIndexOnPath

         static int locationIndexOnPath(LatLng point, List<LatLng> poly, boolean geodesic, double tolerance)

        Computes whether (and where) a given point lies on or near a polyline, within a specified tolerance.The polyline is not closed -- the closing segment between the first point and the last point is not included.

        Parameters:
        point - our needle
        poly - our haystack
        geodesic - the polyline is composed of great circle segments if geodesicis true, and of Rhumb segments otherwise
        tolerance - tolerance (in meters)
      • locationIndexOnEdgeOrPath

         static int locationIndexOnEdgeOrPath(LatLng point, 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.If closed, the closing segment between the last and first points of the polyline is not considered.

        Parameters:
        point - our needle
        poly - our haystack
        closed - whether the polyline should be considered closed by a segment connecting the last point back to the first one
        geodesic - the polyline is composed of great circle segments if geodesicis true, and of Rhumb segments otherwise
        toleranceEarth - tolerance (in meters)
      • simplify

         static List<LatLng> simplify(List<LatLng> poly, double tolerance)

        Simplifies the given poly (polyline or polygon) using the Douglas-Peucker decimationalgorithm. Increasing the tolerance will result in fewer points in the simplified polylineor polygon.

        When the providing a polygon as input, the first and last point of the list MUST have thesame latitude and longitude (i.e., the polygon must be closed). If the input polygon is notclosed, 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 thisalgorithm too frequently in your code.

        Parameters:
        poly - polyline or polygon to be simplified.
        tolerance - in meters.
      • isClosedPolygon

         static boolean isClosedPolygon(List<LatLng> poly)

        Returns true if the provided list of points is a closed polygon (i.e., the first and lastpoints are the same), and false if it is not

        Parameters:
        poly - polyline or polygon
      • distanceToLine

         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.

        Parameters:
        p - the point to be measured
        start - the beginning of the line segment
        end - the end of the line segment
      • decode

         static List<LatLng> decode(String encodedPath)

        Decodes an encoded path string into a sequence of LatLngs.

      • encode

         static String encode(List<LatLng> path)

        Encodes a sequence of LatLngs into an encoded path string.