On 20 October 2017 at 18:30, Luigi Pirelli <lui...@gmail.com> wrote: > probably the problem is the facto that you use: > https://qgis.org/api/2.18/classQgsFeature.html#ab0a934a1b173ce5ad8d13363c20ef3c8 > without cloning geometry... and then you remove the layer => the > geometry pointer is no more valid. > > try to do > geom = QgsGeometry( feature.geometry() ) > or better > geom = QgsGeometry( feature.constGeometry() )
Just for future reference - this applies to 2.x only. In 3.0 it's safe to use the original code and you don't need to make these copies. Nyall > Luigi Pirelli > > ************************************************************************************************** > * Boundless QGIS Support/Development: lpirelli AT boundlessgeo DOT com > * LinkedIn: https://www.linkedin.com/in/luigipirelli > * Stackexchange: http://gis.stackexchange.com/users/19667/luigi-pirelli > * GitHub: https://github.com/luipir > * Mastering QGIS 2nd Edition: > * > https://www.packtpub.com/big-data-and-business-intelligence/mastering-qgis-second-edition > ************************************************************************************************** > > > On 20 October 2017 at 10:08, Reginald <reginald.carl...@ingelmunster.be> > wrote: >> Hi, >> >> I am trying to make a report by using a script. >> The script looks as follows: >> >> from qgis.PyQt.QtCore import * >> from qgis.PyQt.QtGui import * >> from qgis.PyQt.QtWidgets import * >> import processing >> # selectiepolygoon layer contains one multipolygone >> layer=None >> for lyr in QgsMapLayerRegistry.instance().mapLayers().values(): >> if lyr.name() == "selectiepolygoon": >> layer = lyr >> break >> >> # Get the first feature from the layer >> feature = layer.getFeatures().next() >> # fetch geometry >> geom = feature.geometry() >> # remove selectiepolygoon from legend >> my_id = layer.id() >> QgsMapLayerRegistry.instance().removeMapLayers(my_id) >> >> layers = iface.legendInterface().layers() >> >> for layer in layers: >> layerType = layer.type() >> if layerType == QgsMapLayer.VectorLayer: >> for feature in layer.getFeatures(): >> if feature.geometry().intersects(geom): >> attr =feature.attributes() >> for att in attr: >> print (att.value) >> >> When I run this script in my project it terminates with a minidump. >> I suspect that the geom is empty at some point? >> Any idea what is wrong with this script? >> >> Regards, >> >> >> >> -- >> Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html >> _______________________________________________ >> Qgis-user mailing list >> Qgis-user@lists.osgeo.org >> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user >> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user > _______________________________________________ > Qgis-user mailing list > Qgis-user@lists.osgeo.org > List info: https://lists.osgeo.org/mailman/listinfo/qgis-user > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user _______________________________________________ Qgis-user mailing list Qgis-user@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user