Add a service for adding a new field

This commit is contained in:
Alireza Adli 2024-03-12 12:20:56 -04:00
parent 5fb2e6fda2
commit 77ea20260f

View File

@ -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()