On 25 January 2018 at 17:30, Daan Goedkoop <dgoedk...@gmx.net> wrote: > Thank you for the answers! > > Ok, so I don't need to manipulate the QgsMultiLineString directly. Yet > I cannot help to wonder a little bit about this (using a .shp file): > >>>> qgis.utils.iface.activeLayer().selectedFeatures()[0].geometry().asGeometryCollection()[0].asWkt() > 'LineString (4.83090675976269512 52.44278398333691626, > 4.89922802216601205 52.37283112413303598)' >>>> qgis.utils.iface.activeLayer().selectedFeatures()[0].geometry().asWkt() > 'MultiLineString ((4.83090675976269512 52.44278398333691626, > 4.89922802216601205 52.37283112413303598))' >>>> qgis.utils.iface.activeLayer().selectedFeatures()[0].geometry().asGeometryCollection()[0].asWkt() > 'LineString (4.83090675976269512 52.44278398333691626, > 4.89922802216601205 52.37283112413303598)' >>>> type(qgis.utils.iface.activeLayer().selectedFeatures()[0].geometry().constGet()) > <class 'qgis._core.QgsMultiLineString'> >>>> qgis.utils.iface.activeLayer().selectedFeatures()[0].geometry().constGet().wkbType() > 5 >>>> qgis.utils.iface.activeLayer().selectedFeatures()[0].geometry().constGet().numGeometries() > 0 >>>> qgis.utils.iface.activeLayer().selectedFeatures()[0].geometry().constGet().asWkt() > <crash> > > Is this expected behaviour?
I suspect what's happening here is that the feature is being garbage collected early, deleting the geometry and causing the unpredictable behavior - try this: f = qgis.utils.iface.activeLayer().selectedFeatures()[0] f.geometry().constGet()...... etc Nyall _______________________________________________ QGIS-Developer mailing list QGIS-Developer@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer