1

I tried to modify the code given in https://gis.stackexchange.com/a/212762/7849 so the value from [field_name] would be divided by the length of the feature. I tried to change the last line in

return sum( f[field_name]/f.geometry().length() for f in features if geometry.contains(f.geometry()) )

But I get an error: 'builtin_function_or_method' object has no attribute 'length'

6
  • Could it be f.geometry().length without the end parentheses?
    – Midavalo
    Mar 23, 2017 at 14:58
  • @Midavalo Then i get following error unsupported operand type(s) for /: 'float' and 'builtin_function_or_method'
    – PieterB
    Mar 23, 2017 at 15:00
  • 1
    What version are you using. The length method says it was added at 1.5 which I think is referring to QGIS 1.5. If you are using something newer than 1.5 are you sure that you didn't change anything else in the code? Because I don't see how you would be getting that message unless features is not a QgsFeatureIterator.
    – TJR
    Mar 23, 2017 at 15:34
  • @TJRockefeller I'm using QGIS 2.18.3
    – PieterB
    Mar 23, 2017 at 15:39
  • 2
    I'm using 2.18.3 as well, and testing this in the python console it was working for me. You might try running the code line by line in the python console so you can verify that all the variables are the correct types. just type in any variable you are curious about and it will print out what type of object it is like <qgis._core.QgsFeatureIterator object at 0x000000000F5CC598>
    – TJR
    Mar 23, 2017 at 15:47

0

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.