[gdal-dev] multipolygon to polygon

Paolo Corti pcorti at gmail.com
Thu Feb 24 09:10:44 EST 2011


On Thu, Feb 24, 2011 at 2:43 PM, Mohammed Rashad <mohammedrashadkm at gmail.com
> wrote:

> How to convert mutipolygon to polygon
>
> my code
> string geometry = "MULTIPOLYGON (((76.742484035494002
> 9.949536084104899,76.783465713734998 9.8207365239198,76.818592866512006
> 9.8773302700617,76.842010968363994 9.931972507716001,76.742484035494002
> 9.949536084104899)))";
>
>     char *geom = (char *) geometry.c_str();
>
>  OGRGeometry *OLGeometry = NULL;
>
>
>  OGRGeometryFactory::createFromWkt( &geom, NULL, &OLGeometry );
>
> the OLGeometry is multipolygon I need it as polygon as given below.
>
> Note: both are not equal
>
> POLYGON ((76.334618761574006 10.378867951388999,76.338521778548994
> 10.419849629630001,76.404873067129998 10.349595324074,76.371697422840001
> 10.271534984568,76.334618761574006 10.378867951388999))
>
>
>
This is Python code, but you can easily convert it to C:

multipoly_geom = ogr.CreateGeometryFromWkt('MULTIPOLYGON
(((76.742484035494002 9.949536084104899,76.783465713734998
9.8207365239198,76.818592866512006 9.8773302700617,76.842010968363994
9.931972507716001,76.742484035494002 9.949536084104899)))')
for geom_part in multipoly_geom:
    print geom_part.ExportToWkt()

POLYGON ((76.742484035494002 9.949536084104899,76.783465713734998
9.8207365239198,76.818592866512006 9.8773302700617,76.842010968363994
9.931972507716001,76.742484035494002 9.949536084104899))

also give a look at this previous discussion:
http://www.mail-archive.com/gdal-dev@lists.osgeo.org/msg09285.html

best regards
P

-- 
Paolo Corti
Geospatial software developer
web: http://www.paolocorti.net
twitter: @paolo_corti
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110224/611609e6/attachment.html


More information about the gdal-dev mailing list