Exploring CSW access in Python using OWSLib with USGS GI-CAT


In [1]:
from IPython.core.display import HTML
HTML('<iframe src=http://geoport.whoi.edu/gi-cat/ width=900 height=250></iframe>')


Out[1]:

In [2]:
from owslib.csw import CatalogueServiceWeb

In [3]:
# connect to CSW, explore it's properties
#endpoint = 'http://www.ngdc.noaa.gov/geoportal/csw' # NGDC Geoportal
#endpoint = 'http://www.nodc.noaa.gov/geoportal/csw'   # NODC Geoportal: granule level
#endpoint = 'http://data.nodc.noaa.gov/geoportal/csw'  # NODC Geoportal: collection level
    
#endpoint = 'http://geodiscover.cgdi.ca/wes/serviceManagerCSW/csw'  # NRCAN CUSTOM
endpoint = 'http://geoport-dev.whoi.edu/gi-cat/services/cswiso' # USGS Woods Hole GI_CAT
#endpoint = 'http://cida.usgs.gov/gdp/geonetwork/srv/en/csw' # USGS CIDA Geonetwork
csw = CatalogueServiceWeb(endpoint,timeout=60)
csw.version


Out[3]:
'2.0.2'

In [4]:
[op.name for op in csw.operations]


Out[4]:
['GetCapabilities', 'DescribeRecord', 'GetRecords', 'GetRecordById']

In [5]:
#bbox=[-141,42,-52,84]
bbox=[-71.5, 39.5, -63.0, 46]
#csw.getrecords(keywords=['temperature'],bbox=bbox,maxrecords=20)
csw.getrecords(keywords=['sea_water_temperature'],bbox=bbox,maxrecords=20)
csw.results


Out[5]:
{'matches': 0, 'nextrecord': 0, 'returned': 0}

In [6]:
for rec,item in csw.records.iteritems():
    print rec
    print item.title

In [7]:
def service_url(rec,service_string='urn:x-esri:specification:ServiceType:WCS'):
    #create a generator object, and iterate through it until the match is found
    #if not found, gets the default value (here "none")
    url = next((d['url'] for d in rec.references if d['scheme'] == service_string), None)
    return url

In [8]:
dap_url=[]
for key,rec in csw.records.iteritems():
    print rec.title
    url=service_url(rec,service_string='urn:x-esri:specification:ServiceType:TDS')
    print url
    dap_url.append(url)