I am using the GEOS/OGR library in Python. I have files full of geometries that overlap, and I want to convert these to files of geometries that don't overlap.
The way I have been approaching this is to just read in all of the geometries from a file, and then looping over each geometry and taking the Union() of that with all of the previous geometries. So something like:
def dedup(geometries): """Return a geometry that is the union of all geometries.""" if not geometries: return None current_union = geometries.Clone() for g in geometries: current_union = current_union.Union(g).Clone() return current_union
Most of the time this appears to work, but occasionally Union() will return None. My debugging reveals that under these cases:
- IsValid() returns true for both g and current_union
- Intersects() return true between g and current_union
- GetGeometryCount() for current_union typically returns a number over 100.
- I suspect the error might be some kind of memory issue because it seems like the error "moves" depending on context. Ie if I say run this on files 1-100, it might crash on file 20, but if I say run it on files 20-100, it might crash on file 40. I never use Destroy() on any geometries. Task Manager does not show me running out of memory though.
Anyway, maybe there is an easier way to do this? Or else does anyone have any idea why it is crashing here?