In [1]:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
%matplotlib inline

In [2]:
def make_map(projection=ccrs.PlateCarree(), extent=[-42, 0, -32, 0.5]):
    subplot_kw = dict(projection=projection)
    fig, ax = plt.subplots(subplot_kw=subplot_kw)
    ax.set_extent(extent)
    gl = ax.gridlines(draw_labels=True)
    gl.xlabels_top = gl.ylabels_right = False
    gl.xformatter = LONGITUDE_FORMATTER
    gl.yformatter = LATITUDE_FORMATTER
    return fig, ax

In [3]:
from owslib.wms import WebMapService
url = "http://nowcoast.noaa.gov/wms/com.esri.wms.Esrimap/analyses"
wms = WebMapService(url)

layer = 'NCEP_RAS_ANAL_RTG_SST'
fig, ax = make_map(projection=ccrs.PlateCarree())
ax.add_wms(wms, layer)
_ = ax.set_title(layer)


/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/IPython/core/formatters.py:239: FormatterWarning: Exception in image/png formatter: u'Invalid WIDTH value, NumberFormatException : For input string: "273.379119692"'
  FormatterWarning,
<matplotlib.figure.Figure at 0x7f64e72e63d0>

In [4]:
url = "http://nowcoast.noaa.gov/wms/com.esri.wms.Esrimap/analyses"
layer = 'NCEP_RAS_ANAL_RTG_SST'

ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_wms(url, layer)
ax.set_extent((-15, 25, 35, 60))


/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/IPython/core/formatters.py:239: FormatterWarning: Exception in image/png formatter: u'Invalid WIDTH value, NumberFormatException : For input string: "334.8"'
  FormatterWarning,
<matplotlib.figure.Figure at 0x7f64e0453250>

In [5]:
url = 'http://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi'
layer = 'VIIRS_CityLights_2012'

ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_wmts(url, layer)
ax.set_extent((-15, 25, 35, 60))

plt.title('Suomi NPP Earth at night April/October 2012')
plt.show()



In [6]:
url='http://coast.noaa.gov/arcgis/services/CCAP/All_Change_0106/MapServer/WMSServer?request=GetCapabilities&service=WMS'
wms = WebMapService(url)

In [7]:
for k,v in wms.contents.iteritems():
    print v.name,v.title


1 pacific_coast_0106_all_change_wm
0 southeast_0106_all_change_wm
3 gulf_coast_0106_all_change_wm
2 northeast_0106_all_change_wm
4 great_lakes_0106_all_change_wm

In [11]:
layer = '2'

In [12]:
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_wms(url, layer)
ax.set_extent((-71.5, 41.5, -71.0, 42))


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-29e64d1222ae> in <module>()
      1 ax = plt.axes(projection=ccrs.PlateCarree())
----> 2 ax.add_wms(url, layer)
      3 ax.set_extent((-71.5, 41.5, -71.0, 42))

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/cartopy/mpl/geoaxes.pyc in add_wms(self, wms, layers, wms_kwargs, **kwargs)
   1543         """
   1544         from cartopy.io.ogc_clients import WMSRasterSource
-> 1545         wms = WMSRasterSource(wms, layers, getmap_extra_kwargs=wms_kwargs)
   1546         return self.add_raster(wms, **kwargs)
   1547 

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/cartopy/io/ogc_clients.pyc in __init__(self, service, layers, getmap_extra_kwargs)
    101         """
    102         if isinstance(service, basestring):
--> 103             service = WebMapService(service)
    104 
    105         if isinstance(layers, basestring):

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/OWSLib-0.8.13-py2.7.egg/owslib/wms.pyc in __init__(self, url, version, xml, username, password, parse_remote_metadata)
     88 
     89         # build metadata objects
---> 90         self._buildMetadata(parse_remote_metadata)
     91 
     92     def _getcapproperty(self):

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/OWSLib-0.8.13-py2.7.egg/owslib/wms.pyc in _buildMetadata(self, parse_remote_metadata)
    103         #serviceIdentification metadata
    104         serviceelem=self._capabilities.find('Service')
--> 105         self.identification=ServiceIdentification(serviceelem, self.version)
    106 
    107         #serviceProvider metadata

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/OWSLib-0.8.13-py2.7.egg/owslib/wms.pyc in __init__(self, infoset, version)
    272     def __init__(self, infoset, version):
    273         self._root=infoset
--> 274         self.type = testXMLValue(self._root.find('Name'))
    275         self.version = version
    276         self.title = testXMLValue(self._root.find('Title'))

AttributeError: 'NoneType' object has no attribute 'find'

In [10]:
url='http://services.arcgisonline.com/arcgis/rest/services/Ocean_Basemap/MapServer/WMTS/1.0.0/WMTSCapabilities.xml'
layer='Ocean_Basemap'
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_wmts(url, layer)
ax.set_extent((-15, 25, 35, 60))


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-7856174d5762> in <module>()
      2 layer='Ocean_Basemap'
      3 ax = plt.axes(projection=ccrs.PlateCarree())
----> 4 ax.add_wmts(url, layer)
      5 ax.set_extent((-15, 25, 35, 60))

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/cartopy/mpl/geoaxes.pyc in add_wmts(self, wmts, layer_name, **kwargs)
   1516         """
   1517         from cartopy.io.ogc_clients import WMTSRasterSource
-> 1518         wmts = WMTSRasterSource(wmts, layer_name)
   1519         return self.add_raster(wmts, **kwargs)
   1520 

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/cartopy/io/ogc_clients.pyc in __init__(self, wmts, layer_name)
    191                 hasattr(wmts, 'contents') and
    192                 hasattr(wmts, 'gettile')):
--> 193             wmts = owslib.wmts.WebMapTileService(wmts)
    194 
    195         try:

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/OWSLib-0.8.13-py2.7.egg/owslib/wmts.pyc in __init__(self, url, version, xml, username, password, parse_remote_metadata, vendor_kwargs)
    171 
    172         # build metadata objects
--> 173         self._buildMetadata(parse_remote_metadata)
    174 
    175     def _getcapproperty(self):

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/OWSLib-0.8.13-py2.7.egg/owslib/wmts.pyc in _buildMetadata(self, parse_remote_metadata)
    191         # serviceProvider metadata
    192         serviceprov = self._capabilities.find(_SERVICE_PROVIDER_TAG)
--> 193         self.provider = ServiceProvider(serviceprov)
    194 
    195         # serviceOperations metadata

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/OWSLib-0.8.13-py2.7.egg/owslib/ows.pyc in __init__(self, infoset, namespace)
     78     def __init__(self, infoset,namespace=DEFAULT_OWS_NAMESPACE):
     79         self._root = infoset
---> 80         val = self._root.find(util.nspath('ProviderName', namespace))
     81         self.name = util.testXMLValue(val)
     82         self.contact = ServiceContact(infoset, namespace)

AttributeError: 'NoneType' object has no attribute 'find'

In [ ]:


In [ ]:
http://coast.noaa.gov/arcgis/services/CCAP/All_Change_0106/MapServer/WMSServer?request=GetCapabilities&service=WMS