Collectionextract function in C api
Maybe I looked over it, but I don't seem to find an ST_CollectionExtract equivalent in the C API.
If it is indeed not available, it would be great if it could be added...
Regards, Pieter
The C++ API has a geos::geom::util::GeometryExtracter class (example use with GeometryExtracterTest.cpp), but this does appear to be absent from the C API.
If it is indeed not available, it would be great if it could be added...
What is your use case for this? Is it to deal with mixed-dimension results from overlay operations, or something else?
Related: https://trac.osgeo.org/geos/ticket/1117
Here's a possible design, for comment:
Geometry* GEOSGeom_extractCollection(Geometry* collection, unsigned int dimension)
Should this have simple copy semantics? Or should it minimize allocations via:
- adds the elements of required dimension to a new
Multigeometry (should this be returned as an atomic geometry if only one element is found?) - ?? any elements not returned are destroyed automatically
- ?? caller must destroy original geometry
Actually the question of "return POLYGON() or return MULTIPOLYGON()" for single-item collections seems a little fraught... doing so over a set could result in a heterogeneous set of POLYGON/MULTIPOLYGON instead of a nice homogeneous set of MULTIPOLYGON.
Actually the question of "return
POLYGON()or returnMULTIPOLYGON()" for single-item collections seems a little fraught... doing so over a set could result in a heterogeneous set of POLYGON/MULTIPOLYGON instead of a nice homogeneous set of MULTIPOLYGON.
Fraught indeed... also, extracting an arbitrary set of polygons into a MULTIPOLYGON might produce an invalid geometry, if they happen to overlap.
I suggest taking the low road and just banging all polygons into a single MULTIPOLYGON, caveat usor. For more refined semantics the user will have to write their own code.
If it is indeed not available, it would be great if it could be added...
What is your use case for this? Is it to deal with mixed-dimension results from overlay operations, or something else?
Yes indeed. Remove eg. lines and points from collections returned from overlay operations (e.g. intersection,...) between polygons, or cleanup the result of makevalid if linework algorithm is used, as it doesn't support keepcollapsed=False.
I suppose the GeometryExtracter mentioned above already takes this in account, but to be sure: geometrycollections can be nested, so possibly the extraction needs to be recursive (or maybe/hopefully there is some limit on the number of nestings?).
E.g. GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(LINESTRING(0 0, 1 1)),LINESTRING(2 2, 3 3))
geometrycollections can be nested, so possibly the extraction needs to be recursive (or maybe/hopefully there is some limit on the number of nestings?).
Yes, this function needs to extract all elements from nested GeometryCollections.