PHP/KML Polyline Simplification with Douglas-Peucker
by Clay vanSchalkwijk on April 20, 2009
Quality GIS data sometimes comes with a lot more precision than what is usable for Google Maps (or other mapping software). The problem lies in the number of points representing a polygon that you want to overlay. A county representation for a state might include 100,000 points that is not usable without some form of reduction. Luckily there is an algorithm that solves that problem, Douglas-Peucker.
The algorithm simplifies a polyline by removing vertices that do not contribute (sufficiently) to the overall shape. It is a recursive process which finds the most important vertices for every given reduction. First, the most basic reduction is assumed. A single segment connecting the beginning and end of the original polyline. This is when the recursion starts, the most significant vertex (the most distant) for this segment is found and, when the distance from this vertex to the segment exceeds the reduction tolerance, the segment is split into two sub-segments, each inheriting a subset of the original vertex list. Each segment continues to subdivide until none of the vertices in the local list are further away than the tolerance value.
There is a PHP class that does just this: Douglas-Peucker Polyline Simplification in PHP by Anthony Cartmell. Based on the original quality of the data and tolerance level, I was able to achieve a 90-93% reduction in size. This reduction allows me to represent significantly more data at a reasonable performance level to clients. Keep in mind, that this reduction is removing data out of the coordinate array so the quality of your representation will go down with the tolerance and reduction being applied. I highly suggest that you play around with the tolerance until you find a good balance between data size and image quality.
3 comments
Hi ,
I would like to know where I can find this PHP class,
the link actually points to a HTTP 404 error page.
Thanks !
by zdf on April 25, 2011 at 11:46 am. #
I uploaded a few of the files since the original link was taken down:
http://www.derivante.com/files/reduction.txt
http://www.derivante.com/files/reduction-sample.txt
Shoot me an email if you have any questions getting it going. I had extracted a whole lot of shp files into lat/lng and needed it reduced considerably before rendering into google maps.
by Clay vanSchalkwijk on May 16, 2011 at 7:39 pm. #
Your page references KML but your example just seems to work with points. Do you have or can you recommend a Linux command line way to do
$ program in.kml out.kml tolerance
shapefiles or other similar formats ok,
Ive spent about two days trying to find this, and have only found solution in C#
thank you!
by Tom Friedel on May 8, 2009 at 3:52 pm. #