CSW made simple

The nationaal georegister (NGR) asked us to develop a simple way for third parties to use NGR’s catalogue service. NGR implemented geonetwork as their catalogue-software and it supports CSW v2.0.2. As such anyone or anything that talks CSW can already use NGR’s service. With CSW you can search the NGR database for online geo-information. This could be useful for developers who want to add relevant maps to their websites.

However, CSW is a complex, XML based standard which takes quite some time to understand and implement. Also, being XML it is subject to the security model of browsers, which forces the developer to setup a proxy on their server. This means that it isn’t very easy for a developer to use NGR in their website. CSW supports many different query parameters and returns a lot of meta data, which are important for GIS professionals, but not necessarily for casual users.

To simplify this powerful tool we decided to leave the XML on the server and talk JSON to the client. We created a CSWTransformer service where you can send in one query string and it gives you back a JSON object with the results. The query string only searches in the abstract and title fields of the database and only those which are actual WMS services. Since it is a JSON object it is possible to bypass the browser’s security and directly get the object from a different source than the webserver of the html page.

The trick to do this is to dynamically add a script to the webpage:

var script = document.createElement("script");
script.setAttribute("src", ngrUrl+"?url="+cswUrl+"&search="+keyword+"&callback="+callback);
script.setAttribute("type", "text/javascript");
script.setAttribute("id", "ngrZoekScript");
head.appendChild(script);

It is important to have a callback function, which will be executed after the response gets in. The response looks like this:
showResponse(

{ "response":
{ "records":
[{"wmsurl": "http://gdsc.nlr.nl/wms/lufo2005?",
"name": "lufo2005-1m",
"title": "Aerodata luchtfotobedekking Nederland 2005"},
{"wmsurl": "http://geoservice.pbl.nl/wmsconnector/com.esri.wms.Esrimap/GCN_2009_o3_2008",
"name": "Mapservice layers",
"title": "GCN concentratie ozon (O3) 2008"}]
}})

In the webpage there’s a function showResponse which parses this response and displays the result. This way a developer only has to include two javascript functions: getNGRRecords() and showResponse() and a simple search form and he can search for WMS’s in NGR. See also this example.

Leave a Reply