Michael Thomas Flanagan's Java Scientific Library

PolylineSimplification Class:     Polyline Simplification

     

Last update: 5 December 2011                                                                                                                              Main Page of Michael Thomas Flanagan's Java Scientific Library

This class contains the constructor and methods for performing a polyline simplification using the using the algorithm of Douglas and Peucker. A polyline is a polygonal chain, i.e. a curve through several points in which the segments between the points are treated as lines, and the simplification attempts to return a similar curve of fewer points.
This Java implementation is modelled on softSurfer's C++ implementation. See Polyline Simplification by Dan Sunday (Implementation).
The polyline is entered as an n point array of m dimensional data points where m may be 2 or 3, i.e. the simplification may be appied to either two or three dimensional curves. The point dimension, m, must be the same for all n points.

See Point.html for a convenient way of handling points in multidimensional space. Entering data to PolylineSimplification via an array of Point allows the entry of data types other than double. Point converts such arrays to double.

import directive: import flanagan.interpolation.PolylineSimplification;

SUMMARY OF CONSTRUCTOR AND METHODS

Constructors public PolylineSimplification(double[] xpoints, double[] ypoints, double[] zpoints)
public PolylineSimplification(double[] xpoints, double[] ypoints)
public PolylineSimplification(double[][] points)
public PolylineSimplification(Point[] points)
Simplification public Point[] douglasPeucker(double[] tolerance)
public Point[] douglasPeucker()
Return simplified curve public Point[] simplifiedCurve()
public double[][] simplifiedCurveCoordinates()
public int[] simplifiedCurveIndices()
public int numberOfSimplifiedCurvePoints()
Tolerance public void setTolerance(double tolerance)
public double getTolerance()
Plot public void plot()



CONSTRUCTORS

public PolylineSimplification(double[] xpoints, double[] ypoints, double[] zpoints)
public PolylineSimplification(double[] xpoints, double[] ypoints)
public PolylineSimplification(double[][] points)
public PolylineSimplification(Point[] points)

Constructor with data entered as three arrays of doubles
public PolylineSimplification(double xpoints, double ypoints, double zpoints)
Usage:                      PolylineSimplification pls = new PolylineSimplification(xpoints, ypoints, zpoints);
Creates an instance of the PolylineSimplification with the coordinates of the polyline data points entered as three arrays of doubles; xpoints should contain the values of the x-coordinates, ypoints should contain the values of the y-coordinates and zpoints should contain the values of the z-coordinates.

Constructor with data entered as two arrays of doubles
public PolylineSimplification(double xpoints, double ypoints)
Usage:                      PolylineSimplification pls = new PolylineSimplification(xpoints, ypoints);
Creates an instance of the PolylineSimplification with the coordinates of the polyline data points entered as two arrays of doubles; xpoints should contain the values of the x-coordinates and ypoints should contain the values of the y-coordinates.

Constructor with data entered as a multidimensional array
public PolylineSimplification(double[] points)
Usage:                      PolylineSimplification pls = new PolylineSimplification(points);
Creates an instance of the PolylineSimplification with the coordinates of the polyline data points [points] entered as a multidimensional array of doubles. The array is of the form double[n][m] where n is the dimensions of the point, i.e. 2 for points in two cartesian dimensional space (x and y), 3 for points in three dimensional cartesian space (x, y and z), and m is the number of data points.

Constructor with data entered as Point[]
public PolylineSimplification(Point[] points)
Usage:                      PolylineSimplification pls = new PolylineSimplification(points);
Creates an instance of the PolylineSimplification with the coordinates of the polyline data points [points] entered as a Point array.


METHODS

SIMPLIFICATION
public Point[] douglasPeucker(double[] tolerance)
public Point[] douglasPeucker()
Usage:                      scurve = pls.douglasPeucker(tolerance);
Returns the simplified curve using the Douglas-Peucker algorithm, as an array of Point, for the data entered as the argument of the Constructor and for a tolerance, argument tolerance.

Usage:                      scurve = pls.douglasPeucker();
Returns the simplified curve using the Douglas-Peucker algorithm, as an array of Point, for the data entered as the argument of the Constructor. The required tolerance must have been previously entered using the setTolerance method.



RETURN SIMPLIFED CURVE
public Point[] simplifiedCurve()
public double[][] simplifiedCurveCoordinates()
public int[] simplifiedCurveIndices()
public int numberOfSimplifiedCurvePoints()

Return the simplified curve points
public Point[] simplifiedCurve()
public double[][] simplifiedCurveCoordinates()
Usage:                      scurve = pls.simplifiedCurve();
This method returns the simplified curve as an array of Point, for the data entered as the argument of the Constructor.

Usage:                      scurve = pls.simplifiedCurveCoordinates();
This method returns the simplified curve, for the data entered as the argument of the Constructor, as a two dimensional array of doubles, double[n][m], where n is the dimensions of the point, i.e. 2 for points in two cartesian dimensional space (x and y), 3 for points in three dimensional cartesian space (x, y and z), etc., and m is the number of data points.

Return the simplified curve indices
public int[] simplifiedCurveIndices()
Usage:                      sci = pls.simplifiedCurveIndices();
This method returns the original indices of the simplified curve points.

Return the simplified curve indices
public int numberOfSimplifiedCurvePoints()
Usage:                      nscp = pls.numberOfSimplifiedCurvePoints();
This method returns the number of points in the simplified curve points.



TOLERANCE
Set tolerance
public void setTolerance(double tolerance)
Usage:                      pls.setTolerance(tolerance);
Sets the tolerance required by the Douglas-Peucker algorithm. Overrides any previously entered tolerence. This tolerance may also be entered via te argument list of the simplification method DouglasPeucker.

Get tolerance
public double getTolerance()
Usage:                      tol = pls.getTolerance();
Returns the tolerance used in the last performed Douglas-Peucker simplification.



PLOT A 2-DIMENSION SIMPLIFICATION
public void plot()
Usage:                      pls.plot();
This method only works for an array of 2D data points. It displays a graph showing plots of the original data and of the simplified curve.



EXAMPLE PROGRAM

The following link is to a short program illustrating the use of PolylineSimplification:

PolylineExample.java


OTHER CLASSES USED BY THIS CLASS

This class uses the following classes in this library:


This page was prepared by Dr Michael Thomas Flanagan