[gdal-dev] ogr.Geometry - UnionCascaded() question
Even Rouault
even.rouault at spatialys.com
Tue Sep 16 11:08:14 PDT 2014
Le mardi 16 septembre 2014 19:43:43, Max Demars a écrit :
> Hi,
>
> I want to do a union on many ogr.Geometry stored in a list, but I have a
> TypeError: unbound method UnionCascaded() must be called with Geometry
> instance as first argument (got list instance instead).
>
> I though UnionCascaded was made to perform Union on many geometries like
> this:
>
> geometries = []
> for feature in featureCollection['features']:
>
> geometries.append(ogr.CreateGeometryFromJson(json.dumps(feature['geometry']
> ))) outputGeometry = ogr.Geometry
> output = outputGeometry.UnionCascaded(geometries)
>
> How am I supposed to use this function if list are not accepted?
Max,
UnionCascaded() takes no argument and operates on a multipolygon geometry :
For example
geom = ogr.CreateGeometryFromWkt('MULTIPOLYGON(((0 0,0 1,1 1,0 0)),((0 0,1 1,1
0,0 0)))')
result = geom.UnionCascaded()
Or you can build it into several steps :
geom = ogr.Geometry(ogr.wkbMultiPolygon)
geom.AddGeometry(ogr.CreateGeometryFromWkt('POLYGON((0 0,0 1,1 1,0 0))'))
geom.AddGeometry(ogr.CreateGeometryFromWkt('POLYGON((0 0,1 1,1 0,0 0))'))
result = geom.UnionCascaded()
Best regards,
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list