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'
endpoint = 'http://geodata.gov.gr/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 [21]:
val = 'protection'
filter1 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [ filter1 ]

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


10
Ζώνες προστασίας Εθνικού Πάρκου Λιμνοθάλασσας Μεσολογγίου-Αιτωλικού
Zώνες Προστασίας Ορεινού Όγκου Αιγάλεω
Zώνες Προστασίας Ορεινού Όγκου Πάρνηθας
Περιοχές Οικοανάπτυξης
Περιοχές προστατευόμενες από διεθνείς συνθήκες
Μεγανήσι - Αρχαιολογικός χώρος
Ζώνες προστασίας Κρύας Τούμπας
Ελεγχόμενες Κυνηγετικές Περιοχές (e-per.gr)
Εθνικά Πάρκα
Λοιποί Τόποι Περιβαλλοντικού Ενδιαφέροντος (e-per.gr)

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


Zώνες Προστασίας Ορεινού Όγκου Πάρνηθας
Out[34]:
[{'scheme': 'None', 'url': 'http://geodata.gov.gr'}]

In [35]:
csw.request


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

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


Out[36]:
'<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>780ad9bc-e517-42c7-b894-b4648fc3595f</dc:identifier><dc:title>Z&#974;&#957;&#949;&#962; &#928;&#961;&#959;&#963;&#964;&#945;&#963;&#943;&#945;&#962; &#927;&#961;&#949;&#953;&#957;&#959;&#973; &#908;&#947;&#954;&#959;&#965; &#928;&#940;&#961;&#957;&#951;&#952;&#945;&#962;</dc:title><dc:type>dataset</dc:type><dc:subject>Protected sites</dc:subject><dc:subject>&#960;&#940;&#961;&#957;&#951;&#952;&#945;</dc:subject><dc:subject>&#959;&#961;&#949;&#953;&#957;&#959;&#943; &#972;&#947;&#954;&#959;&#953;</dc:subject><dc:subject>&#960;&#961;&#959;&#963;&#964;&#945;&#963;&#943;&#945;</dc:subject><dc:subject>&#949;&#965;&#945;&#943;&#963;&#952;&#951;&#964;&#951; &#960;&#949;&#961;&#953;&#959;&#967;&#942;</dc:subject><dc:subject>&#959;&#961;&#963;&#945;</dc:subject><dc:subject>&#960;&#961;&#959;&#963;&#964;&#945;&#964;&#949;&#965;&#972;&#956;&#949;&#957;&#949;&#962;-&#960;&#949;&#961;&#953;&#959;&#967;&#941;&#962;</dc:subject><dct:references scheme="None">http://geodata.gov.gr</dct:references><dct:modified>2011-10-19</dct:modified><dct:abstract>&#928;&#949;&#961;&#953;&#941;&#967;&#959;&#957;&#964;&#945;&#953; &#964;&#945; &#964;&#945; &#972;&#961;&#953;&#945; &#964;&#969;&#957; &#950;&#969;&#957;&#974;&#957; &#960;&#961;&#959;&#963;&#964;&#945;&#963;&#943;&#945;&#962; &#964;&#959;&#965; &#959;&#961;&#949;&#953;&#957;&#959;&#973; &#972;&#947;&#954;&#959;&#965; &#964;&#951;&#962; &#928;&#940;&#961;&#957;&#951;&#952;&#945;&#962;. &#927;&#953; &#950;&#974;&#957;&#949;&#962; &#960;&#961;&#959;&#963;&#964;&#945;&#963;&#943;&#945;&#962; &#964;&#959;&#965; &#959;&#961;&#949;&#953;&#957;&#959;&#973; &#972;&#947;&#954;&#959;&#965; &#964;&#951;&#962; &#928;&#940;&#961;&#957;&#951;&#952;&#945;&#962; &#954;&#945;&#952;&#959;&#961;&#943;&#950;&#959;&#957;&#964;&#945;&#953; &#945;&#960;&#972; &#964;&#959; &#928;.&#916;. &#934;&#917;&#922; 619&#916;/2008. &#919; &#954;&#955;&#953;&#956;&#945;&#954;&#945; &#968;&#951;&#966;&#953;&#959;&#960;&#959;&#943;&#951;&#963;&#951;&#962; &#949;&#943;&#957;&#945;&#953; 1:30000.</dct:abstract><dc:date>2011-10-19</dc:date><dc:rights>otherRestrictions</dc:rights><ows:BoundingBox crs="urn:x-ogc:def:crs:EPSG:6.11:4326" dimensions="2"><ows:LowerCorner>38.08 23.53</ows:LowerCorner><ows:UpperCorner>38.26 23.85</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 [14]:
bbox = [20.6, 36.6, 24.6, 39.6]    # [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 [15]:
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(' ')


10
title:Ζώνες προστασίας Εθνικού Πάρκου Λιμνοθάλασσας Μεσολογγίου-Αιτωλικού
identifier:3037619f-fa50-4a98-9e75-e83da20c19ad
modified:2015-04-21
 
title:Zώνες Προστασίας Ορεινού Όγκου Αιγάλεω
identifier:6ba4fac8-8499-40be-b9a4-e5ea579ee9c3
modified:2010-09-22
 
title:Zώνες Προστασίας Ορεινού Όγκου Πάρνηθας
identifier:780ad9bc-e517-42c7-b894-b4648fc3595f
modified:2011-10-19
 
title:Περιοχές Οικοανάπτυξης
identifier:124b95bd-7b18-41f7-ba45-fa950797b120
modified:2011-10-19
 
title:Περιοχές προστατευόμενες από διεθνείς συνθήκες
identifier:20f5f4ad-c456-40ac-b031-81b8d4fca010
modified:2011-10-19
 
title:Μεγανήσι - Αρχαιολογικός χώρος
identifier:8684f4be-881c-4b20-b5ac-12b7a9ed50f1
modified:2015-08-04
 
title:Ζώνες προστασίας Κρύας Τούμπας
identifier:e46bae43-0c45-4269-bb42-4470424ccf94
modified:2015-04-16
 
title:Ελεγχόμενες Κυνηγετικές Περιοχές (e-per.gr)
identifier:12e4e303-6fe8-4f95-b1cb-991b0c3b6c92
modified:2010-09-20
 
title:Εθνικά Πάρκα
identifier:7346d3cd-f237-44a6-a50f-d7de6596f29e
modified:2011-10-19
 
title:Λοιποί Τόποι Περιβαλλοντικού Ενδιαφέροντος (e-per.gr)
identifier:3ebfe61a-802c-4f79-8714-1bee9d322c19
modified:2010-09-21
 

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