[gdal-dev] Adding multipolygons to an existing geometry collection

danotchki danotchki at gmail.com
Thu Mar 25 06:35:28 EDT 2010

That would be awesome, Frank. forceToMultiPolygon was exactly the function I
was looking for (and wondering why it wasn' there).

Just pushing my luck: would there be another way to force the type of
Geometry returned by GetFeatureRef or when getting the layer from the data
source opening the shp?

Thanks again for your help. I'm a big fan of the OGR tools.


On Wed, Mar 24, 2010 at 8:07 PM, Frank Warmerdam <warmerdam at pobox.com>wrote:

> danotchki wrote:
>> Hello List,
>> I hope you will be able to help me. I'm stuck on a problem.
>> I'm trying to reconstruct within my Python script polygons from a
>> shapefile that belong together.
>> So I naturally perfomed:
>> geom_tmp = ogr.CreateGeometryFromWkb(ftr.GetGeometryRef().ExportToWkb())
>> geom.AddGeometryDirectly(geom_tmp)
>> However this works only when the geometry to add is of type POLYGON. This
>> _doesn't_ work with type MULTIPOLYGON (exit code 3).
> Daniel,
> What type is "geom"?  If it is a MULTIPOLYGON then it can only
> have polygons as children, not multipolygons.
>  My question: is there a way to add MULTIPOLYGONs to an existing Geometry?
>> What I don't understand is that when CreateGeometryFromWkb returns a
>> MULTIPOLYGON it actually returns a GEOMETRY instead of a GEOMETRYCOLLECTION,
>> thus preventing looping on each individual geometry with GetNumGeometries.
>> Would there be a way to cast the polygon to a multipolygon?
> In C/C++ there are methods on OGRGeometryFactory like
> forceToPolygon and forceToMultiPolygon that might be helpful
> but I see these are not exposed in Python.  Are you willing to
> build from SVN trunk source code?  If so, I could add these methods
> for you.
> Best regards,
> --
> ---------------------------------------+--------------------------------------
> I set the clouds in motion - turn up   | Frank Warmerdam,
> warmerdam at pobox.com
> light and sound - activate the windows | http://pobox.com/~warmerdam<http://pobox.com/%7Ewarmerdam>
> and watch the world go round - Rush    | Geospatial Programmer for Rent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20100325/52e2e829/attachment.html

More information about the gdal-dev mailing list