geopython / pygeoapi

pygeoapi is a Python server implementation of the OGC API suite of standards. The project emerged as part of the next generation OGC API efforts in 2018 and provides the capability for organizations to deploy a RESTful OGC API endpoint using OpenAPI, GeoJSON, and HTML. pygeoapi is open source and released under an MIT license.
https://pygeoapi.io
MIT License
460 stars 250 forks source link

key-error when requesting map in non supported crs code #1648

Open pvgenuchten opened 1 month ago

pvgenuchten commented 1 month ago

Is your feature request related to a problem? Please describe.

When requesting a map in epsg:3857 http://localhost:5000/collections/mapserver_world_map/map?f=png&bbox-crs=EPSG:3857& the follwoing error is displayed:

File "/mnt/c/projects/geopython/lib/python3.10/site-packages/pygeoapi-0.17.dev0-py3.10.egg/pygeoapi/flask_app.py", line 160, in execute_from_flask
headers, status, content = api_function(api_, api_request, *args)
File "/mnt/c/projects/geopython/lib/python3.10/site-packages/pygeoapi-0.17.dev0-py3.10.egg/pygeoapi/api/maps.py", line 160, in get_collection_map
data = p.query(**query_args)
File "/mnt/c/projects/geopython/lib/python3.10/site-packages/pygeoapi-0.17.dev0-py3.10.egg/pygeoapi/provider/wms_facade.py", line 93, in query
LOGGER.debug(f'Output CRS: {CRS_CODES[crs]}')
KeyError: 'EPSG:3857'

the reason is clear, i'm requesting a map in non supported projection, however would be nice to have a better error discription. Seems the bbox is expected as http://www.opengis.net/def/crs/EPSG/0/3857. However when I run this request, a nill image is returned:

https://demo.pygeoapi.io/master/collections/mapserver_world_map/map?f=png&bbox-crs=http://www.opengis.net/def/crs/EPSG/0/3857&service=WMS&request=GetMap&layers=&styles=&format=image%2Fjpeg&transparent=false&version=1.1.1&width=256&height=256&srs=EPSG%3A3857&bbox=-3757032.814272984,3757032.8142729844,-2504688.5428486555,5009377.085697314

in logs the following error is displayed:

[2024-05-11T15:48:02Z] {/mnt/c/projects/geopython/lib/python3.10/site-packages/pygeoapi-0.17.dev0-py3.10.egg/pygeoapi/api/__init__.py:1393} ERROR - query error (check logs)
Traceback (most recent call last):
  File "/mnt/c/projects/geopython/lib/python3.10/site-packages/pygeoapi-0.17.dev0-py3.10.egg/pygeoapi/api/maps.py", line 160, in get_collection_map
    data = p.query(**query_args)
  File "/mnt/c/projects/geopython/lib/python3.10/site-packages/pygeoapi-0.17.dev0-py3.10.egg/pygeoapi/provider/wms_facade.py", line 138, in query
    raise ProviderQueryError(msg)
pygeoapi.provider.base.ProviderQueryError: WMS error: b'<?xml version=\'1.0\' encoding="UTF-8" standalone="no" ?>\n<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd">\n<ServiceException>\nmsWMSLoadGetMapParams(): WMS server error. Invalid values for BBOX.\n</ServiceException>\n</ServiceExceptionReport>\n'

the wms backend seems to not support the 3857 projection, suggestion here would be to return an error in stead of an empty image