Skip to content

Commit

Permalink
Add style to every layer based on IGN themes.
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesGrillot committed Jun 11, 2024
1 parent f6f1112 commit d3be06d
Show file tree
Hide file tree
Showing 59 changed files with 16,290 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bd_topo_extractor/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def plugin_metadata_as_dict() -> dict:
__wfs_schema__: str = __plugin_md__.get("wfs").get("schema")
__wfs_crs__: str = __plugin_md__.get("wfs").get("crs")
__wfs_geometry__: str = __plugin_md__.get("wfs").get("geometry")
__wfs_style__: str = __plugin_md__.get("wfs").get("style")
__wfs_layer_order__: str = __plugin_md__.get("wfs").get("layer_order")
__wfs_metadata__: str = __plugin_md__.get("wfs").get("metadata")
__wfs_credit__: str = __plugin_md__.get("wfs").get("producer")
__wfs_logo__: Path = DIR_PLUGIN_ROOT.resolve() / __plugin_md__.get("wfs").get("logo")
Expand Down
6 changes: 5 additions & 1 deletion bd_topo_extractor/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ changelog=
1.0.0 sphinx documentation, add metadata variable for schema, geometry column and crs.
1.0.1 crs correction.
1.0.2 crs correction for area calculation, adding a gif when export is loading
1.1.0 add group by themes and style created by IGN.


[wfs]
plugin_name=BD_TOPO_Extractor
Expand All @@ -35,6 +37,8 @@ uri=https://data.geopf.fr/wfs/ows
schema=BDTOPO_V3
geometry=geometrie
crs=4326
metadata=https://geoservices.ign.fr/bdtopo
style=true
layer_order={"TRANSPORT": {"TRONCON_DE_ROUTE": "0", "ROUTE_NUMEROTEE_OU_NOMMEE": "1", "TRONCON_DE_VOIE_FERREE": "2", "EQUIPEMENT_DE_TRANSPORT": "3", "PISTE_D_AERODROME": "4", "AERODROME": "5", "POINT_DE_REPERE": "6", "NON_COMMUNICATION": "7", "POINT_DU_RESEAU": "8", "TRANSPORT_PAR_CABLE": "9", "VOIE_FERREE_NOMMEE": "10", "TOPONYMIE_TRANSPORT": "11"}, "BATI": {"BATIMENT": "0", "CIMETIERE": "1", "CONSTRUCTION_PONCTUELLE": "2", "CONSTRUCTION_LINEAIRE": "3", "CONSTRUCTION_SURFACIQUE": "4", "RESERVOIR": "5", "LIGNE_OROGRAPHIQUE": "6", "PYLONE": "7", "TERRAIN_DE_SPORT": "8", "TOPONYMIE_BATI": "9"}, "LIEUX_NOMMEES": {"DETAIL_OROGRAPHIQUE": "0", "ZONE_D_HABITATION": "1", "LIEU_DIT_NON_HABITE": "2", "TOPONYMIE_LIEUX_NOMMES": "3"}, "SERVICES_ET_ACTIVITES": {"CANALISATION": "0", "LIGNE_ELECTRIQUE": "1", "POSTE_DE_TRANSFORMATION": "2", "ERP": "3", "ZONE_D_ACTIVITE_OU_D_INTERET": "4", "TOPONYMIE_SERVICES_ET_ACTIVITES": "5"}, "ADMINISTRATIF": {"ARRONDISSEMENT_MUNICIPAL": "0", "COMMUNE": "1", "COMMUNE_ASSOCIEE_OU_DELEGUEE": "2", "ARRONDISSEMENT": "3", "CONDOMINIUM": "4", "DEPARTEMENT": "5", "COLLECTIVITE_TERRITORIALE": "6", "EPCI": "7", "REGION": "8"}, "HYDROGRAPHIE": {"COURS_D_EAU": "0", "TRONCON_HYDROGRAPHIQUE": "1", "SURFACE_HYDROGRAPHIQUE": "2", "PLAN_D_EAU": "3", "DETAIL_HYDROGRAPHIQUE": "4", "LIMITE_TERRE_MER": "5", "NOEUD_HYDROGRAPHIQUE": "6", "BASSIN_VERSANT_TOPOGRAPHIQUE": "7", "TOPONYMIE_HYDROGRAPHIE": "8"}, "ZONES_REGLEMENTEES": {"PARC_OU_RESERVE": "0", "FORET_PUBLIQUE": "1", "TOPONYMIE_ZONES_REGLEMENTEES": "2"}, "OCCUPATION_DU_SOL": {"HAIE": "0", "ZONE_DE_VEGETATION": "1", "ZONE_D_ESTRAN": "2"}, "ORDER": {"TRANSPORT": "0", "BATI": "1", "LIEUX_NOMMEES": "2", "SERVICES_ET_ACTIVITES": "3", "ADMINISTRATIF": "4", "HYDROGRAPHIE": "5", "ZONES_REGLEMENTEES": "6", "OCCUPATION_DU_SOL": "7"}}
metadata=https://geoservices.ign.fr/bd-topor-explorer-descriptif-de-contenu
producer=https://www.ign.fr/
logo=resources/images/logo.png
28 changes: 27 additions & 1 deletion bd_topo_extractor/plugin_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import Path
import datetime
import os.path
import json

# PyQGIS
from qgis.core import (
Expand Down Expand Up @@ -38,6 +39,8 @@
__wfs_uri__,
__wfs_name__,
__uri_tracker__,
__wfs_layer_order__,
__wfs_style__,
)
from bd_topo_extractor.gui.dlg_settings import PlgOptionsFactory

Expand Down Expand Up @@ -324,7 +327,30 @@ def processing(self):
):
self.project.instance().addMapLayer(
request.final_layer, False)
group.addLayer(request.final_layer)
# If styled layer are set to true in metadata.txt, a specific style is applied to every layer.
if __wfs_style__:
# style name is based on layer name in uppercase with underscore instead of spaces and single quotes
style_name = str(request.final_layer.name()).replace("'", "_").replace(" ", "_").upper()
layer_order_dict = json.loads(__wfs_layer_order__)
# the layer are ordered based on a dictionnary with theme as key.
for elem in layer_order_dict:
if style_name in list(layer_order_dict[elem].keys()):
theme = self.project.instance().layerTreeRoot().findGroup(elem)
# if the theme doesn't exists it is created.
if not theme:
group.insertGroup(int(layer_order_dict['ORDER'][elem]), elem)
theme = self.project.instance().layerTreeRoot().findGroup(elem)
theme.addLayer(request.final_layer)
style_name_ext = style_name + ".qml"
style_path: Path = (
DIR_PLUGIN_ROOT / f'{"resources/styles"}' / f'{style_name_ext}')
# if the style exists it is added to the layer.
if os.path.isfile(style_path.__str__()):
request.final_layer.loadNamedStyle(style_path.__str__())
else:
print("ERROR : style " + str(style_name_ext) + " doesn't exists.")
else:
group.addLayer(request.final_layer)

# Increase the ProgressBar value
n = n + 1
Expand Down
Loading

0 comments on commit d3be06d

Please sign in to comment.