Add a service for adding a new field
This commit is contained in:
parent
5fb2e6fda2
commit
77ea20260f
14
services_scripts/add_new_field.py
Normal file
14
services_scripts/add_new_field.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user