Query apiso:ServiceType on pycsw endpoint


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://data.doi.gov/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]

In [5]:
val = 'laterite'
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


2
Preliminary map of selected post-Nevadan geologic features of the Klamath Mountains and adjacent areas, California and Oregon: A digital database
Ni-Co laterite deposits of the world

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


Ni-Co laterite deposits of the world
Out[7]:
[{'scheme': 'None',
  'url': 'http://mrdata.usgs.gov/services/laterite?request=getcapabilities&service=WMS&version=1.1.1&'},
 {'scheme': 'None',
  'url': 'http://mrdata.usgs.gov/wfs/laterite?request=getcapabilities&service=WFS&version=1.0.0&'},
 {'scheme': 'minerals',
  'url': 'http://mrdata.usgs.gov/laterite/laterite-csv.zip'}]

In [8]:
csw.request


Out[8]:
'<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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>*laterite*</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>31987f20-1f87-4cd7-8dda-1413d67bdc46</dc:identifier><dc:title>Ni-Co laterite deposits of the world</dc:title><dc:type>dataset</dc:type><dc:subject>mine sites</dc:subject><dc:subject>mineral deposit areas</dc:subject><dc:subject>comma-delimited text</dc:subject><dc:subject>DBF</dc:subject><dc:subject>HTML table</dc:subject><dc:subject>KML</dc:subject><dc:subject>OGC WFS</dc:subject><dc:subject>OGC WMS</dc:subject><dc:subject>shapefile</dc:subject><dc:subject>tab-delimited text</dc:subject><dc:subject>Residuum</dc:subject><dc:subject>Cobalt</dc:subject><dc:subject>Nickel</dc:subject><dc:subject> Laterite</dc:subject><dc:subject>cobalt</dc:subject><dc:subject>economic geology</dc:subject><dc:subject>geospatial datasets</dc:subject><dc:subject>metallic ores</dc:subject><dc:subject>nickel</dc:subject><dc:subject>unconsolidated deposits</dc:subject><dc:subject>Geology</dc:subject><dc:subject>fAL = Albania</dc:subject><dc:subject>fAS = Australia</dc:subject><dc:subject>fBR = Brazil</dc:subject><dc:subject>fBM = Burma</dc:subject><dc:subject>fBY = Burundi</dc:subject><dc:subject>fCM = Cameroon</dc:subject><dc:subject>fCO = Colombia</dc:subject><dc:subject>fIV = Cote D\'Ivoire</dc:subject><dc:subject>fCU = Cuba</dc:subject><dc:subject>fDR = Dominican Republic</dc:subject><dc:subject>f41019 = Douglas</dc:subject><dc:subject>fET = Ethiopia</dc:subject><dc:subject>fGR = Greece</dc:subject><dc:subject>fGT = Guatemala</dc:subject><dc:subject>fIN = India</dc:subject><dc:subject>fID = Indonesia</dc:subject><dc:subject>fKZ = Kazakhstan</dc:subject><dc:subject>fMK = Macedonia</dc:subject><dc:subject>fMA = Madagascar</dc:subject><dc:subject>fNC = New Caledonia</dc:subject><dc:subject>fPP = Papua New Guinea</dc:subject><dc:subject>fRP = Philippines</dc:subject><dc:subject>fRS = Russia</dc:subject><dc:subject>fSR = Serbia</dc:subject><dc:subject>fBP = Solomon Islands</dc:subject><dc:subject>fTU = Turkey</dc:subject><dc:subject>fVE = Venezuela</dc:subject><dct:references scheme="None">http://mrdata.usgs.gov/services/laterite?request=getcapabilities&amp;service=WMS&amp;version=1.1.1&amp;</dct:references><dct:references scheme="None">http://mrdata.usgs.gov/wfs/laterite?request=getcapabilities&amp;service=WFS&amp;version=1.0.0&amp;</dct:references><dct:references scheme=" minerals">http://mrdata.usgs.gov/laterite/laterite-csv.zip</dct:references><dct:modified>2016-02-09</dct:modified><dct:abstract>Location, type, mineralogy, name, tonnage and grade, and geological setting for 120 deposits of this type. The US has no active nickel mines or nickel reserves.</dct:abstract><dc:date>2016-02-09</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>-33.65 -123.44</ows:LowerCorner><ows:UpperCorner>59.71 166.93</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(' ')


1
title:Ni-Co laterite deposits of the world
identifier:31987f20-1f87-4cd7-8dda-1413d67bdc46
modified:2016-02-09
 

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 [ ]: