In [1]:
In [32]:
endpoint = 'http://localhost:8082/csw'
# connect to CSW, explore it's properties
#endpoint = 'http://www.ngdc.noaa.gov/geoportal/csw' # NGDC Geoportal
#endpoint = 'http://data.nodc.noaa.gov/geoportal/csw' # NODC Geoportal: collection level
#endpoint = 'http://geodiscover.cgdi.ca/wes/serviceManagerCSW/csw' # NRCAN CUSTOM
#endpoint = 'http://geoport.whoi.edu/gi-cat/services/cswiso' # USGS Woods Hole GI_CAT
#endpoint = 'http://cida.usgs.gov/gdp/geonetwork/srv/en/csw' # USGS CIDA Geonetwork
#endpoint = 'http://www.nodc.noaa.gov/geoportal/csw' # NODC Geoportal: granule level
In [31]:
from owslib.csw import CatalogueServiceWeb
from owslib import fes
csw = CatalogueServiceWeb('http://localhost:8082/csw')
In [2]:
csw.identification.type
csw.version
Out[2]:
In [3]:
[op.name for op in csw.operations]
Out[3]:
In [4]:
csw.getrecords2()
csw.results
Out[4]:
In [5]:
from owslib.fes import PropertyIsEqualTo, PropertyIsLike, BBox
In [6]:
csw.getrecords2(maxrecords=5)
csw.results
Out[6]:
In [18]:
test_query = PropertyIsEqualTo('csw:AnyText', 'test')
csw.getrecords2(constraints=[test_query], maxrecords=20)
csw.results
Out[18]:
In [35]:
def displayrecords(url):
try:
csw = CatalogueServiceWeb(url)
csw.getrecords2()
csw.results
for rec in csw.records:
print csw.records[rec].title
except:
print 'something went wrong'
In [36]:
displayrecords(endpoint)
In [46]:
for rec,item in csw.records.iteritems():
print rec
print item.abstract
print item.modified
print item.subjects
print item.title
print item.format
print item.creator
print item.type
print '-----------------------------------------'
In [41]:
print(csw.records.keys())
In [22]:
# changed template to use "type" element
#
#csw.transaction(ttype="insert", typename='csw:Record', record=str(record))
from mako.template import Template
import uuid
def publish(my_csw, record):
from os.path import join, dirname
record['identifier'] = uuid.uuid4().get_urn()
templ_dc = Template(filename="dublin_core.xml")
my_csw.transaction(ttype="insert", typename='csw:Record', record=str(templ_dc.render(**record)))
record = {}
record["keywords"]='test,service'
record["abstract"]='test publication 1 dummy + type'
record['title']='testpub2'
record['format']='ws'
record['creator']='Stephan Kindermann'
record['source']='manual ingest'
record['rights']='open'
record['type']='service'
In [18]:
print record
In [23]:
publish(csw,record)
In [47]:
csw.getrecords2(cql='csw:AnyText like "%testtt%"')
csw.results
Out[47]:
Links