From 640af05644341e1f962627577ebd5cbb9d3d2138 Mon Sep 17 00:00:00 2001 From: Blottiere Paul Date: Mon, 23 Sep 2024 11:58:37 +0200 Subject: [PATCH] Add data type and band counts metadata for raster layers --- docs/src/sandbox/raster/layers.md | 18 ++++++++++++++++++ qsa-api/qsa_api/project.py | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/docs/src/sandbox/raster/layers.md b/docs/src/sandbox/raster/layers.md index d93f753a..79c0bb07 100644 --- a/docs/src/sandbox/raster/layers.md +++ b/docs/src/sandbox/raster/layers.md @@ -23,8 +23,26 @@ true ### List layers and get metadata ```` shell +# list layers $ curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" ["polygons","dem"] + +# get metadata +$ curl "http://localhost:5000/api/projects/my_project/layers/dem?schema=my_schema" +{ + "bands": 1, + "bbox": "18.6662979442000001 45.77670143760000343, 18.70359794419999844 45.81170143760000002", + "crs": "EPSG:4326", + "current_style": "default", + "data_type": "float32", + "name": "dem", + "source": "/dem.tif", + "styles": [ + "default" + ], + "type": "raster", + "valid": true +} ```` diff --git a/qsa-api/qsa_api/project.py b/qsa-api/qsa_api/project.py index 9179b852..6e36c30f 100644 --- a/qsa-api/qsa_api/project.py +++ b/qsa-api/qsa_api/project.py @@ -218,6 +218,9 @@ def layer(self, name: str) -> dict: if layer.type() == Qgis.LayerType.Vector: infos["geometry"] = QgsWkbTypes.displayString(layer.wkbType()) + elif layer.type() == Qgis.LayerType.Raster: + infos["bands"] = layer.bandCount() + infos["data_type"] = layer.dataProvider().dataType(1).name.lower() infos["source"] = layer.source() infos["crs"] = layer.crs().authid() @@ -320,6 +323,10 @@ def exists(self) -> bool: ) projects = storage.listProjects(uri) + # necessary step if the project has been created without QSA + if self.name in projects: + self._qgis_projects_dir().mkdir(parents=True, exist_ok=True) + return self.name in projects and self._qgis_projects_dir().exists() def create(self, author: str) -> (bool, str):