I have a series of polygon that was already batch loaded in my QGIS desktop using this code (courtesy of this post):
import os
source_dir = "/data/brent/LUCID/admin_boundaries_clup/sen2agri_all_muni"
for files in os.listdir(source_dir):
if files.endswith(".shp"):
# create vector layer object
vlayer = QgsVectorLayer(source_dir + "/" + files, files, "ogr")
print(files)
# add the layer to the registry
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
The next steps I want to do to each recently added vectors are:
1) Enter into editing mode. (In preparation for number 2)
2) Create new field, field name as "AREA", field type = real, output length = 10, precision = 2.
3) Calculate area using this string (in field calculator): '$area'
4) Save the edits.
Is it possible to insert codes from the example above?
