[GIS] Help simplifying multipolygons in geodjango

geodjangogeometrysimplify

I have a few multipolygons that have several hundred points in them. I'm looking to create less complex "thumbnails" polygons.

Naturally I'm attempting to use the simplify method, which is supposed to apply the Ramer-Douglas-Peucker algorithm. However, it doesn't seem to be working:

>>> m = Multipolygon.objects.get(id=1)
>>> m.geometry.num_points
1007
>>> m.geometry.simplify(0).num_points
1007
>>> m.geometry.simplify(1).num_points
0
>>> m.geometry.simplify(0.5).num_points
0
>>> m.geometry.simplify(10).num_points
0

I'm clearly missing something. When I simplify, I either get the original polygon back or an empty one, depending on the tolerance value that I use. How is the tolerance parameter supposed to work?

Best Answer

The tolerance value is specified in map units: if two points are within the snapping tolerance, they are collapsed. So if you have geographic coordinates, simplify(1) would collapse everything to the nearest degree. Try something like simplify(0.0001) to start, or smaller depending on the resolution of your input data.

You may also be interested in this snippet, which allows you to specify precision as a number of points to retain in the output geometry.