Query apiso:ServiceType on data.gov pycsw


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

In [32]:
#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'
endpoint = 'http://geodata.gov.gr/csw'
csw = CatalogueServiceWeb(endpoint,timeout=60)
print csw.version


2.0.2

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


Out[33]:
[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 [34]:
try:
    csw.get_operation_by_name('GetDomain')
    csw.getdomain('apiso:ServiceType', 'property')
    print(csw.results['values'])
except:
    print('GetDomain not supported')


[None]

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

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


0

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


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-46-867dc78a1150> in <module>()
----> 1 choice=np.random.choice(list(csw.records.keys()))
      2 print(csw.records[choice].title)
      3 csw.records[choice].references

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

ValueError: a must be non-empty

In [27]:
csw.request


Out[27]:
'<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>*DATA*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter></csw:Constraint></csw:Query></csw:GetRecords>'

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


Out[28]:
'<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:rim="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.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" xmlns:wrs="http://www.opengis.net/cat/wrs/1.0"><dc:identifier>35166d2e-e8db-11e4-a29e-005056822e38</dc:identifier><dc:title>Iran Lakes</dc:title><dc:type>dataset</dc:type><dc:subject>lakes</dc:subject><dc:subject>polygon</dc:subject><dc:subject>hydrography</dc:subject><dc:subject>seas</dc:subject><dc:subject>inlandWaters</dc:subject><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wms?layers=geonode%3Airn_hyd_lakes&amp;width=426&amp;bbox=45.009735107%2C37.024032593%2C45.9764328%2C38.269702911&amp;service=WMS&amp;format=image%2Fjpeg&amp;srs=EPSG%3A4326&amp;request=GetMap&amp;height=550</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wms?layers=geonode%3Airn_hyd_lakes&amp;width=426&amp;bbox=45.009735107%2C37.024032593%2C45.9764328%2C38.269702911&amp;service=WMS&amp;format=application%2Fpdf&amp;srs=EPSG%3A4326&amp;request=GetMap&amp;height=550</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wms?layers=geonode%3Airn_hyd_lakes&amp;width=426&amp;bbox=45.009735107%2C37.024032593%2C45.9764328%2C38.269702911&amp;service=WMS&amp;format=image%2Fpng&amp;srs=EPSG%3A4326&amp;request=GetMap&amp;height=550</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wfs?format_options=charset%3AUTF-8&amp;typename=geonode%3Airn_hyd_lakes&amp;outputFormat=SHAPE-ZIP&amp;version=1.0.0&amp;service=WFS&amp;request=GetFeature</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wfs?typename=geonode%3Airn_hyd_lakes&amp;outputFormat=gml2&amp;version=1.0.0&amp;request=GetFeature&amp;service=WFS</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wfs?typename=geonode%3Airn_hyd_lakes&amp;outputFormat=text%2Fxml%3B+subtype%3Dgml%2F3.1.1&amp;version=1.0.0&amp;request=GetFeature&amp;service=WFS</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wfs?typename=geonode%3Airn_hyd_lakes&amp;outputFormat=csv&amp;version=1.0.0&amp;request=GetFeature&amp;service=WFS</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wfs?typename=geonode%3Airn_hyd_lakes&amp;outputFormat=excel&amp;version=1.0.0&amp;request=GetFeature&amp;service=WFS</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wfs?srsName=EPSG%3A4326&amp;typename=geonode%3Airn_hyd_lakes&amp;outputFormat=json&amp;version=1.0.0&amp;service=WFS&amp;request=GetFeature</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wms/kml?layers=geonode%3Airn_hyd_lakes&amp;mode=download</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wms/kml?layers=geonode%3Airn_hyd_lakes&amp;mode=refresh</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/gwc/service/gmaps?layers=geonode:irn_hyd_lakes&amp;zoom={z}&amp;x={x}&amp;y={y}&amp;format=image/png8</dct:references><dct:references scheme="WWW:LINK-1.0-http--link">http://geonode.wfp.org/layers/geonode%3Airn_hyd_lakes</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wms/reflect?layers=geonode:irn_hyd_lakes&amp;width=200&amp;height=150&amp;format=image/png8</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/uploaded/thumbs/layer-35166d2e-e8db-11e4-a29e-005056822e38-thumb.png</dct:references><dct:references scheme="WWW:DOWNLOAD-1.0-http--download">http://geonode.wfp.org/geoserver/wms?request=GetLegendGraphic&amp;format=image/png&amp;WIDTH=20&amp;HEIGHT=20&amp;LAYER=geonode:irn_hyd_lakes&amp;legend_options=fontAntiAliasing:true;fontSize:12;forceLabels:on</dct:references><dct:references scheme="OGC:WMS">http://geonode.wfp.org/geoserver/geonode/wms</dct:references><dct:references scheme="OGC:WFS">http://geonode.wfp.org/geoserver/geonode/wfs</dct:references><dct:modified>2007-11-04</dct:modified><dct:abstract>World Lakes represents the major lakes and inland seas within the world.</dct:abstract><dc:date>2007-11-04</dc:date><dc:language>eng</dc:language><ows:BoundingBox crs="urn:x-ogc:def:crs:EPSG:6.11:4326" dimensions="2"><ows:LowerCorner>37.024032593 45.009735107</ows:LowerCorner><ows:UpperCorner>38.269702911 45.9764328</ows:UpperCorner></ows:BoundingBox></csw:Record>'

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


---------------------------------------------------------------------------
ExceptionReport                           Traceback (most recent call last)
<ipython-input-30-1f720cf77c2a> in <module>()
      3                         escapeChar='\\',wildCard='*',singleChar='?')
      4 filter_list = [fes.And([filter1, filter2])]
----> 5 csw.getrecords2(constraints=filter_list, maxrecords=1000)

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/owslib/csw.pyc in getrecords2(self, constraints, sortby, typenames, esn, outputschema, format, startposition, maxrecords, cql, xml, resulttype)
    366             self.request = node0
    367 
--> 368         self._invoke()
    369 
    370         if self.exceptionreport is None:

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/owslib/csw.pyc in _invoke(self)
    686         val = self._exml.find(util.nspath_eval('ows:Exception', namespaces))
    687         if val is not None:
--> 688             raise ows.ExceptionReport(self._exml, self.owscommon.namespace)
    689         else:
    690             self.exceptionreport = None

ExceptionReport: 'Invalid query: column "servicetype" does not exist\nLINE 1: ...esourcebase" WHERE (csw_anytext like \'%DATA%\' and servicetyp...\n                                                             ^'

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 [50]:
val = 'wms'
filter2 = fes.PropertyIsLike(propertyname='apiso:ServiceType',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [filter2]
csw.getrecords2(constraints=filter_list, maxrecords=1000)

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