OGC CSW query examples


Sometimes you need to talk machine talk to find out what data is available in a public OGC CSW compliant service.
First you need to examine the GetCapabilities request response.
After that you may want to know how many records are in a particular CSW catalogue.

You can do that by using this query:

<?xml version="1.0" encoding="UTF-8"?>
<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2"  resultType="hits">
  <csw:Query typeNames="csw:Record">
  </csw:Query>
</csw:GetRecords>

NOTE: I highlighted the resultType because that is what determines the type of the response that you get from the service. It tells the service that you want to know the number of the results that match your query and because the query is empty it will be all records. In SQL this would look something like select count(*) from table.


Then you may want to download the metadata records:

 <?xml version="1.0" encoding="UTF-8"?>
<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2"  resultType="results" startPosition="1" maxRecords="5">
  <csw:Query typeNames="csw:Record">
<csw:ElementSetName>full</csw:ElementSetName>
  </csw:Query>
</csw:GetRecords>

I added here startPosition that means starting form the first record, maxRecords that determines the number of records you get back by the query and ElementSetName that tells the service to send you back the full metadata. Using this query you can page through all the data that is stored in a catalogue.

Reference:

CSW Implementation Specification

Comments

Popular posts from this blog

The biggest java security vulnerability of 2021