The sos4R package provides simple yet powerful access to OGC Sensor Observation Service instances. The package supports both encapsulation and abstraction from the service interface for novice users as well as powerful request building for specialists. sos4R is motivated by the idea to close the gap between the Sensor Web and tools for (geo-)statistical analyses. It implements the core profile of the SOS specification and supports temporal, spatial, and thematical filtering of observations.

This document gives a brief overview and demo. Other vignettes dive deeper into the SOS specification and the package’s features are explained extensively: exploration of service metadata, request building with filters, function exchangeability, result data transformation.

The package is published under GPL 2 license within the geostatistics community of 52°North Initiative for Geospatial Open Source Software.


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.


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

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:
  • ioos: Example using SOS by the Integrated Ocean Observing System which provides data in different formats (CSV)
  • oceanwatch: SOS by NOAA Center for Operational Oceanographic Products and Services (CO-OPS) - under construction.
  • pegel: Water gauge data in Germany by Pegelonline, shows how to create an xyplot of a set of variables.

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:

  • method: The transport protocol. Currently available are Key-value-pair (GET), Plain old XML (POST); the default is POX. GET is less powerful, especially regarding filtering operations.
  • version: The service version. Currently available version(s) is/are 1.0.0, 2.0.0.
  • parsers: The list of parsing functions. See vignette “Extending”.
  • encoders: The list of encoding functions. See vignette “Extending”.
  • dataFieldConverters: The list of conversion functions. See vignette “Extending”.
  • timeFormat: The time format to be used or decoding and encoding time character strings to and from POSIXt classes, the default is %Y-%m-%dT%H:%M:%OS%z.
  • verboseOutput: Trigger parameter for extensive debugging information on the console for all requests made to this SOS instance.
  • switchCoordinates: Switches all coordinates that are encountered during the parsing phase, such as in an element like <gml:lowerCorner>117.3 -41.5</gml:lowerCorner>.

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")
#> URL: http://sensorweb.demo.52north.org/sensorwebtestbed/service/kvp
cat("Title:", sosTitle(mySOS), "\n")
#> Title: 52N SOS
cat("Abstract:", sosAbstract(mySOS), "\n")
#> Abstract: 52North Sensor Observation Service - Data Access for the Sensor Web
cat("Version:", sosVersion(mySOS), "\n")
#> Version: 1.0.0
cat("Time format:", sosTimeFormat(mySOS), "\n")
#> Time format: %Y-%m-%dT%H:%M:%OS%z
cat("Binding:", sosBinding(mySOS), "\n")
#> Binding: KVP

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

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

#> Object of class SOS_1.0.0 [KVP, http://sensorweb.demo.52north.org/sensorwebtestbed/service/kvp, 52N SOS]
#> $class
#> [1] "SOS_1.0.0"
#> attr(,"package")
#> [1] "sos4R"
#> $version
#> [1] "1.0.0"
#> $url
#> [1] "http://sensorweb.demo.52north.org/sensorwebtestbed/service/kvp"
#> $binding
#> [1] "KVP"
#> $title
#> [1] "52N SOS"
#> $abstract
#> [1] "52North Sensor Observation Service - Data Access for the Sensor Web"
#> $time
#>                 Length Class  Mode
#> ws2500          2      -none- list
#> ws2500-internal 2      -none- list
#> wwu-ws-kli-hsb  2      -none- list
#> wxt520          2      -none- list
#> $offeringCount
#> [1] 4
#> $procedureCount
#> [1] 4
#> $observedPropCount
#> [1] 43
#> attr(,"class")
#> [1] "summary.SOS_versioned"

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"]]
#> Object of class SosObservationOffering
#> [[id:]]      [1] "wwu-ws-kli-hsb"
#> [[name:]]    [1] NA
#> [[time:]]          Length Class   Mode   
#> begin 1      POSIXct numeric
#> end   1      POSIXct numeric
#> [[bbox:]]    [1] "urn:ogc:def:crs:EPSG::4326, 51.9692611694336 7.59587907791138, 51.9692611694336 7.59587907791138"
#> [[fois:]]    [1] 1
#> [[procs:]]   [1] 1
#> [[obsProps:]]    [1] 13
#> [1] "wwu-ws-kli-hsb"
#> [[1]]
#> [1] "AirTemperature"
#> [[2]]
#> [1] "AthmosphericPressure"
#> [[3]]
#> [1] "Humidity"
#> [[4]]
#> [1] "ShortwaveRadiation"
#> [[5]]
#> [1] "Visibility"
#> [[6]]
#> [1] "WeatherCode"
#> [[7]]
#> [1] "WeatherCode_text"
#> [[8]]
#> [1] "WindDirection"
#> [[9]]
#> [1] "WindDirectionText"
#> [[10]]
#> [1] "WindMaxGust"
#> [[11]]
#> [1] "WindSpeedBft"
#> [[12]]
#> [1] "WindSpeedKmh"
#> [[13]]
#> [1] "WindSpeedMperSec"
#> [[1]]
#> [1] "wwu-ws-kli-hsb"

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(..).

#>  phenomenonTime                AirTemperature  
#>  Min.   :2017-12-01 00:10:00   Min.   :-1.300  
#>  1st Qu.:2017-12-07 16:00:00   1st Qu.: 2.200  
#>  Median :2017-12-15 18:00:00   Median : 4.600  
#>  Mean   :2017-12-15 23:10:21   Mean   : 4.602  
#>  3rd Qu.:2017-12-23 22:10:00   3rd Qu.: 6.700  
#>  Max.   :2017-12-30 23:50:00   Max.   :12.400

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.


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

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

#> Attaching package: 'leafpop'
#> The following objects are masked from 'package:mapview':
#>     popupGraph, popupImage, popupTable

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))