diff --git a/qsa-api/qsa_api/api/projects.py b/qsa-api/qsa_api/api/projects.py index 2718cd8..2e302fa 100644 --- a/qsa-api/qsa_api/api/projects.py +++ b/qsa-api/qsa_api/api/projects.py @@ -298,12 +298,19 @@ def project_add_layer(name): datetime = None if "datetime" in data: # check format "yyyy-MM-dd HH:mm:ss" - datetime = QDateTime.fromString(data["datetime"], "yyyy-MM-dd HH:mm:ss") + datetime = QDateTime.fromString( + data["datetime"], "yyyy-MM-dd HH:mm:ss" + ) if not datetime.isValid(): return {"error": "Invalid datetime"}, 415 rc, err = project.add_layer( - data["datasource"], data["type"], data["name"], crs, overview, datetime + data["datasource"], + data["type"], + data["name"], + crs, + overview, + datetime, ) if rc: return jsonify(rc), 201 diff --git a/qsa-api/qsa_api/api/symbology.py b/qsa-api/qsa_api/api/symbology.py index 419d29c..76d2786 100644 --- a/qsa-api/qsa_api/api/symbology.py +++ b/qsa-api/qsa_api/api/symbology.py @@ -85,10 +85,10 @@ def symbology_raster_singlebandpseudocolor(): props = {} props["band"] = {"band": 1, "min": 0.0, "max": 1.0} props["ramp"] = { - "name" : f"Spectral ({ramps})", - "color1": "0,0,0,255", - "color2": "255,255,255,255", - "interpolation": "Linear (Linear, Discrete, Exact)" + "name": f"Spectral ({ramps})", + "color1": "0,0,0,255", + "color2": "255,255,255,255", + "interpolation": "Linear (Linear, Discrete, Exact)", } props["contrast_enhancement"] = { "limits_min_max": "MinMax (MinMax, UserDefined)", diff --git a/qsa-api/qsa_api/app.py b/qsa-api/qsa_api/app.py index 9d85b24..4df2563 100644 --- a/qsa-api/qsa_api/app.py +++ b/qsa-api/qsa_api/app.py @@ -34,6 +34,7 @@ def __init__(self) -> None: def run(self): app.run(host="0.0.0.0", threaded=False) + qsa = QSA() diff --git a/qsa-api/qsa_api/mapproxy/mapproxy.py b/qsa-api/qsa_api/mapproxy/mapproxy.py index 5ac7dec..c916533 100644 --- a/qsa-api/qsa_api/mapproxy/mapproxy.py +++ b/qsa-api/qsa_api/mapproxy/mapproxy.py @@ -52,7 +52,12 @@ def clear_cache(self, layer_name: str) -> None: shutil.rmtree(d) def add_layer( - self, name: str, bbox: list, srs: int, is_raster: bool, datetime: QDateTime | None + self, + name: str, + bbox: list, + srs: int, + is_raster: bool, + datetime: QDateTime | None, ) -> (bool, str): if self.cfg is None: return False, "Invalid MapProxy configuration" @@ -65,7 +70,9 @@ def add_layer( lyr = {"name": name, "title": name, "sources": [f"{name}_cache"]} if datetime and is_raster: lyr["dimensions"] = {} - lyr["dimensions"]["time"] = {"values": [datetime.toString(Qt.ISODate)]} + lyr["dimensions"]["time"] = { + "values": [datetime.toString(Qt.ISODate)] + } self.cfg["layers"].append(lyr) @@ -86,7 +93,7 @@ def add_layer( "coverage": {"bbox": bbox, "srs": f"EPSG:{srs}"}, } if datetime and is_raster: - s["forward_req_params"] = ['TIME'] + s["forward_req_params"] = ["TIME"] self.cfg["sources"][f"{name}_wms"] = s diff --git a/qsa-api/qsa_api/project.py b/qsa-api/qsa_api/project.py index abe893c..40ce332 100644 --- a/qsa-api/qsa_api/project.py +++ b/qsa-api/qsa_api/project.py @@ -323,7 +323,7 @@ def add_layer( name: str, epsg_code: int, overview: bool, - datetime: QDateTime | None + datetime: QDateTime | None, ) -> (bool, str): t = self._layer_type(layer_type) if t is None: diff --git a/qsa-api/qsa_api/raster/renderer.py b/qsa-api/qsa_api/raster/renderer.py index 6f4cbc2..2e66bef 100644 --- a/qsa-api/qsa_api/raster/renderer.py +++ b/qsa-api/qsa_api/raster/renderer.py @@ -25,7 +25,9 @@ class RasterSymbologyRenderer: class Type(Enum): SINGLE_BAND_GRAY = QgsSingleBandGrayRenderer(None, 1).type() - SINGLE_BAND_PSEUDOCOLOR = QgsSingleBandPseudoColorRenderer(None, 1).type() + SINGLE_BAND_PSEUDOCOLOR = QgsSingleBandPseudoColorRenderer( + None, 1 + ).type() MULTI_BAND_COLOR = QgsMultiBandColorRenderer(None, 1, 1, 1).type() def __init__(self, name: str) -> None: @@ -46,7 +48,9 @@ def __init__(self, name: str) -> None: self.renderer = QgsSingleBandGrayRenderer(None, 1) elif name == RasterSymbologyRenderer.Type.MULTI_BAND_COLOR.value: self.renderer = QgsMultiBandColorRenderer(None, 1, 1, 1) - elif name == RasterSymbologyRenderer.Type.SINGLE_BAND_PSEUDOCOLOR.value: + elif ( + name == RasterSymbologyRenderer.Type.SINGLE_BAND_PSEUDOCOLOR.value + ): self.renderer = QgsSingleBandPseudoColorRenderer(None, 1) @property @@ -127,7 +131,10 @@ def style_to_json(path: Path) -> (dict, str): props = RasterSymbologyRenderer._multibandcolor_properties( renderer ) - elif renderer_type == RasterSymbologyRenderer.Type.SINGLE_BAND_PSEUDOCOLOR: + elif ( + renderer_type + == RasterSymbologyRenderer.Type.SINGLE_BAND_PSEUDOCOLOR + ): props = RasterSymbologyRenderer._singlebandpseudocolor_properties( renderer ) @@ -253,8 +260,12 @@ def _singlebandpseudocolor_properties(renderer) -> dict: props["ramp"] = {} shader_fct = renderer.shader().rasterShaderFunction() - color_1 = shader_fct.sourceColorRamp().properties()["color1"].split("rgb")[0] - color_2 = shader_fct.sourceColorRamp().properties()["color2"].split("rgb")[0] + color_1 = ( + shader_fct.sourceColorRamp().properties()["color1"].split("rgb")[0] + ) + color_2 = ( + shader_fct.sourceColorRamp().properties()["color2"].split("rgb")[0] + ) props["ramp"]["color1"] = color_1 props["ramp"]["color2"] = color_2 @@ -294,21 +305,30 @@ def _refresh_min_max_multibandcolor(self, layer: QgsRasterLayer) -> None: if min_max_origin == QgsRasterMinMaxOrigin.Limits.MinMax: red_band = renderer.redBand() red_stats = layer.dataProvider().bandStatistics( - red_band, QgsRasterBandStats.Min | QgsRasterBandStats.Max, layer.extent(), 250000 + red_band, + QgsRasterBandStats.Min | QgsRasterBandStats.Max, + layer.extent(), + 250000, ) red_ce.setMinimumValue(red_stats.minimumValue) red_ce.setMaximumValue(red_stats.maximumValue) green_band = renderer.greenBand() green_stats = layer.dataProvider().bandStatistics( - green_band, QgsRasterBandStats.Min | QgsRasterBandStats.Max, layer.extent(), 250000 + green_band, + QgsRasterBandStats.Min | QgsRasterBandStats.Max, + layer.extent(), + 250000, ) green_ce.setMinimumValue(green_stats.minimumValue) green_ce.setMaximumValue(green_stats.maximumValue) blue_band = renderer.blueBand() blue_stats = layer.dataProvider().bandStatistics( - blue_band, QgsRasterBandStats.Min | QgsRasterBandStats.Max, layer.extent(), 250000 + blue_band, + QgsRasterBandStats.Min | QgsRasterBandStats.Max, + layer.extent(), + 250000, ) blue_ce.setMinimumValue(blue_stats.minimumValue) blue_ce.setMaximumValue(blue_stats.maximumValue) @@ -333,7 +353,10 @@ def _refresh_min_max_singlebandgray(self, layer: QgsRasterLayer) -> None: if min_max_origin == QgsRasterMinMaxOrigin.Limits.MinMax: # Accuracy : estimate stats = layer.dataProvider().bandStatistics( - 1, QgsRasterBandStats.Min | QgsRasterBandStats.Max, layer.extent(), 250000 + 1, + QgsRasterBandStats.Min | QgsRasterBandStats.Max, + layer.extent(), + 250000, ) ce.setMinimumValue(stats.minimumValue) @@ -341,13 +364,18 @@ def _refresh_min_max_singlebandgray(self, layer: QgsRasterLayer) -> None: layer.renderer().setContrastEnhancement(ce) - def _refresh_min_max_singlebandpseudocolor(self, layer: QgsRasterLayer) -> None: + def _refresh_min_max_singlebandpseudocolor( + self, layer: QgsRasterLayer + ) -> None: # compute min/max min_max_origin = layer.renderer().minMaxOrigin().limits() if min_max_origin == QgsRasterMinMaxOrigin.Limits.MinMax: # Accuracy : estimate stats = layer.dataProvider().bandStatistics( - 1, QgsRasterBandStats.Min | QgsRasterBandStats.Max, layer.extent(), 250000 + 1, + QgsRasterBandStats.Min | QgsRasterBandStats.Max, + layer.extent(), + 250000, ) layer.renderer().setClassificationMin(stats.minimumValue)