Re: [Qgis-user] getFeatures() and fields()
You are right, Nyall. The problem was the path of the vector layer. Thank you, Roberto El lun., 29 oct. 2018 a las 23:54, Nyall Dawson () escribió: > On Tue, 30 Oct 2018 at 06:39, Roberto Herrero > 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 > ___ 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
Re: [Qgis-user] getFeatures() and fields()
On Tue, 30 Oct 2018 at 06:39, Roberto Herrero 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 ___ 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] getFeatures() and fields()
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