Thanks, all good stuff. I am leaning toward the VW algorithm now.
So now for a more basic question--are there examples anywhere of how to instantiate a MultiPolygonField from a simple list of points? I am guessing it has a MultiPolygon class as its back end, but how do I tell whether it's the one from gdal.geometries or geos.collections?
http://www.djangosnippets.org/snippets/1559/
Thanks to Josh Livni for helpful pointers.
Comments are welcome, of course, either here or on the snippets page.
Thanks,
Steve
> Thanks, all good stuff. I am leaning toward the VW algorithm now.
VW rocks. I'd love to see that implemented in python.
http://users.cs.cf.ac.uk/C.B.Jones/Zhou_JonesSDH04.pdf
Dane
I didn't read the paper carefully, but this Python code at least captures some of the concepts.
http://www.djangosnippets.org/snippets/1559/
The code removes vertices by area, and recalculates triangles as vertices are removed. It does a straight area calculation, though, i.e. there is no tuning for flatness, convexity, etc.
Also, I didn't quite understand the section about removing all points and then restoring them in order, so I may be missing something, but my interpretation of the gist of the algorithm seemed to produce good results on our dataset.
If anybody gets a chance to play with the code I posted above, please let us know how you modified it.
Thanks,
Steve
>
> whereas I assume your code (which I haven't
> even looked at) does something like 1) walk
> along the line, removing 'unimportant' vertices as
> you go along, so perhaps previously removed vertices are not
> included in current calculations about what to remove
Just to be clear, after I remove any point, I do recalculate the effective areas for its neighbors, as you tend to want to keep a point more after its neighbor has been removed. So the algorithm is smart that way. But it *is* greedy, i.e. every iteration removes the least effective point, and there is no "restore" process.
Here is the main piece of code.
def simplify_points(points, max, id, name):
tups = []
for i, point in enumerate(points):
if i == 0 or i == len(points) - 1:
benefit = None
else:
benefit = benefit_function(point, points[i-1], points[i+1])
tups.append((point, benefit))
removals = 0
while len(tups) > max + 1:
min_benefit = tups[1][1]
min_i = 1
for i, (point, benefit) in enumerate(tups):
# print i, benefit
if benefit and benefit < min_benefit:
min_benefit = benefit
min_i = i
del tups[min_i]
removals += 1
for i in [min_i-1, min_i]:
point = tups[i][0]
if i == 0 or i == len(tups) - 1:
benefit = None
else:
benefit = benefit_function(point, tups[i-1][0], tups[i+1][0])
tups[i] = (point, benefit)
points = [point for point, benefit in tups]
return points
Ramer-Douglas-Peucker
implementation I found.-ElliotAlso, do you mean django.contrib.gis.gdal objects?Hi Max,Yes I can. Thanks for asking. The only thing is that GDAL objects take a while to create and each masking operation would have to create new ones for the result. I'm guesstimating that gdal geom creation time will be a good portion of the run time. A small number of gdal geoms with a large number of points would be fine, but 50,000+ might be sluggish. I'm sure it'll be fine though.
--
You received this message because you are subscribed to a topic in the Google Groups "geodjango" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/geodjango/EwgAxiVf0eA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to geodjango+...@googlegroups.com.
To post to this group, send email to geod...@googlegroups.com.
Visit this group at http://groups.google.com/group/geodjango.
For more options, visit https://groups.google.com/d/optout.
--