Skip to content

Instantly share code, notes, and snippets.

@ryanjdillon
Created August 23, 2017 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanjdillon/938ef4d5be1b34c10f5da6c4b9006ba9 to your computer and use it in GitHub Desktop.
Save ryanjdillon/938ef4d5be1b34c10f5da6c4b9006ba9 to your computer and use it in GitHub Desktop.
Working on getting retrieving Kartverket map data
'''
A Package for retrieving Kartverket image data for specified areas.
Exampl URLs
-----------
GetCapabilities:
http://opencache.statkart.no/gatekeeper/gk/gk.open?Version=1.0.0&service=wms&request=getcapabilities
NOAA (not active/testable):
http://porter.pmel.noaa.gov:8922/wms/wms_servlet?VERSION=1.1.1&REQUEST=GetMap&LAYERS=coads_climatology_cdf:airt&STYLES=ferret_default&WIDTH=640&HEIGHT=320&FORMAT=image/png&SRS=EPSG:4326&BBOX=-180.0,-90.0,180.0,90.0&EXCEPTION=application/vnd.ogc.se_xml&DIM_COADS_CLIMATOLOGY_CDF_TIME=15-Jan
'''
def getmap_url(layers, styles='', width=640, height=320, fmt='image/png',
srs='EPSG:4326', bbox='-180.0,-90.0,180.0,90.0', exception=None,
time=None):
'''Retrieve image data for specified layer and attributes
'''
from collections import OrderedDict
layers = ','.join(['GeoWebCache WMS:{}'.format(l) for l in layers])
#layers = ','.join([l for l in layers])
if styles:
styles = ','.join([s for s in styles])
wms = OrderedDict()
wms['url'] = 'http://opencache.statkart.no/gatekeeper/gk/gk.open?'
wms['version'] = 'VERSION=1.0.0'
wms['service'] = '&SERVICE=WMS'
wms['getmap'] = '&REQUEST=GetMap'
wms['layers'] = '&LAYERS={}'.format(layers)
wms['styles'] = '&STYLES={}'.format(styles)
wms['width'] = '&WIDTH={}'.format(width)
wms['height'] = '&HEIGHT={}'.format(height)
wms['fmt'] = '&FORMAT={}'.format(fmt)#.replace('/','%2F'))
wms['srs'] = '&SRS={}'.format(srs)#.replace(':', '%3A'))
wms['bbox'] = '&BBOX={}'.format(bbox)
#wms['exception'] = '&EXCEPTION=application/vnd.ogc.se_xml'
return ''.join(list(wms.values()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment