[Qgis-developer] Learning the new Python API, problem with combine

gene martin.laloux at gmail.com
Sat Mar 30 10:03:37 PDT 2013


Hi,

I am trying to learn the new Python API (calling dir(variable) to understand
the differences) and i have a problem with combine (union) geometries in the
Python console
With the old API, I use

    geoms = []
    for elem in layer.selectedFeatures():
        geom = elem.geometry() 
        geoms.append(geom) 

   union_geom = geom # starting with the last geometry in layer
   for geometry in geoms:
         union_geom = union_geom.combine(geometry)

For of a polyline layer, the result is a MultiLineString, for example

but this causes a  crash with the new Python API (Mac OS X master version)

No problem if I use Shapely (also based on geos, more direct with the union
function)

   from shapely.wkb import loads
   from shapely.geometry import *
   union_geom = LineString() # empty shapely LineString, it is a Polyline
layer here
   for elem in layer.selectedFeatures():
       wkb = loads(elem.geometry().asWkb()) # conversion to shapely geometry
       union_geom = union_geom.union(wkb)

Thanks




--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Learning-the-new-Python-API-problem-with-combine-tp5043806.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list