I'm working with a large dataset, and I need to be able to combine up to 400,000 polygons. I have been using the
QgsGeometry::combine(QgsGeometry* geometry) function and simply looping over all geometries in an interative fashion like this:
union_geoms = geometries for geometry in geometries: union_geoms = union_geoms.combine(geometry)
This works fine for most of my data, (the largest list of polygons I have gotten it to complete is ~30,000.) But I have two sets of ~200,000 and one of ~400,000 and I can't get this to complete in a timely fashion (I have let it run for days to no avail). So I started looking for a better method to combine these geometries, and I found
geos::operation::geounion::CascadedPolygonUnion This algorithm, described here, is well suited to my application as the polygons of interest contain a lot of adjacency.
So my question is how would I go about implementing this type of algorithm, or more simply how can I use the existing implementation in GEOS from my own (python) scripts? From the 2013 link,
you can use
QgsGeometry::asGeos()in the plugin instead of wkt-export / wkt-import. For cascaded union, there is the method
GEOSUnaryUnion(const GEOSGeometry* g1)in the c-api. The argument seems to be a geometry collection, which can be created with
But there doesn't seem to by python bindings for the
Anyone have suggestions as to how to proceed?