Archives for posts with tag: RCurl

This week I made the first steps to support POST requests to the SOS. I was happy with my architecture, because I only had to figure out how to use the method postForm of the package RCurl, and after some debugging in a SOS instance I set the style variable to post (how surprising!) and successfully requested capabilities and sensor descriptions.

You can try out the following code yourself:


library("RCurl")

getCapRequest <- '<?xml version="1.0" encoding="UTF-8"?><GetCapabilities xmlns="http://www.opengis.net/sos/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosGetCapabilities.xsd" service="SOS"><ows:AcceptVersions><ows:Version>1.0.0</ows:Version></ows:AcceptVersions><ows:Sections><ows:Section>OperationsMetadata</ows:Section><ows:Section>ServiceIdentification</ows:Section><ows:Section>ServiceProvider</ows:Section><ows:Section>Filter_Capabilities</ows:Section><ows:Section>Contents</ows:Section></ows:Sections></GetCapabilities>'

# using 'post' as style for application/x-www-form-urlencoded content
caps.response <- postForm(uri = "http://v-swe.uni-muenster.de:8080/WeatherSOS2/sos",
request = getCapRequest,
style = "POST",
.encoding = "UTF-8")

And this is how the same thing looks like when using sos4R (sadly you cannot run this one just yet):


# GetCapabilities
sos = SOS("http://v-swe.uni-muenster.de:8080/WeatherSOS2/sos", method = "POST")
caps = sosCaps(sos)

# DescribeSensor
procedures = sosProcedures(sos)
sensor.10 <- describeSensor(sos = sos, procedure = procedures[10:12], verbose = TRUE)

In this case, the variable caps does not contain XML as a character string, but a S4 class holding important content of the capabilities document as list/slots/et cetera.

Now I’ll continue with the implementation of the (most important) operation GetObservation and then try out some SOAP…

What is KVP – encoding? An OGC forum entry gives an answer, and Wikipedia gives some background. But what is it for the Sensor Observation Service? Well, first of all it is a promised, but undocumented feature! Why is it a promise? Because it is mentioned in section 8.1 of the SOS specification:

Clauses 8, 9, and 10 define the XML encodings for SOS operations. Clause 11 defines the KVP form of each of the operations.

But if you look in the contents section, there simply is not clause 11!

Luckily some people noticed. Eventually, the folks from the OOSTethys project created a best practice documentation of a key value pair encoding for the core SOS operations, which is also implemented by the 52° North SOS: http://www.oostethys.org/best-practices/best-practices-get. The website explains well the background (HTTP, GET et cetera) and the specifications they rely on.

Does it work? To simply receive a capabilities document from a sensor observation service that supports GET and key-value pairs (like the 52° North SOS), just do the following in R:

# using download to file
download.file(
url = "http://giv-sos.uni-muenster.de:8080/52nSOSv3/sos?request=GetCapabilities&amp;version=1.0.0&amp;service=SOS",
destfile = "caps.xml")

# using RCurl
library(RCurl)
caps <- getURL("http://giv-sos.uni-muenster.de:8080/52nSOSv3/sos?request=GetCapabilities&amp;version=1.0.0&amp;service=SOS")
print(caps)