SciTools / cartopy

Cartopy - a cartographic python library with matplotlib support
https://scitools.org.uk/cartopy/docs/latest
BSD 3-Clause "New" or "Revised" License
1.41k stars 359 forks source link

WMS error: Parameter 'layers' contains unacceptable layer names #1020

Closed rsignell-usgs closed 6 years ago

rsignell-usgs commented 6 years ago

When I try to add the Gebco hillshade bathmetry WMS layer thusly:

import cartopy.crs as ccrs
from owslib.wms import WebMapService

url='https://gis.ngdc.noaa.gov/arcgis/services/gebco08_hillshade/MapServer/WMSServer'
wms = WebMapService(url)

layer='GEBCO_08 Hillshade'

plt.figure(figsize=(6,6))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_wms(wms, layer)

I'm getting:

Parameter 'layers' contains unacceptable layer names

Is there perhaps some problem with the underscore or space in the layer name?

FWIW, this WMS endpoint works okay with other WMS clients, including Folium:

import folium
bbox = [-74.5, 40, -72., 41.5]
zoom_start = 5
lon = (bbox[0] + bbox[2]) / 2
lat = (bbox[1] + bbox[3]) / 2
m = folium.Map(width='100%', height='100%',
               location=[lat, lon], zoom_start=zoom_start)
url = 'https://gis.ngdc.noaa.gov/arcgis/services/gebco08_hillshade/MapServer/WMSServer'
w = folium.WmsTileLayer(url, name='GEBCO Bathymetry', fmt='image/png',
    layers='GEBCO_08 Hillshade', attr='GEBCO',  overlay=True, transparent=True)
w.add_to(m)
m

Screen grab: 2018-02-07_7-20-03

akrherz commented 6 years ago

Hi @rsignell-usgs ! GEBCO_08 Hillshade gets sent to the WMS server as GEBCO_08+Hillshade instead of GEBCO_08%20Hillshade, unsure if the bug is with cartopy or owslib, but will dig some more!

akrherz commented 6 years ago

Oh, https://github.com/mapserver/mapserver/issues/5232#issuecomment-180048058 implies this issue is a ESRI bug!

The issue code and description at ESRI was

[#NIM104588 For layer names having spaces, the GetMap request URL for ArcGIS WMS services requires %20 to be used in place of spaces instead of a '+' sign.]

pelson commented 6 years ago

If there is a bug with the implementation, I think it exists in owslib, where there is an urlencoding at https://github.com/geopython/OWSLib/blob/508f966ecaf212ed4a413d69279e944ecb6cac26/owslib/map/wms130.py#L302. cartopy is simply passing the layers through to owslib, and if possible I would want owslib to do the validation, not cartopy itself.

@rsignell-usgs - do you want to move the discussion over to owslib for visibility?

Closing this here as I don't think there is anything cartopy should do in this instance.