Minor fix

This commit is contained in:
Jacky Volpes 2021-02-25 12:00:44 +01:00
parent c29cf02d85
commit a642b9bdaa

View File

@ -76,27 +76,28 @@ def main():
layers = processing.run("quickosm:openosmfile", {"FILE": osmfile}) layers = processing.run("quickosm:openosmfile", {"FILE": osmfile})
for osm_name, style_layer_names in names.items(): for osm_name, style_layer_names in names.items():
style_name, layer_name = style_layer_names
# On enregistre le layer dans le gpkg # On enregistre le layer dans le gpkg
options.layerName = style_layer_names[1] options.layerName = layer_name
code, error = QgsVectorFileWriter.writeAsVectorFormat(layers[osm_name], str(workDir / "data.gpkg"), options) code, error = QgsVectorFileWriter.writeAsVectorFormat(layers[osm_name], str(workDir / "data.gpkg"), options)
if code != 0: 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 return
new_layer = QgsVectorLayer(str(workDir / f"data.gpkg|layername={layer_name}"), layer_name)
# Les layers suivants seront enregistrés dans le gpkg déjà existant # Les layers suivants seront enregistrés dans le gpkg déjà existant
options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer
# On charge le nouveau layer
style_name, layer_name = style_layer_names
new_layer = QgsVectorLayer(str(workDir / f"data.gpkg|layername={layer_name}"), layer_name)
project.addMapLayer(new_layer)
# On charge le style # On charge le style
if style_name is not None: if style_name is not None:
stylefile = str((Path(tempdir.name) / style_name).with_suffix('.qml')) stylefile = str((Path(tempdir.name) / style_name).with_suffix('.qml'))
processing.run("native:filedownloader", {"URL": styles_url + f"/{style_name}.qml", "OUTPUT": stylefile}) processing.run("native:filedownloader", {"URL": styles_url + f"{style_name}.qml", "OUTPUT": stylefile})
new_layer.loadNamedStyle(stylefile) new_layer.loadNamedStyle(stylefile)
# On charge le nouveau layer
project.addMapLayer(new_layer)
try: try:
project.removeMapLayer(project.mapLayersByName("OpenStreetMap")[0]) project.removeMapLayer(project.mapLayersByName("OpenStreetMap")[0])
except IndexError: except IndexError: