Hi Dominik On Mon, Oct 29, 2012 at 12:26 PM, Dominik Fröhlich <[email protected]> wrote: > Der QGIS developers, > > I'm trying to write a python plugin to reate input data for one of our > models. It basicly converts three shape files with special fields to a text > file. > > I have a buildings vector (polygon) layer containing three polygons (which I > created for testing). This layer is called "build" in the code. To extract > its geometries, I wrote a little function: > > def extract_poly_geometry(self, layer): > feature = QgsFeature() > geom_list = [] > while layer.dataProvider().nextFeature(feature): > geom_list.append(feature.geometry()) > return geom_list
The problem in your code is that you are storing QgsGeometry instances which are owned by the QgsFeature instance. So when another feature is stored into your QgsFeature instance (in nextFeature() call) or when feature instance goes out of scope, the geometry instance becomes invalid - you still have a python object, but it contains a dangling pointer, hence the crashes. The solution is to store a copy of the geometry: geom_list.append( QgsGeometry( feature.geometry() ) ) Regards Martin _______________________________________________ Qgis-developer mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/qgis-developer
