from owslib.csw import CatalogueServiceWeb
from owslib import fes
from pprint import pprint
#endpoint = 'http://geoport.whoi.edu/csw'
#endpoint = 'http://data.nodc.noaa.gov/geoportal/csw'
#endpoint = 'https://dev-catalog.ioos.us/csw'
#endpoint = 'https://gamone.whoi.edu/csw'
endpoint = 'https://data.ioos.us/csw'
csw = CatalogueServiceWeb(endpoint,timeout=60)
print(csw.version)
2.0.2
try:
csw.get_operation_by_name('GetDomain')
csw.getdomain('apiso:ServiceType', 'property')
pprint(csw.results['values'])
except:
print('GetDomain not supported')
['ERDDAP OPeNDAP', 'Open Geospatial Consortium Web Map Service (WMS),Open Geospatial Consortium ' 'Web Feature Service (WFS)', 'THREDDS OPeNDAP,Open Geospatial Consortium Sensor Observation Service ' '(SOS),THREDDS HTTP Service', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Coverage Service (WCS),Open ' 'Geospatial Consortium Sensor Observation Service (SOS),THREDDS NetCDF Subset ' 'Service', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Map Service (WMS),THREDDS ' 'NetCDF Subset Service,THREDDS HTTP Service', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Coverage Service ' '(WCS),THREDDS NetCDF Subset Service', 'OGC:WMS,OGC:WFS', 'THREDDS OPeNDAP,Open Geospatial Consortium Sensor Observation Service (SOS)', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Map Service (WMS)', 'ERDDAP tabledap,OPeNDAP', 'Open Geospatial Consortium Web Map Service (WMS),Open Geospatial Consortium ' 'Web Map Service - Cached (WMS-C)', 'Open Geospatial Consortium Web Coverage Service (WCS),Open Geospatial ' 'Consortium Web Map Service (WMS)', 'OPeNDAP:OPeNDAP,OGC:WMS,file', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Map Service (WMS),THREDDS ' 'HTTP Service', 'Open Geospatial Consortium Web Coverage Service (WCS),Open Geospatial ' 'Consortium Web Map Service (WMS),Open Geospatial Consortium Web Map Service ' '- Cached (WMS-C)', 'OGC:SOS', 'ERDDAP griddap,OPeNDAP,Open Geospatial Consortium Web Map Service (WMS)', 'THREDDS OPeNDAP', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Map Service (WMS),THREDDS ' 'NetCDF Subset Service', 'Open Geospatial Consortium Web Feature Service (WFS),Open Geospatial ' 'Consortium Web Map Service (WMS)', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Coverage Service (WCS),Open ' 'Geospatial Consortium Web Map Service (WMS),THREDDS NetCDF Subset Service', 'THREDDS OPeNDAP,Open Geospatial Consortium Sensor Observation Service ' '(SOS),THREDDS NetCDF Subset Service,THREDDS HTTP Service', 'ERDDAP tabledap,OPeNDAP,ERDDAP Subset', 'OPeNDAP:OPeNDAP,OGC:WMS,UNIDATA:NCSS', 'OPeNDAP:OPeNDAP,file', 'ERDDAP OPeNDAP,Open Geospatial Consortium Web Map Service (WMS)', 'OPeNDAP:OPeNDAP,OGC:SOS,file', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Coverage Service (WCS),Open ' 'Geospatial Consortium Web Map Service (WMS)', None, 'OPeNDAP:OPeNDAP', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Coverage Service (WCS),Open ' 'Geospatial Consortium Web Map Service (WMS),THREDDS NetCDF Subset ' 'Service,THREDDS HTTP Service', 'THREDDS OPeNDAP,THREDDS HTTP Service', 'Open Geospatial Consortium Web Feature Service (WFS),Open Geospatial ' 'Consortium Web Map Service (WMS),Open Geospatial Consortium Web Map Service ' '- Cached (WMS-C)', 'Open Geospatial Consortium Web Map Service (WMS)']
def get_csw_records(csw, filter_list, pagesize=10, maxrecords=1000):
"""Iterate `maxrecords`/`pagesize` times until the requested value in
`maxrecords` is reached.
"""
from owslib.fes import SortBy, SortProperty
# Iterate over sorted results.
sortby = SortBy([SortProperty('dc:title', 'ASC')])
csw_records = {}
startposition = 0
nextrecord = getattr(csw, 'results', 1)
while nextrecord != 0:
csw.getrecords2(constraints=filter_list, startposition=startposition,
maxrecords=pagesize, sortby=sortby)
csw_records.update(csw.records)
if csw.results['nextrecord'] == 0:
break
startposition += pagesize + 1 # Last one is included.
if startposition >= maxrecords:
break
csw.records.update(csw_records)
val = 'NECOFS (FVCOM) - Hampton'
filter1 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [filter1]
get_csw_records(csw, filter_list, maxrecords=1000)
#csw.getrecords2(constraints=filter_list, maxrecords=1000)
print(len(csw.records.keys()))
for rec in list(csw.records.keys()):
print('title:'+csw.records[rec].title)
print('identifier:'+csw.records[rec].identifier)
print('modified:'+csw.records[rec].modified)
pprint(csw.records[rec].references)
print(' ')
1 title:NECOFS (FVCOM) - Hampton - Latest Forecast identifier:hampton_nocache modified:2018-05-02 [{'scheme': 'WWW:LINK', 'url': 'http://www.smast.umassd.edu:8080/thredds/dodsC/FVCOM/NECOFS/Forecasts/NECOFS_FVCOM_OCEAN_HAMPTON_FORECAST.nc.html'}, {'scheme': 'WWW:LINK', 'url': 'http://www.ncdc.noaa.gov/oa/wct/wct-jnlp-beta.php?singlefile=http://www.smast.umassd.edu:8080/thredds/dodsC/FVCOM/NECOFS/Forecasts/NECOFS_FVCOM_OCEAN_HAMPTON_FORECAST.nc'}, {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://www.smast.umassd.edu:8080/thredds/dodsC/FVCOM/NECOFS/Forecasts/NECOFS_FVCOM_OCEAN_HAMPTON_FORECAST.nc'}, {'scheme': 'OGC:WMS', 'url': 'http://www.smast.umassd.edu:8080/ncWMS2/wms?service=WMS&version=1.3.0&request=GetCapabilities'}, {'scheme': 'file', 'url': 'http://www.smast.umassd.edu:8080/thredds/fileServer/FVCOM/NECOFS/Forecasts/NECOFS_FVCOM_OCEAN_HAMPTON_FORECAST.nc'}]
val = 'ru26d'
filter1 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [filter1]
get_csw_records(csw, filter_list, maxrecords=1000)
#csw.getrecords2(constraints=filter_list, maxrecords=1000)
print(len(csw.records.keys()))
for rec in list(csw.records.keys()):
print('title:'+csw.records[rec].title)
print('identifier:'+csw.records[rec].identifier)
print('modified:'+csw.records[rec].modified)
pprint(csw.records[rec].references)
print(' ')
6 title:ru26d-20141225T1450 identifier:ru26d-20141225T1450 modified:2018-07-30 [{'scheme': 'order', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20141225T1450.html'}, {'scheme': 'order', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20141225T1450.graph'}, {'scheme': 'ERDDAP:tabledap', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20141225T1450'}, {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20141225T1450'}, {'scheme': 'search', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20141225T1450.subset'}] title:ru26d-20141225T1450 identifier:edu.rutgers.marine:ru26d-20141225T1450_f070_8f49_1646 modified:2018-07-31 [{'scheme': 'WWW:LINK', 'url': 'http://data.ioos.us/thredds/dodsC/deployments/rutgers/ru26d-20141225T1450/ru26d-20141225T1450.nc3.nc.html'}, {'scheme': 'WWW:LINK', 'url': 'http://www.ncdc.noaa.gov/oa/wct/wct-jnlp-beta.php?singlefile=http://data.ioos.us/thredds/dodsC/deployments/rutgers/ru26d-20141225T1450/ru26d-20141225T1450.nc3.nc'}, {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://data.ioos.us/thredds/dodsC/deployments/rutgers/ru26d-20141225T1450/ru26d-20141225T1450.nc3.nc'}, {'scheme': 'OGC:SOS', 'url': 'http://data.ioos.us/thredds/sos/deployments/rutgers/ru26d-20141225T1450/ru26d-20141225T1450.nc3.nc?service=SOS&version=1.0.0&request=GetCapabilities'}, {'scheme': 'file', 'url': 'http://data.ioos.us/thredds/fileServer/deployments/rutgers/ru26d-20141225T1450/ru26d-20141225T1450.nc3.nc'}] title:ru26d-20160201T1313 identifier:ru26d-20160201T1313 modified:2018-07-30 [{'scheme': 'order', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20160201T1313.html'}, {'scheme': 'order', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20160201T1313.graph'}, {'scheme': 'ERDDAP:tabledap', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20160201T1313'}, {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20160201T1313'}, {'scheme': 'search', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20160201T1313.subset'}] title:ru26d-20160201T1313 identifier:edu.rutgers.marine:ru26d-20160201T1313_f070_8f49_1646 modified:2018-07-31 [{'scheme': 'WWW:LINK', 'url': 'http://data.ioos.us/thredds/dodsC/deployments/rutgers/ru26d-20160201T1313/ru26d-20160201T1313.nc3.nc.html'}, {'scheme': 'WWW:LINK', 'url': 'http://www.ncdc.noaa.gov/oa/wct/wct-jnlp-beta.php?singlefile=http://data.ioos.us/thredds/dodsC/deployments/rutgers/ru26d-20160201T1313/ru26d-20160201T1313.nc3.nc'}, {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://data.ioos.us/thredds/dodsC/deployments/rutgers/ru26d-20160201T1313/ru26d-20160201T1313.nc3.nc'}, {'scheme': 'OGC:SOS', 'url': 'http://data.ioos.us/thredds/sos/deployments/rutgers/ru26d-20160201T1313/ru26d-20160201T1313.nc3.nc?service=SOS&version=1.0.0&request=GetCapabilities'}, {'scheme': 'file', 'url': 'http://data.ioos.us/thredds/fileServer/deployments/rutgers/ru26d-20160201T1313/ru26d-20160201T1313.nc3.nc'}] title:ru26d-20171211T0920 identifier:ru26d-20171211T0920 modified:2018-07-30 [{'scheme': 'order', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20171211T0920.html'}, {'scheme': 'order', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20171211T0920.graph'}, {'scheme': 'ERDDAP:tabledap', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20171211T0920'}, {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20171211T0920'}, {'scheme': 'search', 'url': 'https://data.ioos.us/gliders/erddap/tabledap/ru26d-20171211T0920.subset'}] title:ru26d-20171211T0920 identifier:edu.rutgers.marine:ru26d-20171211T0920_f070_8f49_1646 modified:2018-07-31 [{'scheme': 'WWW:LINK', 'url': 'http://data.ioos.us/thredds/dodsC/deployments/rutgers/ru26d-20171211T0920/ru26d-20171211T0920.nc3.nc.html'}, {'scheme': 'WWW:LINK', 'url': 'http://www.ncdc.noaa.gov/oa/wct/wct-jnlp-beta.php?singlefile=http://data.ioos.us/thredds/dodsC/deployments/rutgers/ru26d-20171211T0920/ru26d-20171211T0920.nc3.nc'}, {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://data.ioos.us/thredds/dodsC/deployments/rutgers/ru26d-20171211T0920/ru26d-20171211T0920.nc3.nc'}, {'scheme': 'OGC:SOS', 'url': 'http://data.ioos.us/thredds/sos/deployments/rutgers/ru26d-20171211T0920/ru26d-20171211T0920.nc3.nc?service=SOS&version=1.0.0&request=GetCapabilities'}, {'scheme': 'file', 'url': 'http://data.ioos.us/thredds/fileServer/deployments/rutgers/ru26d-20171211T0920/ru26d-20171211T0920.nc3.nc'}]