In a script on PyQGIS, after a for cycle, I obtain a list like:

LIST:, [[[0], 0.035, [0], [0], [0], [0], 0.036, 0.031]])

I need to put that values in the column of Shapefile Attribute Table, but I'm not able to do this, and the result is only a series of 0,000.

Can anyone help me find the error?

Final part of the script:

    for p in int_points:
        valore = prov_raster.identify(
        ang_OBSTd = [0]
        difelev = (valore - valore_iniz)
        if (difelev) >= 200:
            distanza = values.index(valore)*xsize  
            tana = (valore / distanza) 

            ang_OBSTd = np.degrees(np.arctan(np.max(tan_a)))

angle = [LIST]
feat.setAttributes([i, angle, value[idx_lines[i]],direction[k]])


  • 1
    There's a basic script I put together gis.stackexchange.com/questions/138180/… . I don't see where you're updating the feature, are you committing the changes? Commented Nov 22, 2017 at 4:48
  • What do you bean with "committing the change"? I updated the script adding the FOR cycle with ang_OBSTd calculation.
    – Mr Prince
    Commented Nov 22, 2017 at 7:23
  • Have a close look at the linked script. You've changed the attributes and the geometry of the feature but you haven't told QGIS to update the existing geometry A.K.A. 'save' the changes to the feature, then you also need to tell QGIS to update the layer otherwise all your changes are lost. Commented Nov 22, 2017 at 21:10
  • 1
    Yes, to update the feature (the geometry is just a value in the table) you need to call dsslvExplodeLyr.updateFeature(f), assuming your parent layer is dsslvExplodeLyr. The object you're setting fields on is a copy of the feature, held in memory, you have to instruct QGIS to commit the changes to the existing feature and also to the shapefile with dsslvExplodeLyr.commitChanges() to ensure the changes that have been made to the features are saved. There's a double buffer there (layer and feature) which I think has something to do with python representations of C objects. Commented Nov 24, 2017 at 1:36
  • 1
    I see, you're creating the features, not updating existing ones. What field type is angle? Are you sure that difelev (which is valore - valore_iniz) >= 200? Can you insert print('valore {}, diffelev {}'.format(valore,diffelev)) before the if statement then run to ensure that the condition is being met? Are you sure the the point p is in the same spatial reference and falls on prov_raster? Commented Nov 24, 2017 at 2:24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.