diff --git a/examples/create_layers.yaml b/examples/create_layers.yaml index e32b4a4..d52c376 100644 --- a/examples/create_layers.yaml +++ b/examples/create_layers.yaml @@ -40,6 +40,9 @@ common_items: # cache_age_max: 86400 # Set projection policy for the layer projection_policy: FORCE_DECLARED + # bounding boxes as [minx, miny, maxx, maxy, srs] + # latlon_bbox: [15.3, 42.7, 57.1, 70.8, "EPSG:4326"] + # native_bbox: [-208000, 1072000, 6390000, 7926000, "EPSG:3067"] # Set the default and additional styles to the layer. The styles should already exist style: diff --git a/georest/__init__.py b/georest/__init__.py index e76fbc8..983227c 100644 --- a/georest/__init__.py +++ b/georest/__init__.py @@ -18,7 +18,7 @@ requests = None import trollsift from geoserver.catalog import Catalog, FailedRequestError -from geoserver.support import DimensionInfo, write_string +from geoserver.support import DimensionInfo, write_string, write_bbox from georest import utils @@ -127,6 +127,16 @@ def add_layer_metadata(cat, workspace, layer_name, dimensions, meta, style=None) coverage = _add_cache_age_max(coverage, meta.get("cache_age_max", None)) coverage = _add_projection_policy(coverage, meta.get("projection_policy", None)) + # Add bounding boxes + coverage = _add_latlon_bbox(coverage, meta.get("latlon_bbox", None)) + coverage = _add_native_bbox(coverage, meta.get("native_bbox", None)) + + # It seems that changing the native bbox somehow triggers the calculation + # of latlon bbox, so if both are specified we need to save twice + # to actually store both values + if "latlon_bbox" in meta and "native_bbox" in meta: + cat.save(coverage) + # Save the added metadata cat.save(coverage) @@ -232,6 +242,20 @@ def _add_projection_policy(coverage, projection_policy): return coverage +def _add_latlon_bbox(coverage, latlon_bbox): + if latlon_bbox is None: + return coverage + coverage.latlon_bbox = latlon_bbox + return coverage + + +def _add_native_bbox(coverage, native_bbox): + if native_bbox is None: + return coverage + coverage.native_bbox = native_bbox + return coverage + + def create_s3_layers(config): """Create all configured layers for S3 based imagery.""" for layer_config in config["layers"]: diff --git a/georest/tests/test_geoserver.py b/georest/tests/test_geoserver.py index 7540e0e..4e07e81 100644 --- a/georest/tests/test_geoserver.py +++ b/georest/tests/test_geoserver.py @@ -86,7 +86,12 @@ def _create_extra_files(tempdir, files): CREATE_LAYERS_CONFIG = { "host": "host", "workspace": "workspace", - "common_items": {"cache_age_max": 86400, "projection_policy": "FORCE_DECLARED"}, + "common_items": { + "cache_age_max": 86400, + "projection_policy": "FORCE_DECLARED", + "latlon_bbox": [10, 15, 20, 25, "EPSG:4326"], + "native_bbox": [1000, 1500, 2000, 2500, "EPSG:3067"], + }, "properties": {"foo": {"bar": "baz"}}, "dimensions": { "time_dimension": {