woudc-total-ozone.xml
, the following works for me :from owslib.csw import CatalogueServiceWeb
f = 'woudc-total-ozone.xml'
csw = CatalogueServiceWeb('http://localhost:8000')
csw.transaction(ttype='insert', typename='gmd:MD_Metadata', record=open(f).read())
pycsw
) endpoint using owslib
- following the docs I tried the following query (which works):from owslib.csw import CatalogueServiceWeb
from owslib.fes import PropertyIsEqualTo, PropertyIsLike, BBox
endpoint = 'https://csw.epinux.com/'
csw = CatalogueServiceWeb(endpoint,timeout=30)
csw.version
# prints out:
# '2.0.2'
[op.name for op in csw.operations]
# prints out:
"""
['GetCapabilities',
'DescribeRecord',
'GetDomain',
'GetRecords',
'GetRecordById',
'GetRepositoryItem',
'Transaction',
'Harvest']
"""
csw.getdomain('GetRecords.resultType')
csw.results
# prints out:
"""
{'type': 'csw:Record',
'parameter': 'GetRecords.resultType',
'values': ['hits', 'results', 'validate']}
"""
sentinel_query = PropertyIsEqualTo('csw:AnyText', 'sentinel')
csw.getrecords2(constraints=[sentinel_query], maxrecords=20)
csw.results
# prints out:
"""
{'matches': 442291, 'returned': 10, 'nextrecord': 11}
"""
and:
for rec in csw.records:
print(csw.records[rec].title)
returns the expected values.
however, when I run the following:
bbox_query = BBox([-141,42,-52,84])
csw.getrecords2(constraints=[sentinel_query, bbox_query])
it returns the following exception:
---------------------------------------------------------------------------
ExceptionReport Traceback (most recent call last)
<ipython-input-138-0a44e99fbd69> in <module>
----> 1 csw.getrecords2(constraints=[sentinel_query, bbox_query])
/usr/lib/python3/dist-packages/owslib/csw.py in getrecords2(self, constraints, sortby, typenames, esn, outputschema, format, startposition, maxrecords, cql, xml, resulttype)
377 self.request = node0
378
--> 379 self._invoke()
380
381 if self.exceptionreport is None:
/usr/lib/python3/dist-packages/owslib/csw.py in _invoke(self)
709 val = self._exml.find(util.nspath_eval('ows:Exception', namespaces))
710 if val is not None:
--> 711 raise ows.ExceptionReport(self._exml, self.owscommon.namespace)
712 else:
713 self.exceptionreport = None
ExceptionReport: 'Invalid query syntax'
root@874f513999fd:~# pip3.8 install -U owslib
Requirement already up-to-date: owslib in /usr/lib/python3/dist-packages (0.20.0)
WARNING: You are using pip version 20.2.2; however, version 20.2.3 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.
root@874f513999fd:~#
why thius query:
from owslib.csw import CatalogueServiceWeb
from owslib.fes import PropertyIsEqualTo, PropertyIsLike, BBox
endpoint='https://csw.epinux.com'
csw = CatalogueServiceWeb(endpoint,timeout=30)
bbox=[2,50,15,70]
bbox_query = BBox(bbox)
equalTo_query = [PropertyIsEqualTo('csw:AnyText', 'sentinel')]
csw.getrecords2(constraints=[equalTo_query, bbox_query], maxrecords=20)
returns 10 records
while this one:
csw.getrecords2(constraints=[bbox_query], maxrecords=20)
returns 0
csw.getrecords2(constraints=equalTo_query, maxrecords=20)
compared with csw.getrecords2(constraints=[equalTo_query, bbox_query], maxrecords=20)
getrecords2
function:from owslib.csw import CatalogueServiceWeb
from owslib.fes import PropertyIsEqualTo, PropertyIsLike, BBox
endpoint='https://csw.epinux.com'
csw = CatalogueServiceWeb(endpoint,timeout=30)
bbox=[2,50,15,70]
bbox_query = BBox(bbox)
equalTo_query = PropertyIsEqualTo('csw:AnyText', 'sentinel')
csw.getrecords2(constraints=[[equalTo_query, bbox_query]], maxrecords=20)
print(csw.request)
print(csw.results)
csw.getrecords2(constraints=[bbox_query], maxrecords=20)
print(csw.request)
print(csw.results)
thanks! I think I am getting there, thanks for the working example :) - now dealing with the extraction of the extent for each dataset - I got it with something like:
for rec in csw.records:
bbox = vars(csw.records[rec].bbox)
which I'm gonna use to create a geojson feature.
I am not quite sure about how to work with the generator returned by the query.
I can get the first 10 records .. but how to access the next in the results? Do I need to repeat the query by changing the startposition
parameter .. until I get all of them?
say, csw.results
gives me:
{'matches': 274536, 'returned': 10, 'nextrecord': 11}
I can get the values for the first "returned" 10 elements, by looping over it, like:
for rec in csw.records:
appendJsonFeature(name = csw.records[rec].identifiers,
geom = vars(csw.records[rec].bbox))
How to get the next 10 ,, and so on .. ?
do I need to re-issue the query, like:
startposition = csw.results['nextrecord']
csw.getrecords2(constraints=[[equalTo_query, bbox_query]], maxrecords=20, esn='full', startposition=startposition)
until startposition reaches the 'matches' records?
Hi all: FYI 0.21.0 has been released: https://lists.osgeo.org/pipermail/owslib-users/2020-December/000194.html
Thanks for everyone’s contributions and @cehbrecht for continued support.