Query CSW using WMS apiso:ServiceType and print references


In [1]:
from owslib.csw import CatalogueServiceWeb
from owslib import fes
import numpy as np

search NODC geoportal


In [2]:
#endpoint = 'http://data.nodc.noaa.gov/geoportal/csw'
endpoint = 'http://www.nodc.noaa.gov/geoportal/csw' 

val = 'wms'
filter2 = fes.PropertyIsLike(propertyname='apiso:ServiceType',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')
csw = CatalogueServiceWeb(endpoint,timeout=60)


filter_list = [filter2]
csw.getrecords2(constraints=filter_list, maxrecords=1000)

print(len(csw.records.keys()))
choice=np.random.choice(list(csw.records.keys()))
print(csw.records[choice].title)
csw.records[choice].references


1000
20150607-MODIS_A-JPL-L2P-A2015158055500.L2_LAC_GHRSST_N-v01.nc.bz2
Out[2]:
[{'scheme': 'urn:x-esri:specification:ServiceType:ArcIMS:Metadata:Onlink',
  'url': 'http://www.nodc.noaa.gov/SatelliteData/ghrsst/'},
 {'scheme': 'urn:x-esri:specification:ServiceType:ArcIMS:Metadata:Document',
  'url': 'http://www.nodc.noaa.gov/geoportal/csw?getxml=%7B239EBA40-0492-4A0A-81A9-C758053B9E16%7D'},
 {'scheme': 'urn:x-esri:specification:ServiceType:TDS',
  'url': 'http://data.nodc.noaa.gov/thredds/catalog/ghrsst/L2P/MODIS_A/JPL/2015/158/catalog.html?dataset=ghrsst/L2P/MODIS_A/JPL/2015/158/20150607-MODIS_A-JPL-L2P-A2015158055500.L2_LAC_GHRSST_N-v01.nc.bz2'},
 {'scheme': 'urn:x-esri:specification:ServiceType:OPeNDAP',
  'url': 'http://data.nodc.noaa.gov/opendap/ghrsst/L2P/MODIS_A/JPL/2015/158/20150607-MODIS_A-JPL-L2P-A2015158055500.L2_LAC_GHRSST_N-v01.nc.bz2.html'},
 {'scheme': 'urn:x-esri:specification:ServiceType:Download',
  'url': 'http://data.nodc.noaa.gov/ghrsst/L2P/MODIS_A/JPL/2015/158/20150607-MODIS_A-JPL-L2P-A2015158055500.L2_LAC_GHRSST_N-v01.nc.bz2'},
 {'scheme': 'urn:x-esri:specification:ServiceType:Download',
  'url': 'ftp://ftp.nodc.noaa.gov/pub/data.nodc/ghrsst/L2P/MODIS_A/JPL/2015/158/20150607-MODIS_A-JPL-L2P-A2015158055500.L2_LAC_GHRSST_N-v01.nc.bz2'},
 {'scheme': 'urn:x-esri:specification:ServiceType:WMS',
  'url': 'http://data.nodc.noaa.gov/thredds/wms/ghrsst/L2P/MODIS_A/JPL/2015/158/20150607-MODIS_A-JPL-L2P-A2015158055500.L2_LAC_GHRSST_N-v01.nc.bz2?service=WMS&version=1.3.0&request=GetCapabilities'},
 {'scheme': 'urn:x-esri:specification:ServiceType:WCS',
  'url': 'http://data.nodc.noaa.gov/thredds/wcs/ghrsst/L2P/MODIS_A/JPL/2015/158/20150607-MODIS_A-JPL-L2P-A2015158055500.L2_LAC_GHRSST_N-v01.nc.bz2?service=WCS&version=1.0.0&request=GetCapabilities'}]

In [3]:
csw.request


Out[3]:
'<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ogc="http://www.opengis.net/ogc" outputSchema="http://www.opengis.net/cat/csw/2.0.2" outputFormat="application/xml" version="2.0.2" service="CSW" resultType="results" maxRecords="1000" xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd"><csw:Query typeNames="csw:Record"><csw:ElementSetName>summary</csw:ElementSetName><csw:Constraint version="1.1.0"><ogc:Filter><ogc:PropertyIsLike wildCard="*" singleChar="?" escapeChar="\\"><ogc:PropertyName>apiso:ServiceType</ogc:PropertyName><ogc:Literal>*wms*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter></csw:Constraint></csw:Query></csw:GetRecords>'

search geoport pycsw


In [5]:
endpoint = 'http://geoport.whoi.edu/csw'   # NODC/UAF Geoportal: granule level

val = 'WMS'
filter2 = fes.PropertyIsLike(propertyname='apiso:ServiceType',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')
csw = CatalogueServiceWeb(endpoint,timeout=60)


filter_list = [filter2]
csw.getrecords2(constraints=filter_list, maxrecords=1000)

print(len(csw.records.keys()))
choice=np.random.choice(list(csw.records.keys()))
print(csw.records[choice].title)
csw.records[choice].references


0
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-9ab07506b222> in <module>()
     11 
     12 print(len(csw.records.keys()))
---> 13 choice=np.random.choice(list(csw.records.keys()))
     14 print(csw.records[choice].title)
     15 csw.records[choice].references

mtrand.pyx in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:10408)()

ValueError: a must be non-empty

In [ ]:
csw.request

search NGDC geoportal


In [ ]:
endpoint = 'http://www.ngdc.noaa.gov/geoportal/csw' 

val = 'WMS'
filter2 = fes.PropertyIsLike(propertyname='apiso:ServiceType',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')
csw = CatalogueServiceWeb(endpoint,timeout=60)


filter_list = [filter2]
csw.getrecords2(constraints=filter_list, maxrecords=1000)

print(len(csw.records.keys()))
choice=np.random.choice(list(csw.records.keys()))
print(csw.records[choice].title)
print(csw.records[choice].references)

In [ ]:
csw.request

In [ ]:


In [ ]: