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
_______________________________________________
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

Reply via email to