geopython / OWSLib

OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service (hence OWS) interface standards, and their related content models.
https://owslib.readthedocs.io
BSD 3-Clause "New" or "Revised" License
390 stars 276 forks source link

Incorrect WMS Key Value Pair syntax created by geturl() #363

Closed nmtoken closed 7 years ago

nmtoken commented 7 years ago

geturl() creates incorrect WMS Key Value Pair (KVP) syntax.

The WMS specification tells us:

A URL prefix is defined as an opaque string including the protocol, hostname, optional port number, path, a question mark '?', and, optionally, one or more server specific parameters ending in an ampersand '&'.

A client appends the necessary request parameters as name/value pairs in the form "name=value&". The resulting URL shall be valid according to the HTTP Common Gateway Interface standard [CGI], which mandates the presence of '?' before the sequence of query parameters and the '&' between each parameter. The URL prefix shall end in either a '?' (in the absence of additional server-specific parameters) or a '&'.

So we should have a URL like: http://host[:port]/path?{name[=value]&}

Using the following code as an example we can see that we don't get a closing ampersand instead the key (name) / value pairs seem to be added with a starting ampersand, so we get a double && when parameters are appended to the advertised service URL

i.e.

...?language=eng&&service=WMS

from owslib import wms as wms

end_point = "http://ogc.bgs.ac.uk/cgi-bin/BGS_AGS_EN_Bedrock_and_Structural_Geology/wms?"

wm_130 = wms.WebMapService(end_point, version='1.3.0')
afmap = wm_130.getmap(layers=['AFG_AGS_1M_BLS'], styles=[], srs="EPSG:32641",
                      bbox=(180307, 2.97704e+006, 1.7569e+006, 4.6101e+006),
                      format="image/png", size=(1205, 735), transparent=True)
print(afmap.geturl())

wm_111 = wms.WebMapService(end_point, version='1.1.1')
afmap1 = wm_111.getmap(layers=['AFG_AGS_1M_BLS'], styles=[], srs="EPSG:32641",
                      bbox=(180307, 2.97704e+006, 1.7569e+006, 4.6101e+006),
                      format="image/png", size=(1205, 735), transparent=True)
print(afmap1.geturl())

The generated URLs are:

http://ogc.bgs.ac.uk/cgi-bin/BGS_AGS_EN_Bedrock_and_Structural_Geology/wms?language=eng&&service=WMS&version=1.3.0&request=GetMap&layers=AFG_AGS_1M_BLS&styles=&width=1205&height=735&crs=EPSG%3A32641&bbox=180307%2C2977040.0%2C1756900.0%2C4610100.0&format=image%2Fpng&transparent=TRUE&bgcolor=0xFFFFFF&exceptions=XML

http://ogc.bgs.ac.uk/cgi-bin/BGS_AGS_EN_Bedrock_and_Structural_Geology/wms?language=eng&&service=WMS&version=1.1.1&request=GetMap&layers=AFG_AGS_1M_BLS&styles=&width=1205&height=735&srs=EPSG%3A32641&bbox=180307%2C2977040.0%2C1756900.0%2C4610100.0&format=image%2Fpng&transparent=TRUE&bgcolor=0xFFFFFF&exceptions=application%2Fvnd.ogc.se_xml

tomkralidis commented 7 years ago

Fixed in master.