from owslib import fes from pprint import pprint
#endpoint = 'http://geoport.whoi.edu/csw'
#endpoint = 'http://data.nodc.noaa.gov/geoportal/csw'
#endpoint = 'https://data.ioos.us/csw'
#endpoint = 'https://dev-catalog.ioos.us/csw'
endpoint = 'https://gamone.whoi.edu/csw'
csw = CatalogueServiceWeb(endpoint,timeout=60)
print(csw.version)
2.0.2
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 = 'CMG_Portal'
filter1 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
escapeChar='\\',wildCard='*',singleChar='?')
val = 'Barnegat'
filter2 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [fes.And([filter1, filter2])]
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[2])
print(' ')
5 title:2010: Delineation of Water Bodies in Emergent Wetlands in Coastal New Jersey identifier:580e7704e4b0f497e794b928 modified:2016-11-03T16:50:32Z {'scheme': 'WWW:LINK-1.0-http--link', 'url': 'https://www.sciencebase.gov/arcgis/rest/services/Catalog/580e7704e4b0f497e794b928/MapServer'} title:COAWST Hindcast:Barnegat Bay:ADCIRC tides, real rivers, plume, lowpass Espresso bdry, NAM, new bathy identifier:COAWST.Barnegat_Bay.Spring2012 modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/usgs/data0/bbleh/spring2012/00_dir_roms.ncml'} title:Conceptual salt marsh units for wetland synthesis: Edwin B. Forsythe National Wildlife Refuge, New Jersey identifier:57fe81fbe4b0824b2d148389 modified:2016-10-28T19:11:45Z {'scheme': 'WWW:LINK-1.0-http--link', 'url': 'https://www.sciencebase.gov/arcgis/rest/services/Catalog/57fe81fbe4b0824b2d148389/MapServer/kml/mapImage.kmz'} title:USGS Barnegat Bay Model for Hurricane Sandy : run076 identifier:gov.usgs.cmg:USGS_BBLEH_SANDY_076 modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/zdefne/run076/00_dir_roms.ncml'} title:USGS Barnegat Bay Model for non-Sandy conditions: run076ns identifier:gov.usgs.cmg:USGS_BBLEH_SANDY_076NS modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/zdefne/run076ns/00_dir_roms.ncml'}
val = 'CMG_Portal'
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[2])
print(' ')
15 title:USGS Chincoteague Bay Model for EPR identifier:gov.usgs.cmg:USGS_COAWST_CHINCO_bedelevation modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/sand/usgs/users/nganju/portal_runs/chincoteague_bedelevation/00_dir.ncml'} title:USGS Chincoteague Bay Model for Hurricane Sandy identifier:gov.usgs.cmg:USGS_COAWST_CHINCO_SANDY modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/sand/usgs/users/nganju/portal_runs/chinco_sandy/00_dir.ncml'} title:USGS-CMG-COAWST Model: Hurricane Sandy, NYB07 700m Nest identifier:gov.usgs.cmg:USGS-CMG-COAWST-NYB07 modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Sandy/triple_nest/00_dir_NYB07.ncml'} title:USGS-CMG-COAWST Model: Hurricane Sandy, SHF05 100m Nest identifier:gov.usgs.cmg:USGS-CMG-COAWST-SHF05 modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Sandy/triple_nest/00_dir_SHF05.ncml'} title:USGS-CMG-COAWST Model: Hurricane Sandy, USE31 5000m Nest identifier:gov.usgs.cmg:USGS-CMG-COAWST-USE31 modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Sandy/triple_nest/00_dir_USE31.ncml'} title:2010: Delineation of Water Bodies in Emergent Wetlands in Coastal New Jersey identifier:580e7704e4b0f497e794b928 modified:2016-11-03T16:50:32Z {'scheme': 'WWW:LINK-1.0-http--link', 'url': 'https://www.sciencebase.gov/arcgis/rest/services/Catalog/580e7704e4b0f497e794b928/MapServer'} title:COAWST Forecast System : USGS : US East Coast and Gulf of Mexico (Experimental) identifier:gov.usgs.cmgp:COAWST.USEAST.Forecast modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/coawst_4/use/fmrc/coawst_4_use_best.ncd'} title:COAWST Hindcast:Barnegat Bay:ADCIRC tides, real rivers, plume, lowpass Espresso bdry, NAM, new bathy identifier:COAWST.Barnegat_Bay.Spring2012 modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/usgs/data0/bbleh/spring2012/00_dir_roms.ncml'} title:COAWST Hindcast:MVCO/CBlast 2007:ripples with SWAN-40m res identifier:COAWST.MVCO.CBLAST.spatial_7_ar0fd modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/usgs/data0/mvco_ce/mvco_output/spatial_7_ar0fd/00_dir_roms.ncml'} title:Conceptual salt marsh units for wetland synthesis: Edwin B. Forsythe National Wildlife Refuge, New Jersey identifier:57fe81fbe4b0824b2d148389 modified:2016-10-28T19:11:45Z {'scheme': 'WWW:LINK-1.0-http--link', 'url': 'https://www.sciencebase.gov/arcgis/rest/services/Catalog/57fe81fbe4b0824b2d148389/MapServer/kml/mapImage.kmz'} title:Hudson River and Jamaica Bay Model for Hurricane Sandy identifier:gov.usgs.cmg:HudJBay_Sandy modified:2017-06-02 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://clancy.whoi.edu/thredds/dodsC/data1/dralston/hudson/sandy/sandy009/00_dir_roms.ncml'} title:Hurricane Sandy: 2013 NWI Data of Selected USFWS Wildlife Refuges along New Jersey and Long Island, New York. identifier:5798c696e4b0589fa1c728a5 modified:2016-08-25T20:05:38Z {'scheme': 'OGC:WMS', 'url': 'https://www.sciencebase.gov/arcgis/services/Catalog/5798c696e4b0589fa1c728a5/MapServer/WMSServer?request=GetCapabilities&service=WMS'} title:Marsh Condition Change Map (Radar and optical mapping of surge persistence and marsh dieback along the New Jersey Mid-Atlantic coast after Hurricane Sandy, April 2016) identifier:57f2aa95e4b0bc0bec001f03 modified:2016-10-11T15:03:16Z {'scheme': 'OGC:WMS', 'url': 'https://www.sciencebase.gov/catalogMaps/mapping/ows/57f2aa95e4b0bc0bec001f03?service=wms&request=getcapabilities&version=1.3.0'} title:USGS Barnegat Bay Model for Hurricane Sandy : run076 identifier:gov.usgs.cmg:USGS_BBLEH_SANDY_076 modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/zdefne/run076/00_dir_roms.ncml'} title:USGS Barnegat Bay Model for non-Sandy conditions: run076ns identifier:gov.usgs.cmg:USGS_BBLEH_SANDY_076NS modified:2017-08-21 {'scheme': 'OPeNDAP:OPeNDAP', 'url': 'http://geoport-dev.whoi.edu/thredds/dodsC/clay/usgs/users/zdefne/run076ns/00_dir_roms.ncml'}
csw.get_operation_by_name('GetDomain')
csw.getdomain('apiso:ServiceType', 'property')
print(csw.results['values'])
except: print('GetDomain not supported')