QgsFeature attributes are instances of a class that allow the user to access and manipulate the individual attributes of a QgsFeature object. These attributes can be any type of data, such as integers, floats, or strings, and can be stored in different fields within the feature.
Code example 1:
QgsFeature feature = layer.getFeature(0); QString value = feature.attribute("Name").toString(); double x = feature.attribute("X").toDouble(); double y = feature.attribute("Y").toDouble();
This code fetches the attributes of a feature from a layer and assigns them to variables. "Name" is a string attribute, and "X" and "Y" are numeric attributes.
Package library: QGIS
Code example 2:
QgsFeature feature = layer.getFeature(1); feature.setAttribute("Name", "New Name"); layer.updateFeature(feature);
This code updates the "Name" attribute of a feature in a layer to a new value. The updateFeature() method is used to commit the changes to the layer.
Package library: QGIS
Code example 3:
QgsFeature feature = layer.getFeature(2); QgsGeometry geometry = feature.geometry(); QgsPointXY point = geometry.asPoint(); double x = point.x(); double y = point.y();
This code retrieves the geometry of a feature from a layer and assigns it to a QgsGeometry object. The asPoint() method is then used to convert the geometry to a QgsPointXY object, and the x() and y() methods are called to retrieve the coordinates of the point.
Package library: QGIS
C++ (Cpp) QgsFeature::attributes - 30 examples found. These are the top rated real world C++ (Cpp) examples of QgsFeature::attributes extracted from open source projects. You can rate examples to help us improve the quality of examples.