Query apiso:ServiceType on data.gov pycsw


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

In [2]:
#endpoint = 'http://geoport.whoi.edu/csw' 
#endpoint = 'http://data.nodc.noaa.gov/geoportal/csw'
endpoint = 'http://catalog.data.gov/csw-all'
#endpoint = 'http://geonode.wfp.org/catalogue/csw'
csw = CatalogueServiceWeb(endpoint,timeout=60)
print csw.version


2.0.2

In [3]:
csw.get_operation_by_name('GetRecords').constraints


Out[3]:
[Constraint: SupportedISOQueryables - ['apiso:DistanceValue', 'apiso:Abstract', 'apiso:RevisionDate', 'apiso:Subject', 'apiso:KeywordType', 'apiso:Title', 'apiso:CRS', 'apiso:PublicationDate', 'apiso:Type', 'apiso:AlternateTitle', 'apiso:BoundingBox', 'apiso:AnyText', 'apiso:ParentIdentifier', 'apiso:Modified', 'apiso:Operation', 'apiso:Format', 'apiso:TempExtent_end', 'apiso:DistanceUOM', 'apiso:OrganisationName', 'apiso:ServiceType', 'apiso:TempExtent_begin', 'apiso:ResourceLanguage', 'apiso:ServiceTypeVersion', 'apiso:OperatesOn', 'apiso:Denominator', 'apiso:HasSecurityConstraints', 'apiso:OperatesOnIdentifier', 'apiso:GeographicDescriptionCode', 'apiso:Language', 'apiso:Identifier', 'apiso:OperatesOnName', 'apiso:TopicCategory', 'apiso:CreationDate', 'apiso:CouplingType'],
 Constraint: AdditionalQueryables - ['apiso:Lineage', 'apiso:Classification', 'apiso:Creator', 'apiso:Relation', 'apiso:OtherConstraints', 'apiso:SpecificationTitle', 'apiso:ResponsiblePartyRole', 'apiso:SpecificationDateType', 'apiso:Degree', 'apiso:Contributor', 'apiso:ConditionApplyingToAccessAndUse', 'apiso:SpecificationDate', 'apiso:AccessConstraints', 'apiso:Publisher'],
 Constraint: SupportedDublinCoreQueryables - ['dc:contributor', 'dc:source', 'dc:language', 'dc:title', 'dc:subject', 'dc:creator', 'dc:type', 'ows:BoundingBox', 'dct:modified', 'dct:abstract', 'dc:relation', 'dc:date', 'dc:identifier', 'dc:publisher', 'dc:format', 'csw:AnyText', 'dc:rights']]

In [4]:
try:
    csw.get_operation_by_name('GetDomain')
    csw.getdomain('apiso:ServiceType', 'property')
    print(csw.results['values'])
except:
    print('GetDomain not supported')


[None, 'ArcGIS Map Service', 'ERDDAP tabledap,OPeNDAP', 'ERDDAP tabledap,OPeNDAP,ERDDAP Subset', 'GeoServices REST Specification', 'THREDDS OPeNDAP,Open Geospatial Consortium Web Coverage Service (WCS),Open Geospatial Consortium Web Map Service (WMS)', 'urn:ogc:serviceType:WebMapService']

In [5]:
val = 'COAWST'
#val = 'COADS'
filter1 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [ filter1 ]

In [6]:
csw.getrecords2(constraints=filter_list,maxrecords=100,esn='full')
print len(csw.records.keys())
for rec in list(csw.records.keys()):
    print csw.records[rec].title


7
MAB_hIPR.SHP: Half interpercentile range (half of the difference between the 16th and 84th percentiles) of wave-current bottom shear stress in the Middle Atlantic Bight for May, 2010 - May, 2011
MAB_95th_perc.SHP: 95th percentile of wave-current bottom shear stress in the Middle Atlantic Bight for May, 2010 - May, 2011
MAB_mobile_freq.SHP: recurrence interval of sediment mobility at select points in the Middle Atlantic Bight for May, 2010 - May, 2011
MAB_mobile_perc.SHP: percentage of time sediment is mobile for May, 2010 - May, 2011 at select points in the Middle Atlantic Bight
MAB_median.SHP: median of wave-current bottom shear stress in the Middle Atlantic Bight for May, 2010 - May, 2011
COAWST Forecast System : USGS : US East Coast and Gulf of Mexico (Experimental)
COAWST Forecast System : USGS : US East Coast and Gulf of Mexico (Experimental)

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


