I have multiple polygons stored in a list like this :
def drawParcel(self, propriete):
length = len(propriete.name)
i = 0
while i < length:
layer = QgsVectorLayer('Polygon', propriete.name[i], "memory")
allLayers.append(layer)
I have tried this code but i only get in the json file the last element of my list :
uri ="C:/Users/ilyasse2.0/Documents/SQRLAND/ils.json"
context = QgsProject.instance().transformContext()
options = QgsVectorFileWriter.SaveVectorOptions()
options.driverName = "GeoJson"
QgsVectorFileWriter.writeAsVectorFormatV2(allLayers[0],uri,context,options)
#switch mode to append layer instead of overwriting the file
options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer
for layer in allLayers:
QgsVectorFileWriter.writeAsVectorFormatV2(layer,uri,context,options)
How can i create a GeoJSON file with the list of layers ?
options.actionOnExistingFile = QgsVectorFileWriter.AppendToLayerNoNewFields
?