vis/geometry/
mg_polyline_simplify.pro
includes main-level program This function simplifies the vertices of an n
-dimenstional polyline.
Vertices are removed if they are within a tolerance tangential distance from
an approximating line segment.
Examples
See the main-level program at the end of this file for some examples. To run them, type:
IDL> .run mg_polyline_simplify
Author information
- History
Original written by: Brad Gom, April 2004 Modified by Michael Galloy, 2010
Routines
Routines from mg_polyline_simplify.pro
result = mg_polyline_simplify_dot(x, y)
Computes the dot product.
result = mg_polyline_simplify_d2(x, y)
Computes the distance squared of difference between points x and y
mg_polyline_simplify_dp, tol2, vertices, j, k, mk
This is the Douglas-Peucker recursive simplification routine.
result = mg_polyline_simplify(vertices [, tolerance=float] [, factor=float])
MG_POLYLINE_SIMPLIFY uses the Douglas-Peucker (DP) approximation algorithm that is used extensively for both computer graphics and geographic information systems.
Routine details
top mg_polyline_simplify_dot
result = mg_polyline_simplify_dot(x, y)
Computes the dot product.
Return value
float
Parameters
- x in required type=vector
first parameter
- y in required type=vector
first parameter
top mg_polyline_simplify_d2
result = mg_polyline_simplify_d2(x, y)
Computes the distance squared of difference between points x and y
Return value
float
Parameters
- x in required type=fltarr(2)
first point
- y in required type=fltarr(2)
second point
top mg_polyline_simplify_dp
mg_polyline_simplify_dp, tol2, vertices, j, k, mk
This is the Douglas-Peucker recursive simplification routine. It marks
vertices that are part of the simplified polyline for approximating the
polyline subchain vertices[j]
to vertices[k]
.
Parameters
- tol2 in required type=float
approximation tolerance squared
- vertices in required type=fltarr(m, n)
polyline array of vertex points
- j in required type=long
starting index fo subchain
- k in required type=long
ending index fo subchain
- mk in out required type=bytarr(n)
array of markers matching vertex array
vertices
top mg_polyline_simplify
result = mg_polyline_simplify(vertices [, tolerance=float] [, factor=float])
MG_POLYLINE_SIMPLIFY
uses the Douglas-Peucker (DP) approximation
algorithm that is used extensively for both computer graphics and geographic
information systems. See geometryalgorithms.com.
Return value
This function returns the simplified array of vertices. If an error occurs, the output vertices will all be -1L.
Parameters
- vertices in required type=fltarr(m, n)
An array of vertices representing the polyline. Must be a [m, n] array, where
m
is the dimensionality andn
is the number of vertices. Bothm > 1
andn > 1
are required.
Keywords
- tolerance in optional type=float
Set this keyword to the tolerance value to use. If
tolerance
is not set, or set to a negative or zero value, then the tolerance will be set automatically to the minimum average spacing along any dimension between points.Choice of tolerance is key to the amount of simplification. The routine approximates the polyline with line segments that are no further than tolerance from any vertices. Vertices that are within tolerance from the approximating lines are removed. If no tolerance is specified, the routine uses the minimum distance in each dimension between vertices, and multiplies this by
factor
as a tolerance.- factor in optional type=float default=1.
Set this keyword instead of
tolerance
to scale the automatic tolerance. For example,FACTOR=10
will use 10x the minimum average spacing between points as the tolerance. Ignored iftolerance
is set.
File attributes
Modification date: | Wed May 14 15:07:15 2014 |
Lines: | 134 |
Docformat: | rst rst |
Contact me if you have enhancement requests or bug fixes.