0
for pt in pointLayer.getFeatures():
    for pg in polygonLayer.getFeatures():     
        if pg.geometry().intersects(pt.geometry()):
            intersection = pg.geometry().intersection(pt.geometry())
            intersectionLength = intersection.length()
            intersectionArea = intersection.area()

            fieldIndex = pointLayer.fieldNameIndex(pointLayerColumName)
            print  "LOT Value:: " + str(pt[pointLayerColumName])
            if bool(pt[pointLayerColumName] == None):
                updateValue = pg[polygonLayerColumToUpdate]
                print  " 1 updateValue : " + updateValue
            else:
                updateValue = str(pt[pointLayerColumName]) + ","+ pg[polygonLayerColumToUpdate]
                print  "2 updateValue : " + updateValue

            pointLayer.startEditing()
            pointLayer.changeAttributeValue(pt.id(), fieldIndex, updateValue)
            pointLayer.commitChanges()

I want to update a column but first want to check that if data present in that column then add comma (,) after it and append my new data in their. But the problem is only last (looped) data is appending .

And this line

 if bool(pt[pointLayerColumName] == None):

always return true although I previously update data.

  • empty data contains null. it consider null also data – Muhammad Faizan Khan Oct 10 '16 at 12:26
  • actually the problem is i add new data in the column then again my loop to run to add more data but it didn't considering the last data. what the heck is that? – Muhammad Faizan Khan Oct 10 '16 at 12:29
  • Why are you casting to bool in this statement, if bool(pt[pointLayerColumName] == None):? – artwork21 Oct 11 '16 at 11:36
  • @artwork21 just for checking that it is true or false. actually the problem is it only updating the last value although changeattributeValue runs for each value update. it only appending the last value . why – Muhammad Faizan Khan Oct 13 '16 at 4:34
  • You may want to change that if statement too: if not pt[pointLayerColumName]: – artwork21 Oct 13 '16 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.