[geos-devel] C-API Question about GEOSPolygonize()

strk at refractions.net strk at refractions.net
Wed May 10 03:42:52 EDT 2006

On Tue, May 09, 2006 at 10:20:41PM -0400, Stephen Woodbridge wrote:
> With only the geos_c.h as doc for the C-API and getting totally lost in 
> the doxygen doc. I thought I would just ask:
> It seems from testing, that GEOSPolygonize() always returns a geometry 
> collection. Is this true? If not what can I expect as the range of 
> GEOSGeomTypeId that I can expect to get back.
> Assuming it is a geometry collection, what can I expect to find in the 
> collection. Only GEOS_POLYGON, or others like GEOS_MULTIPOLYGON and/or 
> others.

A collection of POLYGONS only. It's not a MULTIPOLYGON because
it would not be a valid one. Note that in postgis we added a
BuildArea function using an algorithm that outputs a valid
"MULTI"POLYGON instead, maybe we should port this to GEOS CAPI.

> How does one get the individual polygons out of a GEOS_MULTIPOLYGON? I 
> would have thought to use:
> extern int GEOS_DLL GEOSGetNumGeometries(const GEOSGeom g1);
> /*
>  * Return NULL on exception, Geometry must be a Collection.
>  * Returned object is a pointer to internal storage:
>  * it must NOT be destroyed directly.
>  */
> extern const GEOSGeom GEOS_DLL GEOSGetGeometryN(const GEOSGeom g, int n);
> /* Return -1 on exception */
> But the comment seems to imply that that is not the correct tool.

Why ? You can clone() the returned geometries to have a clean
version of the elements.

> What I am trying to do is load a bunch of polylines into linestrings and 
> feed them to GEOSPolygonize then load the results into polygon 
> shapefiles. I would like the shapefiles to be able to be loaded into 
> postGIS as valid polygons if I need to do that later.

See above, the buildarea of postgis can do this directly, try loading
the polylines directly into it and use buildarea on them. The result
will likely be a MULTIPOLYGON that you can dump() to obtain elements.


More information about the geos-devel mailing list