diff --git a/services_scripts/add_new_field.py b/services_scripts/add_new_field.py new file mode 100644 index 0000000..50209ec --- /dev/null +++ b/services_scripts/add_new_field.py @@ -0,0 +1,14 @@ +from qgis.core import QgsField, QgsVectorLayer, QgsVectorDataProvider +from qgis.PyQt.QtCore import QVariant + +# Step 1 : Adding the Area field +layer = QgsVectorLayer( + 'C:/Users/a_adli/PycharmProjects/' + 'hydroquebec_archetype_gispy/data/' + 'output_data/multi_to_single/multi_to_single.shp', "your_layer", "ogr") +functionalities = layer.dataProvider().capabilities() + +if functionalities & QgsVectorDataProvider.AddAttributes: + new_field = QgsField("Area", QVariant.Double) # Using QVariant.Double for area + layer.dataProvider().addAttributes([new_field]) + layer.updateFields()