[OWSLib-users] Download Large Sizes for WMS Request in OWSLib [SEC=UNCLASSIFIED]

Dominic Lowe D.Lowe at bom.gov.au
Wed Sep 24 22:59:42 PDT 2014


Hi Noah,

For some reason the server isn't sending the 'Content-Type' http header when you make a large request and it is sending an empty (zero length) response. Probably this is deliberate. OWSLib could handle it more gracefully but I think it's ultimately a server limitation.

You can see this as follows if you make the request directly using urllib2.

In [59]: from urllib2 import urlopen

In [60]: ubig=urlopen('http://raster.nationalmap.gov/arcgis/services/Orthoimagery/USGS_EROS_Ortho_NAIP/ImageServer/WMSServer?request=GetMap&service=WMS&CRS=EPSG:4326&bbox=-111.85738494873,%2039.9462890625,%20-110.98876849262,%2040.445555601989&width=8000&height=4590&format=image/jpeg')

In [61]: usmall=urlopen('http://raster.nationalmap.gov/arcgis/services/Orthoimagery/USGS_EROS_Ortho_NAIP/ImageServer/WMSServer?request=GetMap&service=WMS&CRS=EPSG:4326&bbox=-111.85738494873,%2039.9462890625,%20-110.98876849262,%2040.445555601989&width=800&height=459&format=image/jpeg')

In [62]: ubig.info().headers
Out[62]:
['Cache-Control: private\r\n',
'X-Frame-Options: SAMEORIGIN\r\n',
'Date: Thu, 25 Sep 2014 05:55:33 GMT\r\n',
'Content-Length: 0\r\n',
'Connection: Close\r\n']

In [63]: usmall.info().headers
Out[63]:
['Cache-Control: private\r\n',
'Content-Type: image/jpeg\r\n',
'X-Frame-Options: SAMEORIGIN\r\n',
'Date: Thu, 25 Sep 2014 05:55:36 GMT\r\n',
'Content-Length: 6497\r\n',
'Connection: Close\r\n']

Regards
Dom

From: owslib-users-bounces at lists.osgeo.org [mailto:owslib-users-bounces at lists.osgeo.org] On Behalf Of Noah Taylor
Sent: Thursday, 25 September 2014 3:15 PM
To: owslib-users at lists.osgeo.org
Subject: [OWSLib-users] Download Large Sizes for WMS Request in OWSLib

Hi,

I have been having troubles finding a working WMS server for OWSLib but I finally found a URL that is working with my code:

http://raster.nationalmap.gov/arcgis/services/Orthoimagery/USGS_EROS_Ortho_NAIP/ImageServer/WMSServer?request=GetCapabilities&service=WMS

I'd like to have a world map at this high resolution since this is just a U.S. map, if anybody knows of any, but in any case the problem I am facing now is that when I attempt to call a large size, I get the following error:

KeyError: 'content-type'

The error does not show up if I stay below or close to 3MB so I am unsure if this is a limit that the WMS server is imposing on me or if it is an error in the Python code. I read somewhere there is a default limit to act as the safeguard to the user so they don't accidentally download more than they can handle but am unsure. I will post my 'working' script below. You will only need to run it to see the error and downsize the size for it to actually download the request.

Thanks for your time
Noah

###################################################################

from owslib.wms import WebMapService
wms = WebMapService('http://raster.nationalmap.gov/arcgis/services/Orthoimagery/USGS_EROS_Ortho_NAIP/ImageServer/WMSServer?request=GetCapabilities&service=WMS')


print(wms.identification.type)
print(wms.identification.title)
print(list(wms.contents))
print(wms['0'].title)
print(wms['0'].boundingBox)
print(wms['0'].crsOptions)
print(wms['0'].styles)

print(wms.getOperationByName('GetMap').formatOptions)

print(list(wms.contents))


img = wms.getmap(   layers=['0'],
                     styles=[],
                     srs='EPSG:4326',
                     bbox=(-111.85738494873, 39.9462890625, -110.98876849262, 40.445555601989),
                     size=(8000, 4598),
                     format='image/jpeg',
                     transparent=True,
                     stream = True)
out = open('nationalmap.jpg', 'wb')
out.write(img.read())
out.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/owslib-users/attachments/20140925/be3df0d9/attachment-0001.html>


More information about the OWSLib-users mailing list