Skip to content

Commit

Permalink
Add latlon & native bounding boxes to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ritvje authored and RadAdm committed May 14, 2024
1 parent 33786f4 commit f7c17ed
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions examples/create_layers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 25 additions & 1 deletion georest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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"]:
Expand Down
7 changes: 6 additions & 1 deletion georest/tests/test_geoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit f7c17ed

Please sign in to comment.