-
public class PointReducerReduces 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 doubleorthogonalDistance(GeoPoint point, GeoPoint lineStart, GeoPoint lineEnd)Calculate the orthogonal distance from the line joining thelineStart and lineEnd points to point -
-
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 reducetolerance- 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 forlineStart- The point that starts the linelineEnd- The point that ends the line
-
-
-
-