MAB_95th_perc.SHP: 95th percentile of wave-current bottom shear stress in the Middle Atlantic Bight for May, 2010 - May, 2011
Out[7]:
[{'scheme': 'WWW:LINK',
  'url': 'http://woodshole.er.usgs.gov/project-pages/mobility/mid_atl_bight.html'},
 {'scheme': 'WWW:DOWNLOAD',
  'url': 'http://woodshole.er.usgs.gov/project-pages/mobility/ArcData/MAB_95th_perc.zip'},
 {'scheme': 'WWW:LINK',
  'url': 'http://woodshole.er.usgs.gov/project-pages/mobility/index.html'}]

In [8]:
csw.request


Out[8]:
'<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="100" 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>full</csw:ElementSetName><csw:Constraint version="1.1.0"><ogc:Filter><ogc:PropertyIsLike wildCard="*" singleChar="?" escapeChar="\\"><ogc:PropertyName>apiso:AnyText</ogc:PropertyName><ogc:Literal>*COAWST*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter></csw:Constraint></csw:Query></csw:GetRecords>'

In [9]:
csw.records[choice].xml


Out[9]:
'<csw:Record xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inspire_common="http://inspire.ec.europa.eu/schemas/common/1.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dct="http://purl.org/dc/terms/" xmlns:ows="http://www.opengis.net/ows" xmlns:apiso="http://www.opengis.net/cat/csw/apiso/1.0" xmlns:gml="http://www.opengis.net/gml" xmlns:dif="http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:ogc="http://www.opengis.net/ogc" xmlns:fgdc="http://www.opengis.net/cat/csw/csdgm" xmlns:inspire_ds="http://inspire.ec.europa.eu/schemas/inspire_ds/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:os="http://a9.com/-/spec/opensearch/1.1/" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"><dc:identifier>b740528d-854d-4f04-87e3-6c76fdb113f3</dc:identifier><dc:title>MAB_95th_perc.SHP: 95th percentile of wave-current bottom shear stress in the Middle Atlantic Bight for May, 2010 - May, 2011</dc:title><dc:type>dataset</dc:type><dc:subject>bottom shear stress</dc:subject><dc:subject>U.S. Geological Survey</dc:subject><dc:subject>USGS</dc:subject><dc:subject>Woods Hole Coastal and Marine Science Center</dc:subject><dc:subject>WHCMSC</dc:subject><dc:subject>Coastal and Marine Geology Program</dc:subject><dc:subject>CMGP</dc:subject><dc:subject>wave</dc:subject><dc:subject>current</dc:subject><dc:subject>SWAN</dc:subject><dc:subject>ROMS</dc:subject><dc:subject>Grant-Madsen</dc:subject><dc:subject>Coastal and marine spatial planning</dc:subject><dc:subject>CMSP</dc:subject><dc:subject>sea floor habitat</dc:subject><dc:subject>sediment mobility</dc:subject><dc:subject>oceans</dc:subject><dc:subject>oceans and estuaries</dc:subject><dc:subject>oceans and coastal</dc:subject><dc:subject>geoscientificInformation</dc:subject><dc:subject>Middle Atlantic Bight</dc:subject><dc:subject>U.S. East Coast</dc:subject><dc:subject>Chesapeake Bay</dc:subject><dc:subject>United States</dc:subject><dc:subject>North America</dc:subject><dc:subject>Atlantic Ocean</dc:subject><dc:subject>Long Island</dc:subject><dc:subject>New York Bight</dc:subject><dc:subject>Nantucket Shoals</dc:subject><dc:subject>Hudson Shelf Valley</dc:subject><dc:subject>Long Island Sound</dc:subject><dc:subject>Delaware Bay</dc:subject><dc:subject>Pamlico Sound</dc:subject><dc:subject>Rhode Island Sound</dc:subject><dc:subject>seafloor</dc:subject><dct:references scheme="WWW:LINK">http://woodshole.er.usgs.gov/project-pages/mobility/mid_atl_bight.html</dct:references><dct:references scheme="WWW:DOWNLOAD">http://woodshole.er.usgs.gov/project-pages/mobility/ArcData/MAB_95th_perc.zip</dct:references><dct:references scheme="WWW:LINK">http://woodshole.er.usgs.gov/project-pages/mobility/index.html</dct:references><dc:relation/><dct:modified>2012-06-27</dct:modified><dct:abstract>The U.S. Geological Survey has been characterizing the regional variation in shear stress on the sea floor and sediment mobility through statistical descriptors. The purpose of this project is to identify patterns in stress in order to inform habitat delineation or decisions for anthropogenic use of the continental shelf. The statistical characterization spans the continental shelf from the coast to approximately 120 m water depth, at approximately 5 km resolution. Time-series of wave and circulation are created using numerical models, and near-bottom output of steady and oscillatory velocities and an estimate of bottom roughness are used to calculate a time-series of bottom shear stress at 1-hour intervals. Statistical descriptions such as the median and 95th percentile, which are the output included with this database, are then calculated to create a two-dimensional picture of the regional patterns in shear stress. In addition, time-series of stress are compared to critical stress values at select points calculated from observed surface sediment texture data to determine estimates of sea floor mobility.</dct:abstract><dc:date>2012-06-27</dc:date><dc:language>eng; USA</dc:language><dc:rights>otherRestrictions</dc:rights><ows:BoundingBox crs="urn:x-ogc:def:crs:EPSG:6.11:4326" dimensions="2"><ows:LowerCorner>34.1 -76.82</ows:LowerCorner><ows:UpperCorner>41.62 -68.41</ows:UpperCorner></ows:BoundingBox></csw:Record>'

