Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/source/publishing/ogcapi-maps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ required. An optional style name can be defined via `options.style`.
- `OGC:CRS84` (unsafe)

If `crs` is not provided, the server will default to the `storage_crs`; in case it does not exist, the default is `CRS84`.
If `crs-bbox` is not provided, it will default to `CRS84`. If the `bbox` is not provided, it will default to `-180, -90, 180, 90`.
If `crs-bbox` is not provided, it will default to `CRS84`. If the `bbox` is not provided, it will default to
the bbox that is configured as the collection's spatial extent.

The response headers will always contain the `Content-Crs` and `Content-Bbox`. Examples:

Expand Down
58 changes: 28 additions & 30 deletions pygeoapi/api/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
'http://www.opengis.net/spec/ogcapi-maps-1/1.0/conf/core'
]

DEFAULT_BBOX = [-180, -90, 180, 90] # CRS84


def get_collection_map(api: API, request: APIRequest,
dataset: str, style: str | None = None
Expand All @@ -86,10 +84,9 @@ def get_collection_map(api: API, request: APIRequest,

LOGGER.debug('Loading provider')
try:
collection_def = get_provider_by_type(
api.config['resources'][dataset]['providers'], 'map')

p = load_plugin('provider', collection_def)
collection_def = api.config['resources'][dataset]
provider_def = get_provider_by_type(collection_def['providers'], 'map')
p = load_plugin('provider', provider_def)
except KeyError:
exception = {
'code': 'InvalidParameterValue',
Expand All @@ -111,8 +108,7 @@ def get_collection_map(api: API, request: APIRequest,
# if it does not exist or is not supported, use CRS84.
try:
if 'crs' not in request.params:
query_args['crs'] = collection_def.get('storage_crs',
DEFAULT_CRS)
query_args['crs'] = provider_def.get('storage_crs', DEFAULT_CRS)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the standard states that the default CRS should be CRS84; see: https://docs.ogc.org/is/20-058/20-058.html#_8bcbded1-5f70-4020-b90a-596fe8b8326b 13.2.1. Parameter bbox-crs -> c

Not really sure how to deal with this, when we default to a bbox that may have any crs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit of the code was not modified by this PR, except for the rename of the variable from collection_def to provider_def - I'm not changing the behavior of the code here, just giving it a clearer meaning.

Also, looking at section 16.2.1 - Parameter CRS, NOTE 1 of the standard, it reads:

When no crs parameters are specified, please refer to the Maps API core conformance class to know about the default CRS.

and the respective core conformance class section 7.2.2 Response, Requirement 2, point B reads:

The map response SHALL be in the storage CRS specified in the description of the geospatial resource (such as the associated collection or dataset), or https://www.opengis.net/def/crs/OGC/1.3/CRS84 if none is specified, unless overridden by a specific query parameter (see Requirements Class “Coordinate Reference System”).

So this part of the code seems to conform to the standard.

The reference you quoted is dealing with the bbox-crs query parameter, which is used for subsetting, and is only relevant when the request includes a bbox query param. I don't think it is applicable to this passage of the code.

else:
query_args['crs'] = get_uri(request.params['crs'])

Expand Down Expand Up @@ -149,20 +145,23 @@ def get_collection_map(api: API, request: APIRequest,

LOGGER.debug('Processing bbox parameter')
try:
bbox = request.params.get(
'bbox').split(',')
if len(bbox) != 4:
exception = {
'code': 'InvalidParameterValue',
'description': 'bbox values should be minx,miny,maxx,maxy'
}
headers['Content-type'] = 'application/json'
LOGGER.error(exception)
return headers, HTTPStatus.BAD_REQUEST, to_json(
exception, api.pretty_print)

bbox = request.params.get('bbox').split(',')
except AttributeError:
bbox = DEFAULT_BBOX
# in the absence of user-supplied bbox, use collection spatial extent
bbox = collection_def['extents']['spatial']['bbox']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake of consistency, I think we should either have a fallback for DEFAULT_BBOX here, or remove the fallback to the DEFAULT_CRS on the next line. I am assuming that either we have both, bbox and bbox-crs, or none.

@ricardogsilva ricardogsilva Oct 29, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two points being made here:

  1. pygeoapi already makes it mandatory for all collections to have a spatial extent and with a mandatory bbox - as per its own configuration format and schema - therefore there is no need to add a fallback DEFAULT_BBOX.

    On the other hand, according to the pygeoapi config schema, the collection config's spatial extent is not required to have the crs property, in which case it is assumed to be CRS84. So this code seems correct to me.

  2. It is possible that a request provides a bbox query param and does not provide bbox-crs, in which case, like you pointed out in your other comment, the standard says, bbox-crs is assumed to be CRS84.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn' t collection_def here also be replaced by provider_def ?

@ricardogsilva ricardogsilva Oct 29, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, because the spatial extent is a property of the collection, not of the provider. That was one of the things which tripped me when looking at this code because the variable was erroneously named.

query_args['bbox-crs'] = collection_def['extents']['spatial'].get(
'crs', DEFAULT_CRS)

if len(bbox) != 4:
exception = {
'code': 'InvalidParameterValue',
'description': 'bbox values should be minx,miny,maxx,maxy'
}
headers['Content-type'] = 'application/json'
LOGGER.error(exception)
return headers, HTTPStatus.BAD_REQUEST, to_json(
exception, api.pretty_print)

try:
bbox = [float(c) for c in bbox]
except ValueError:
Expand Down Expand Up @@ -249,16 +248,16 @@ def get_collection_map(api: API, request: APIRequest,
err.http_status_code, headers, request.format,
err.ogc_exception_code, err.message)

mt = collection_def['format']['name']
mt = provider_def['format']['name']

headers['Content-Crs'] = query_args['crs']
headers['Content-Bbox'] = ','.join(map(str, query_args['bbox']))

if format_ == mt:
headers['Content-Type'] = collection_def['format']['mimetype']
headers['Content-Type'] = provider_def['format']['mimetype']
return headers, HTTPStatus.OK, data
elif format_ in [None, 'html']:
headers['Content-Type'] = collection_def['format']['mimetype']
headers['Content-Type'] = provider_def['format']['mimetype']
return headers, HTTPStatus.OK, data
else:
exception = {
Expand Down Expand Up @@ -289,10 +288,9 @@ def get_collection_map_legend(api: API, request: APIRequest,

LOGGER.debug('Loading provider')
try:
collection_def = get_provider_by_type(
api.config['resources'][dataset]['providers'], 'map')

p = load_plugin('provider', collection_def)
collection_def = api.config['resources'][dataset]
provider_def = get_provider_by_type(collection_def['providers'], 'map')
p = load_plugin('provider', provider_def)
except KeyError:
exception = {
'code': 'InvalidParameterValue',
Expand All @@ -314,10 +312,10 @@ def get_collection_map_legend(api: API, request: APIRequest,
err.http_status_code, headers, request.format,
err.ogc_exception_code, err.message)

mt = collection_def['format']['name']
mt = provider_def['format']['name']

if format_ == mt:
headers['Content-Type'] = collection_def['format']['mimetype']
headers['Content-Type'] = provider_def['format']['mimetype']
return headers, HTTPStatus.OK, data
else:
exception = {
Expand Down
24 changes: 24 additions & 0 deletions tests/api/test_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

from http import HTTPStatus

import pytest

from pygeoapi.api import API
from pygeoapi.api.maps import get_collection_map

from tests.util import mock_api_request
Expand Down Expand Up @@ -104,3 +107,24 @@ def test_map_crs_transform(config, api_):

assert code == HTTPStatus.OK
assert floridaIn4326 == floridaProjectedIn3857


def test_map_default_bbox_from_collection_extent(config, openapi):
# Florida in EPSG:3857
config['resources']['mapserver_world_map']['extents']['spatial'] = {
'bbox': [-9837751.2884, 2854464.3843, -8695476.3377, 3634733.5690],
'crs': 'http://www.opengis.net/def/crs/EPSG/0/3857'
}
api_ = API(config, openapi)

# request does not provide bbox, so collection spatial extent is used
req = mock_api_request()
rsp_headers, code, _ = get_collection_map(
api_, req, 'mapserver_world_map')

assert code == HTTPStatus.OK
assert rsp_headers.get(
'Content-Crs', 'http://www.opengis.net/def/crs/OGC/1.3/CRS84')
content_bbox = [float(c) for c in rsp_headers['Content-Bbox'].split(',')]
assert content_bbox == pytest.approx(

@doublebyte1 doublebyte1 Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could also add an assertion here for the bbox-crs?

@ricardogsilva ricardogsilva Oct 29, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bbox-crs is a parameter of the request, not something returned in the response.

Maybe you meant to write that we should check the response contains the Content-Crs header with the correct value?

It is already implied in the assertion, as the coordinates would only make sense if the content CRS would be CRS84 (e.g. the collection's storage CRS in this case), but I will also add the explicit assertion for this response header, as I agree that having it explicitly checked is best.

[-88.374023, 24.826625, -78.112793, 31.015279], abs=1e-5)
Loading