diff --git a/geospatial-utils/adjusters/__init__.py b/geospatial-utils/adjusters/__init__.py new file mode 100644 index 0000000..a6f850f --- /dev/null +++ b/geospatial-utils/adjusters/__init__.py @@ -0,0 +1 @@ +from . import foca as foca diff --git a/geospatial-utils/config.py b/geospatial-utils/config.py index 49bf9d4..582afb7 100644 --- a/geospatial-utils/config.py +++ b/geospatial-utils/config.py @@ -1,13 +1,13 @@ from __future__ import annotations -from datetime import datetime - from implicitdict import ImplicitDict, StringBasedDateTime from uas_standards.eurocae_ed318 import TextShortType class ConverterConfiguration(ImplicitDict): + name: str ed318_additions: ED318Additions + adjusters: list[str] class ED318Additions(ImplicitDict): @@ -19,54 +19,3 @@ class ED318Additions(ImplicitDict): otherGeoid: str feature_collection_bbox: list[float] collection_name: str - - -FOCA = ED318Additions( - default_lang="en-GB", - provider=[ - TextShortType(lang="de-CH", text="BAZL"), - TextShortType(lang="fr-CH", text="OFAC"), - TextShortType(lang="it-CH", text="UFAC"), - TextShortType(lang="en-GB", text="FOCA"), - ], - description=[ # TODO: To validate - TextShortType( - lang="de-CH", - text="Schweizerische UAS Geozones, herausgegeben vom Bundesamt für Zivilluftfahrt (BAZL). Umwandlung aus dem Modell ED-269.", - ), - TextShortType( - lang="fr-CH", - text="UAS Geozones suisses publiées par l'Office fédéral de l'aviation civile (OFAC). Conversion à partir du modèle ED-269", - ), - TextShortType( - lang="it-CH", - text="Geozones UAS svizzere emesse dall'Ufficio federale dell'aviazione civile (UFAC). Conversione dal modello ED-269", - ), - TextShortType( - lang="en-GB", - text="Swiss UAS Geozones issued by the Federal Office of Civil Aviation (FOCA). Conversion from the ED-269 model", - ), - ], - technicalLimitation=[ # TODO: To validate - TextShortType( - lang="de-CH", - text="Der Datensatz entsteht durch die Umwandlung der Originaldaten des ED-269-Modells ins neue ED-318. Für die Umwandlung sind einige Datenänderungen nötig. Diese Datei wurde in INTERLIS 2.4 erstellt.", - ), - TextShortType( - lang="fr-CH", - text="Le fichier a été créé en convertissant les données originales du modèle ED-269 dans le nouveau ED-318. La conversion nécessite des modifications des données. Ce fichier a été créé en INTERLIS 2.4", - ), - TextShortType( - lang="it-CH", - text="Il dataset è stato creato convertendo i dati originali del modello ED-269 nel nuovo ED-318. Per la conversione alcune modifiche dei dati sono necessarie. Questo file è stato creato in INTERLIS 2.4", - ), - TextShortType( - lang="en-GB", - text="The dataset was created by converting the original data from the ED-269 model to the new ED-318. Some data modifications are necessary for conversion. This file was created in INTERLIS 2.4", - ), - ], - issued=StringBasedDateTime(datetime.now()), - otherGeoid="CHGeo2004", - collection_name="Swiss UAS Geozones according to ED-318 converted from the ED-269 data model", - feature_collection_bbox=[2485410.215, 1075268.136, 2833857.724, 1295933.698], -) diff --git a/geospatial-utils/configs/FOCA.json b/geospatial-utils/configs/FOCA.json new file mode 100644 index 0000000..fd5173b --- /dev/null +++ b/geospatial-utils/configs/FOCA.json @@ -0,0 +1,72 @@ +{ + "name": "Swiss FOCA", + "adjusters": [ + "foca" + ], + "ed318_additions": { + "default_lang": "en-GB", + "provider": [ + { + "lang": "de-CH", + "text": "BAZL" + }, + { + "lang": "fr-CH", + "text": "OFAC" + }, + { + "lang": "it-CH", + "text": "UFAC" + }, + { + "lang": "en-GB", + "text": "FOCA" + } + ], + "description": [ + { + "lang": "de-CH", + "text": "Schweizerische UAS Geozones, herausgegeben vom Bundesamt f\u00fcr Zivilluftfahrt (BAZL). Umwandlung aus dem Modell ED-269." + }, + { + "lang": "fr-CH", + "text": "UAS Geozones suisses publi\u00e9es par l'Office f\u00e9d\u00e9ral de l'aviation civile (OFAC). Conversion \u00e0 partir du mod\u00e8le ED-269" + }, + { + "lang": "it-CH", + "text": "Geozones UAS svizzere emesse dall'Ufficio federale dell'aviazione civile (UFAC). Conversione dal modello ED-269" + }, + { + "lang": "en-GB", + "text": "Swiss UAS Geozones issued by the Federal Office of Civil Aviation (FOCA). Conversion from the ED-269 model" + } + ], + "technicalLimitation": [ + { + "lang": "de-CH", + "text": "Der Datensatz entsteht durch die Umwandlung der Originaldaten des ED-269-Modells ins neue ED-318. F\u00fcr die Umwandlung sind einige Daten\u00e4nderungen n\u00f6tig. Diese Datei wurde in INTERLIS 2.4 erstellt." + }, + { + "lang": "fr-CH", + "text": "Le fichier a \u00e9t\u00e9 cr\u00e9\u00e9 en convertissant les donn\u00e9es originales du mod\u00e8le ED-269 dans le nouveau ED-318. La conversion n\u00e9cessite des modifications des donn\u00e9es. Ce fichier a \u00e9t\u00e9 cr\u00e9\u00e9 en INTERLIS 2.4" + }, + { + "lang": "it-CH", + "text": "Il dataset \u00e8 stato creato convertendo i dati originali del modello ED-269 nel nuovo ED-318. Per la conversione alcune modifiche dei dati sono necessarie. Questo file \u00e8 stato creato in INTERLIS 2.4" + }, + { + "lang": "en-GB", + "text": "The dataset was created by converting the original data from the ED-269 model to the new ED-318. Some data modifications are necessary for conversion. This file was created in INTERLIS 2.4" + } + ], + "issued": "2025-12-16T14:38:18.121239Z", + "otherGeoid": "CHGeo2004", + "collection_name": "Swiss UAS Geozones according to ED-318 converted from the ED-269 data model", + "feature_collection_bbox": [ + 2485410.215, + 1075268.136, + 2833857.724, + 1295933.698 + ] + } +} diff --git a/geospatial-utils/configs/personal/.gitignore b/geospatial-utils/configs/personal/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/geospatial-utils/configs/personal/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/geospatial-utils/main.py b/geospatial-utils/main.py index a0a0330..0a9a38f 100644 --- a/geospatial-utils/main.py +++ b/geospatial-utils/main.py @@ -4,12 +4,13 @@ import pathlib import sys -import adjusters.foca -import config +import adjusters import convert import fileutils import validate +from config import ConverterConfiguration from fileutils import ed269 +from implicitdict import ImplicitDict from loguru import logger version = os.environ.get("GEOSPATIAL_UTILS_VERSION", "unknown") @@ -37,6 +38,13 @@ def main(): default="0", ) + convert_cmd.add_argument( + "-c", + "--config", + help="Path to the configuration to use.", + default="configs/FOCA.json", + ) + args = parser.parse_args() if args.command == "convert": @@ -46,19 +54,25 @@ def main(): # Load source ed269_data = ed269.loads(source) - # TODO: Move hard-coded configuration to a json file. - logger.warning( - "Additional data not provided in ED269 is hard-coded with Swiss FOCA information. This will be moved to a configurable file in the near future." - ) + + # Load config + with open(args.config) as f: + data = json.load(f) + config = ImplicitDict.parse(data, ConverterConfiguration) + logger.info(f"Using configuration {config.name}") # Conversion - ed318_data = convert.from_ed269_to_ed318(ed269_data, config=config.FOCA) + ed318_data = convert.from_ed269_to_ed318( + ed269_data, config=config.ed318_additions + ) # Adjustments - logger.warning( - "The output is adjusted with Swiss FOCA configuration. The output contains non-conform ConditionExpressionType values." - ) - ed318_data = adjusters.foca.adjust(ed318_data) + for adjuster in config.adjusters: + if not hasattr(adjusters, adjuster): + logger.error(f"Unknown adjuster: {adjuster}") + sys.exit(1) + + ed318_data = getattr(adjusters, adjuster).adjust(ed318_data) # Save to file output = pathlib.Path(args.output_file)