sos4R

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  concordance = TRUE
)

Introduction

The sos4R package provides classes and methods for retrieving data from an Open Geospatial Consortium (OGC) Sensor Observation Service in version 1.0.0 (Na, 2007) and 2.0 (Bröring, 2010). The goal of this package is to provide easy access with a low entry threshold for everyone to information available via SOSs. The complexity of the service interface shall be shielded from the user as much as possible, while still leaving enough possibilities for advanced users. The output is a standard data.frame with attributed columns for the rich metadata provided by the SOS API. This package uses S4 classes and methods style (Chambers, 1998).

The package was born out of perceiving a missing link between the Sensor Web community (known as Sensor Web Enablement (SWE) Initiative in the OGC realm) and the community of (geo-)statisticians (Nüst, 2011). While the relatively young SWE standards get adopted more by data owners (like governmental organizations), we see a high but unused potential for more open data and spatio-temporal analyses based on it. sos4R can help enabling this.

The project is part of the geostatistics community of the 52°North Initiative for Geospatial Open Source Software. sos4R is available on CRAN.

On the package home page, https://52north.github.io/sos4R, you can stay updated with the developments and find example code and services.

This software is released under a GPL 2 license and contributions are very welcome---please see the file DEV-README.md in the package code repository.

library("sos4R")

Getting started

Cheat sheet

The package comes with a one page quick reference card, also known as a "cheat sheet", which shows everything that you need to know in an extremely concise manner. You can open the document by loading the package and calling

sosCheatSheet()

The most useful functions are highlighted in bold font.

Demos and services

The demos are a good way to get started with the package. Please be aware that you need an internet connection for these demos, the used SOSs might be temporarily unavailable or not available anymore.

# list available demos:
demo(package = "sos4R")
# run a demo:
demo("airquality")

There also is an incomplete list of services that have been tested or are currently evaluated on in a vignette. If you find or can provide new SOS with data useful to others, please do not hesitate to open an issue to have it added. Please note that the sos4R team of this document does not control these services and does not guarantee for any factors like correctness of data or availability.

Creating a SOS connection

The method SOS() is a construction method for classes encapsulating a connection to a SOS. It prints out a short statement when the connection was successfully established (i.e. the capabilities document was received) and returns an object of class SOS.

mySOS <- SOS(url = "http://sensorweb.demo.52north.org/sensorwebtestbed/service/kvp", binding = "KVP")

To create a SOS connection you only need the URL of the service (i.e. the URL endpoint which can be used for HTTP requests). The service connection created above is used for all examples throughout this document.

All parameters except the service endpoint are optional and use default settings:

There are accessor methods for the slots of the class. The encoders, parsers and converters are described extensively in the vignette "Extending".

cat("URL:", sosUrl(mySOS), "\n")
cat("Title:", sosTitle(mySOS), "\n")
cat("Abstract:", sosAbstract(mySOS), "\n")
cat("Version:", sosVersion(mySOS), "\n")
cat("Time format:", sosTimeFormat(mySOS), "\n")
cat("Binding:", sosBinding(mySOS), "\n")

You can also access the used encoding, decoding, and conversion functions (extensive output not included here).

sosEncoders(mySOS)
sosParsers(mySOS)
sosDataFieldConverters(mySOS)

Print and summary methods are available for important classes, like SOS.

mySOS
summary(mySOS)

Get Data

The GetObservation operation is the main data download request of the SOS, and the package's functional equivalent is getObservation(..). You can build a request using the information from the offerings, as they are extracted from the capabilities document when a new connection is created.

off.1 <- sosOfferings(mySOS)[["wwu-ws-kli-hsb"]]
summary(off.1)
sosProcedures(off.1)
sosObservedProperties(off.1)
sosFeaturesOfInterest(off.1)

Not all combinations of procedure, observed property, feature of interest, and event time will deliver a result, but the following one should.

obs.1 <- getObservation(sos = mySOS,
  offering = off.1,
  procedure = sosProcedures(off.1)[[1]],
    observedProperty = sosObservedProperties(off.1)[1],
    eventTime = sosCreateTime(sos = mySOS, time = "2017-12-01::2017-12-31"))

You can then access the result data with the helper function sosResult(..).

#sosResult(data)
summary(sosResult(obs.1))

Spatial Data

Classes with spatial information, i.e. coordinates, have coercion functions to matching sp classes and can therefore be easily rendered on a map, e.g. using leaflet.

library("leaflet")

obs.1.spatial <- as(obs.1, "Spatial")
leaflet::leaflet(obs.1.spatial) %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers() %>%
  addMiniMap()

Using the mapview package you can quickly add plots into pop-up windows.

library("mapview")
library("leafpop")

plotfile <- tempfile(fileext = ".png")
png(filename = plotfile)
plot(x = obs.1.spatial$phenomenonTime, y = obs.1.spatial$AirTemperature,
     pch = 20,
     main = sosId(off.1), xlab = "Time", ylab = "Air Temperature")

#FIXME:mapview(obs.1.spatial, popup = leafpop::popupImage(plotfile, embed = TRUE))
mapview(obs.1.spatial)

For more details on the coercion functions see ?`coerce-sos4R`.

Inspect Requests and Verbose Printing

The package offers two levels of inspection of the ongoing operations indicated by two boolean parameters, inspect and verbose. These are available in all service operation calls.

The option verboseOutput when using the method SOS() turns on the verbose setting for all subsequent requests made to the created connection unless deactivated in an operation call.

obs.1 <- getObservation(sos = mySOS, offering = off.1,
    procedure = sosProcedures(off.1)[[1]],
    observedProperty = sosObservedProperties(off.1)[1],
    eventTime = sosCreateTime(sos = mySOS, time = "2017-12-19::2017-12-20"),
    inspect = TRUE)
getObservation(sos = mySOS, offering = off.1,
    procedure = sosProcedures(off.1)[[1]],
    observedProperty = sosObservedProperties(off.1)[2],
    eventTime = sosCreateTime(sos = mySOS, time = "2018-01-01::2018-01-03"),
    verbose = TRUE)

By using verboseOutput you can also debug the automatic GetCapabilities operation when creating a new SOS connection. That output is too extensive to show within this document.

verboseSOS <- SOS(sosUrl(mySOS),
                  verboseOutput = TRUE,
                  binding = sosBinding(mySOS),
                  dcpFilter = mySOS@dcpFilter)

Support

Feel free to ask questions about using the software or report a bug at the project issue tracker: https://github.com/52North/sos4R/issues. There you can also find existing bug reports and planned features.

Acknowledgements

The start of the project was generously supported by the 52°North Student Innovation Prize for Geoinformatics 2010. Thanks go also to Edzer Pebesma for contributing analyses to the demos at an early stage.

Outlook

In future releases a tighter integration is planned with the sf package regarding output data structures and classes.

References



Try the sos4R package in your browser

Any scripts or data that you put into this service are public.

sos4R documentation built on July 9, 2020, 5:07 p.m.