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:


getCapRequest <- '<?xml version="1.0" encoding="UTF-8"?><GetCapabilities xmlns="" xmlns:ows="" xmlns:ogc="" xmlns:xsi="" xsi:schemaLocation="" 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 = "",
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("", 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: 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
url = ";version=1.0.0&amp;service=SOS",
destfile = "caps.xml")

# using RCurl
caps <- getURL(";version=1.0.0&amp;service=SOS")