simplipy icon indicating copy to clipboard operation
simplipy copied to clipboard

AttributeError: 'QgsRasterLayer' object has no attribute 'pendingFields

Open rahul6612 opened this issue 6 years ago • 0 comments

Remember Python Version 3.6.2 QGIS Version 3.2

while running my code i am getting this error:

` fields = selectedLayer.pendingFields() AttributeError: 'QgsRasterLayer' object has no attribute 'pendingFields'

if i am using fields() instead of pendingFields() because of qgis version 3x getting this error: fields = selectedLayer.fields() AttributeError: 'QgsRasterLayer' object has no attribute 'fields here is my code: `

       filename = self.dlg.lineEdit.text()
        output_file = open(filename, 'w')

        selectedLayerIndex = self.dlg.comboBox.currentIndex()
        selectedLayer = layers[selectedLayerIndex]
        fields = selectedLayer.pendingFields()
        fieldnames = [field.name() for field in fields]

        for f in selectedLayer.getFeatures():
            line = ','.join(unicode(f[x]) for x in fieldnames) + '\n'
            unicode_line = line.encode('utf-8')
            output_file.write(unicode_line)
        output_file.close() 

`

rahul6612 avatar Dec 19 '18 20:12 rahul6612