Repository navigation
get_collection_map() now defaults to using collection's spatial extent #2475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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', | ||
|
|
@@ -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) | ||
| else: | ||
| query_args['crs'] = get_uri(request.params['crs']) | ||
|
|
||
|
|
@@ -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'] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. two points being made here:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn' t
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
|
@@ -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 = { | ||
|
|
@@ -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', | ||
|
|
@@ -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 = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could also add an assertion here for the bbox-crs?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe you meant to write that we should check the response contains the 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) | ||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_deftoprovider_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:
and the respective core conformance class section 7.2.2 Response, Requirement 2, point B reads:
So this part of the code seems to conform to the standard.
The reference you quoted is dealing with the
bbox-crsquery parameter, which is used for subsetting, and is only relevant when the request includes abboxquery param. I don't think it is applicable to this passage of the code.