6

I have just spent several frustrating hours because I was searching the api docs for stuff on attributes when I should have been looking for fields.

Can someone please explain what the difference or relationship is?

2
  • 4
    I suspect that the terms attributes, fields, columns and items are used more or less interchangeably in desktop GIS.
    – PolyGeo
    Aug 12, 2017 at 2:10
  • Agreed with respect to GIS in general, but one would expect the API to use one term and stick to it when it comes to naming class methods! In fact there is a Field class and separate an Attribute class. Aug 12, 2017 at 5:04

1 Answer 1

2

In Python an attribute defines an object variable, which may be accessible through the dot-notation, like object.attribute. Using a wrong name for an attribute throws a specific exception, AttributeError.

Now pyqgis defines a method called attribute, which takes a name of a field and returns the value of the feature for that field (https://qgis.org/api/classQgsFeature.html#ae5957f3cf812dc7c077ee7f906745ac7). Also it defines QgsAttributes, which is implemented as a Python list of Python objects (https://qgis.org/api/classQgsAttributes.html) and so is a more general class.

So it seems, that an attribute is feature-related and has a name and a value, where a Field defines the logical part of a table, with name, data type and so on. I don't know if this is the way it's ment to be by the autors of the QGIS-API, but in addition to that, the python-API is directly derived from the C++-API, where other naming conventions exist, which then collide with python and QGIS-Terms. So at least consistency is not easy to keep.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.