Add bounding box constraint. To specify lon,lat order for bbox (which we want to do so that we can use the same bbox with either geoportal server or pycsw requests), we need to request the bounding box specifying the CRS84 coordinate reference system. The CRS84 option is available in pycsw 1.1.10+. The ability to specify the crs in the bounding box request is available in owslib 0.8.12+. For more info on the bounding box problem and how it was solved, see this pycsw issue, this geoportal server issue, and this owslib issue


In [10]:
bbox = [-87.40, 34.25, -63.70, 66.70]    # [lon_min, lat_min, lon_max, lat_max]
bbox_filter = fes.BBox(bbox,crs='urn:ogc:def:crs:OGC:1.3:CRS84')
filter_list = [fes.And([filter1, bbox_filter])]
csw.getrecords2(constraints=filter_list, maxrecords=1000)

In [11]:
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)
    print(' ')


7
title:MAB_hIPR.SHP: Half interpercentile range (half of the difference between the 16th and 84th percentiles) of wave-current bottom shear stress in the Middle Atlantic Bight for May, 2010 - May, 2011
identifier:171693a6-90c8-478a-ac37-e8856c8db01e
modified:2012-06-27
 
title:MAB_95th_perc.SHP: 95th percentile of wave-current bottom shear stress in the Middle Atlantic Bight for May, 2010 - May, 2011
identifier:b740528d-854d-4f04-87e3-6c76fdb113f3
modified:2012-06-27
 
title:MAB_mobile_freq.SHP: recurrence interval of sediment mobility at select points in the Middle Atlantic Bight for May, 2010 - May, 2011
identifier:df09bfdf-d0a6-4356-8a89-59b7d59a53d8
modified:2012-06-27
 
title:MAB_mobile_perc.SHP: percentage of time sediment is mobile for May, 2010 - May, 2011 at select points in the Middle Atlantic Bight
identifier:4a5f5a5a-e81c-4dff-a349-c0b196f5da42
modified:2012-06-27
 
title:MAB_median.SHP: median of wave-current bottom shear stress in the Middle Atlantic Bight for May, 2010 - May, 2011
identifier:432d2b65-dfc5-425b-87eb-d4b334c71723
modified:2012-06-27
 
title:COAWST Forecast System : USGS : US East Coast and Gulf of Mexico (Experimental)
identifier:gov.usgs.cmgp:COAWST.USEAST.Forecast
modified:2015-04-22
 
title:COAWST Forecast System : USGS : US East Coast and Gulf of Mexico (Experimental)
identifier:gov.usgs.er.whsc:coawst_4.use.fmrc.coawst_4_use_best.ncd
modified:2015-09-22-07:00
 

In [12]:
val = 'WMS'
filter2 = fes.PropertyIsLike(propertyname='apiso:ServiceType',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [fes.And([filter1, filter2, bbox_filter])]
csw.getrecords2(constraints=filter_list, maxrecords=1000)

In [13]:
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)
    print(' ')


0

In [ ]:


In [ ]: