That would be awesome, Frank. forceToMultiPolygon was exactly the function I was looking for (and wondering why it wasn' there).<br><br>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?<br>
<br>Thanks again for your help. I'm a big fan of the OGR tools. <br><br>Best,<br>Daniel<br><br><br><br><div class="gmail_quote">On Wed, Mar 24, 2010 at 8:07 PM, Frank Warmerdam <span dir="ltr"><<a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>danotchki wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello List,<br>
<br>
I hope you will be able to help me. I'm stuck on a problem.<br>
I'm trying to reconstruct within my Python script polygons from a shapefile that belong together.<br>
<br>
So I naturally perfomed:<br>
<br>
geom_tmp = ogr.CreateGeometryFromWkb(ftr.GetGeometryRef().ExportToWkb())<br>
geom.AddGeometryDirectly(geom_tmp)<br>
<br>
However this works only when the geometry to add is of type POLYGON. This _doesn't_ work with type MULTIPOLYGON (exit code 3).<br>
</blockquote>
<br></div>
Daniel,<br>
<br>
What type is "geom"? If it is a MULTIPOLYGON then it can only<br>
have polygons as children, not multipolygons.<div><br>
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
My question: is there a way to add MULTIPOLYGONs to an existing Geometry?<br>
<br>
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?<br>
</blockquote>
<br></div>
In C/C++ there are methods on OGRGeometryFactory like<br>
forceToPolygon and forceToMultiPolygon that might be helpful<br>
but I see these are not exposed in Python. Are you willing to<br>
build from SVN trunk source code? If so, I could add these methods<br>
for you.<div><div></div><div><br>
<br>
Best regards,<br>
-- <br>
---------------------------------------+--------------------------------------<br>
I set the clouds in motion - turn up | Frank Warmerdam, <a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a><br>
light and sound - activate the windows | <a href="http://pobox.com/%7Ewarmerdam" target="_blank">http://pobox.com/~warmerdam</a><br>
and watch the world go round - Rush | Geospatial Programmer for Rent<br>
<br>
</div></div></blockquote></div><br>