Skip to main content
deleted 55 characters in body; edited tags; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Editing an attribute using PythonPyQGIS

I'm trying to automate a simple repetitive task on QGIS. I have some shapefiles with varying number of features in a layer and about 10 different attributes for each feature. I need to add the same string value ("negative") to one of these attributes, over and over again. Copy, paste works but since I want to sharpen my Python scripting skills I'd like to achieve this by creating a simple Python script.

I'm able to print values of attributes using something like this;

layer = iface.activeLayer()

for feature in layer.getFeatures():

    print("{acreage} acres in {name}".format(name=feature['fieldname'],acreage=feature['acreage']))

But I'm stuck at this point. How would I write "negative" to the attribute "acreage"? I tried set.Feature() but it just didn't work. I'd appreciate any help about this, thanks in advance.

Editing an attribute using Python

I'm trying to automate a simple repetitive task on QGIS. I have some shapefiles with varying number of features in a layer and about 10 different attributes for each feature. I need to add the same string value ("negative") to one of these attributes, over and over again. Copy, paste works but since I want to sharpen my Python scripting skills I'd like to achieve this by creating a simple Python script.

I'm able to print values of attributes using something like this;

layer = iface.activeLayer()

for feature in layer.getFeatures():

    print("{acreage} acres in {name}".format(name=feature['fieldname'],acreage=feature['acreage']))

But I'm stuck at this point. How would I write "negative" to the attribute "acreage"? I tried set.Feature() but it just didn't work. I'd appreciate any help about this, thanks in advance.

Editing attribute using PyQGIS

I'm trying to automate a simple repetitive task on QGIS. I have some shapefiles with varying number of features in a layer and about 10 different attributes for each feature. I need to add the same string value ("negative") to one of these attributes, over and over again. Copy, paste works but since I want to sharpen my Python scripting skills I'd like to achieve this by creating a simple Python script.

I'm able to print values of attributes using something like this;

layer = iface.activeLayer()

for feature in layer.getFeatures():

    print("{acreage} acres in {name}".format(name=feature['fieldname'],acreage=feature['acreage']))

But I'm stuck at this point. How would I write "negative" to the attribute "acreage"? I tried set.Feature() but it just didn't work.

Source Link
puredata
  • 511
  • 2
  • 14

Editing an attribute using Python

I'm trying to automate a simple repetitive task on QGIS. I have some shapefiles with varying number of features in a layer and about 10 different attributes for each feature. I need to add the same string value ("negative") to one of these attributes, over and over again. Copy, paste works but since I want to sharpen my Python scripting skills I'd like to achieve this by creating a simple Python script.

I'm able to print values of attributes using something like this;

layer = iface.activeLayer()

for feature in layer.getFeatures():

    print("{acreage} acres in {name}".format(name=feature['fieldname'],acreage=feature['acreage']))

But I'm stuck at this point. How would I write "negative" to the attribute "acreage"? I tried set.Feature() but it just didn't work. I'd appreciate any help about this, thanks in advance.