[Qgis-user] getFeatures() and fields()

Nyall Dawson nyall.dawson at gmail.com
Mon Oct 29 15:54:35 PDT 2018


On Tue, 30 Oct 2018 at 06:39, Roberto Herrero <apabardexu at gmail.com> wrote:
>
> getFeatures() and fields() do not seem to work in Qgis3.2

They 100% work -- if they didn't, QGIS wouldn't be good for anything
except wasting some space on your computer ;)

> # Open vector layer
> LayerName = u'Vector_layer.shp'
> VectorLayer = qgis.core.QgsVectorLayer(LayerName, 'mylayer', 'ogr')

I suspect this is where the issue sits -- try checking

assert VectorLayer.isValid()

here. My suspicion is that your relative path 'Vector_layer.shp' is
not working, and will need to be an absolute path.

Nyall


More information about the Qgis-user mailing list