Package 

Class PointReducer


  • 
    public class PointReducer
    
                        

    Reduces the number of points in a shape using the Douglas-Peucker algorithm.

    From: http://www.phpriot.com/articles/reducing-map-path-douglas-peucker-algorithm/4Ported from PHP to Java. "marked" array added to optimize.

    • Method Summary

      Modifier and Type Method Description
      static ArrayList<GeoPoint> reduceWithTolerance(ArrayList<GeoPoint> shape, double tolerance) Reduce the number of points in a shape using the Douglas-Peucker algorithmSuggested usage
      {@code * * //get the screen bounds * BoundingBox boundingBox = map.getBoundingBox(); * final double latSpanDegrees = boundingBox.getLatitudeSpan(); * //get the degree difference, divide by dpi * double tolerance = latSpanDegrees /densityDpi; * //each latitude degree on screen is represented by this many dip * points = PointReducer.reduceWithTolerance(points, tolerance); * * }
      
       
      static double orthogonalDistance(GeoPoint point, GeoPoint lineStart, GeoPoint lineEnd) Calculate the orthogonal distance from the line joining thelineStart and lineEnd points to point
      • Methods inherited from class java.lang.Object

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

      • reduceWithTolerance

         static ArrayList<GeoPoint> reduceWithTolerance(ArrayList<GeoPoint> shape, double tolerance)

        Reduce the number of points in a shape using the Douglas-Peucker algorithmSuggested usage

        {@code * * //get the screen bounds * BoundingBox boundingBox = map.getBoundingBox(); * final double latSpanDegrees = boundingBox.getLatitudeSpan(); * //get the degree difference, divide by dpi * double tolerance = latSpanDegrees /densityDpi; * //each latitude degree on screen is represented by this many dip * points = PointReducer.reduceWithTolerance(points, tolerance); * * }
        
         
        Parameters:
        shape - The shape to reduce
        tolerance - The tolerance to decide whether or notto keep a point, in the coordinate systemof the points (micro-degrees here)
      • orthogonalDistance

         static double orthogonalDistance(GeoPoint point, GeoPoint lineStart, GeoPoint lineEnd)

        Calculate the orthogonal distance from the line joining thelineStart and lineEnd points to point

        Parameters:
        point - The point the distance is being calculated for
        lineStart - The point that starts the line
        lineEnd - The point that ends the line