Explosion des other_tags et mise à jour des styles

This commit is contained in:
Jacky Volpes 2021-02-28 12:09:41 +01:00
parent c52ddb0bb3
commit 3093f80066
4 changed files with 3878 additions and 2205 deletions

View File

@ -10,6 +10,7 @@ import tempfile
from pathlib import Path
from processing.tools import dataobjects
def main():
# Paramètres du projet
@ -24,6 +25,8 @@ def main():
options = QgsVectorFileWriter.SaveVectorOptions()
options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteFile
options.driverName = "GPKG"
context = dataobjects.createContext()
context.setInvalidGeometryCheck(QgsFeatureRequest.GeometryNoCheck)
# Correspondances des noms des couches et des styles:
# "NOM_DE_LA_COUCHE_OSM": ("nom_du_style", "nom_du_layer")
@ -78,11 +81,14 @@ def main():
for osm_name, style_layer_names in names.items():
style_name, layer_name = style_layer_names
# On explose les champs
layer = processing.run("native:explodehstorefield", parameters={"INPUT": layers[osm_name], "FIELD": "other_tags", "OUTPUT": "memory:"}, context=context)["OUTPUT"]
# On enregistre le layer dans le gpkg
options.layerName = layer_name
code, error = QgsVectorFileWriter.writeAsVectorFormat(layers[osm_name], str(workDir / "data.gpkg"), options)
code, error = QgsVectorFileWriter.writeAsVectorFormat(layer, str(workDir / "data.gpkg"), options)
if code != 0:
QMessageBox.warning(None, 'Erreur', f"Erreur à l'export de la couche {layer.name()} : \n\n{error}")
QMessageBox.warning(None, 'Erreur', f"Erreur à l'export de la couche {layer_name} : \n\n{error}")
return
new_layer = QgsVectorLayer(str(workDir / f"data.gpkg|layername={layer_name}"), layer_name)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff