[Qgis-user] getFeatures() and fields()
Roberto Herrero
apabardexu at gmail.com
Mon Oct 29 13:39:11 PDT 2018
getFeatures() and fields() do not seem to work in Qgis3.2
I'm running the following pyqgis script:
=========================================
#!/usr/bin/python
# -*- coding: utf8 -*-
import qgis.core
# Open vector layer
LayerName = u'Vector_layer.shp'
VectorLayer = qgis.core.QgsVectorLayer(LayerName, 'mylayer', 'ogr')
# Get the list of features
featureList = []
for feature in VectorLayer.getFeatures():
featureList.append(feature)
print("Feature list size = " + str(len(featureList)))
# Make a list with the field names
fieldList = VectorLayer.fields()
print("Field list size = " + str(len(fieldList)))
for field in VectorLayer.fields():
print(field.name(), field.typeName())
================================================
Both the features and the field list have zero size. However, when loaded
manually, the vector layer contains fields and features.
Any idea?
Thank you very much,
Roberto Herrero
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20181029/58be7d2a/attachment.html>
More information about the Qgis-user
mailing list