This document describes how to use OCTOPUS WFS through R software 1 environment – a free, open-source, reproducible and highly versatile way of data access.
OCTOPUS (https://octopusdata.org) is a geospatial open access database of sedimentological, archaeological, and paleo-environmental ages and process rate determinations, organised into thematic data collections. These data can be viewed and exported through a bespoke web interface 2 or accessed directly. For the latter, OCTOPUS database provides OGC compliant web feature service (WFS) allowing users to access database content via third party software such as Geographic Information Systems (GIS) 3, or R language. OCTOPUS data is served by GeoServer 4, an open server solution for sharing geospatial data. Unless data from OCTOPUS is explicitly downloaded and locally stored by the user, it will remain cloud-borne 5, so the user will not have to care about data storage and being up-to-date.
Geospatial and location information development and standardisation
globally is overseen by the Open Geospatial Consortium (OGC) 6. Web
Feature Service (WFS) is an OGC interface standard that enables platform
independent requests for spatial features across the internet. This is
accomplished by Geography Markup Language (GML), an XML derivative.
Unlike for WMS (Web Map Service), where immutable map tiles are
returned, WFS vector entities can be queried, altered, and spatially
analysed.
WFS functionality knows three basal operations -
GetCapabilities
, DescribeFeatureType
, and
GetFeature
. Calling GetCapabilities will generate
a standardised, human readable meta-dataset that describes a WFS service
and its functionality. DescribeFeatureType produces an overview
of supported feature types, and GetFeature fetches features
including their geometry and attribite values, i.e, variable fields.
The below demo R script fetches, via WFS, spatial layers including rich attribute data from OCTOPUS database and generates a scatter plot (Plot 1) and an interactive map representation (Plot 2), respectively.
Note - The script requires the below packages. If not installed on your machine yet, run
# install.packages(c("sf","httr","tidyverse","ows4R","viridis", "mapview", dependencies = TRUE))
and you’ll be all set up.
First we’re going to load the required packages
library(sf) # Simple features support (sf = standardized way to encode spatial vector data)
library(httr) # Generic web-service package for working with HTTP
require(tidyverse) # Workhorse collection of R packages for data sciences
library(ows4R) # Interface for OGC web-services incl. WFS
library(viridis) # Predefined colorblind-friendly color scales for R
OK, we’re ready to go now.
In the following we store the OCTOPUS WFS URL in an object.
Then, using the latter, we establish a connection to OCTOPUS
database.
OCTOPUSdata <- "http://geoserver.octopusdata.org/geoserver/wfs" # store url in object
OCTOPUSdata_client <- WFSClient$new(OCTOPUSdata, serviceVersion = "2.0.0") # connection to db
Let’s see what is there, i.e. show all available layer names and titles
OCTOPUSdata_client$getFeatureTypes(pretty = TRUE) # show available layers and titles
## name
## 1 be10-denude:crn_aus_basins
## 2 be10-denude:crn_aus_outlets
## 3 be10-denude:crn_int_basins
## 4 be10-denude:crn_int_outlets
## 5 be10-denude:crn_xxl_basins
## 6 be10-denude:crn_xxl_outlets
## 7 be10-denude:crn_inprep_basins
## 8 be10-denude:crn_inprep_outlets
## 9 be10-denude:publications
## 10 opengeo:countries
## 11 be10-denude:expage
## 12 be10-denude:fossahul_webmercator_nrand_25000
## 13 be10-denude:sahularch_osl
## 14 be10-denude:sahularch_c14
## 15 be10-denude:sahularch_tl
## 16 be10-denude:sahulsed_aeolian_osl
## 17 be10-denude:sahulsed_aeolian_tl
## 18 be10-denude:sahulsed_fluvial_osl
## 19 be10-denude:sahulsed_fluvial_tl
## 20 be10-denude:sahulsed_lacustrine_osl
## 21 be10-denude:sahulsed_lacustrine_tl
## title
## 1 CRN Australian collection: River basins
## 2 CRN Australian collection: Sample sites
## 3 CRN Global collection: River basins
## 4 CRN Global collection: Sample sites
## 5 CRN Large basins: River basins
## 6 CRN Large basins: Sample sites
## 7 CRN UOW (in preparation): River basins
## 8 CRN UOW (in preparation): Sample sites
## 9 CRN basin bounding boxes
## 10 Countries of the World
## 11 ExpAge Database
## 12 FosSahul Database
## 13 Sahul Archaeology: OSL collection
## 14 Sahul Archaeology: Radiocarbon collection
## 15 Sahul Archaeology: TL collection
## 16 Sahul Sedimentary Archives: Aeolian OSL
## 17 Sahul Sedimentary Archives: Aeolian TL
## 18 Sahul Sedimentary Archives: Fluvial OSL
## 19 Sahul Sedimentary Archives: Fluvial TL
## 20 Sahul Sedimentary Archives: Lacustrine OSL
## 21 Sahul Sedimentary Archives: Lacustrine TL
That’s basically it. Talking to the database via WFS
takes three short lines of code. Everything below this line does not
deal with data access anymore, but with data presentation.
BTW A full description of OCTOPUS database and its collections can be
found in a dedicated Earth Systems Science
Data publication.
Here we fetch and plot Australian catchment-averaged 10Be denudation rates (i.e., layer ‘be10-denude:crn_aus_basins’ from the above list)
url <- parse_url(OCTOPUSdata) # parse URL into list
url$query <- list(service = "wfs",
version = "2.0.0",
request = "GetFeature",
typename = "be10-denude:crn_aus_basins",
srsName = "EPSG:900913") # set parameters for url$query
request <- build_url(url) # build a request URL from 'url' list
CRN_AUS_basins <- read_sf(request) # read simple features using 'request' URL. Takes few secs...
Now that we have the data available, we define our plot parameters. We want to plot denudation rate (“EBE_MMKYR”) over average slope gradient (“SLP_AVE”) and call the plot (last line)
myPlot <- ggplot(CRN_AUS_basins, aes(x=SLP_AVE, y=EBE_MMKYR)) + # plot denudation rate over average slope
geom_errorbar(aes(ymin=(EBE_MMKYR-EBE_ERR), ymax=(EBE_MMKYR+EBE_ERR)), linewidth=0.3, colour="gray80") + # visualise errors
geom_point(aes(size=AREA, color=ELEV_AVE), alpha=.5) + # scale pts. to "AREA", colour pts. to "ELEV_AVE"
scale_color_viridis(option="C", direction = -1) + # use 'viridis' colour scale
scale_size_continuous(range = c(2, 10)) + # define point size range for better visibility
xlab("Slope gradient [m km^-1]") + ylab("Denudation rate [mm kyr^-1]") + # set labels for x and y axes
ggtitle("Australian 10Be catchment-avg. denudation rates") + # make title
theme(plot.title = element_text(size = 18, face = "bold")) + # title settings
labs(size = "Catchment \narea [km^2]", colour = "Average \ncatchment \nelevation [m]") # re-label legend
myPlot # make plot
For this example we quickly want to display Australian OSL (Optically Stimulated Luminescence) ages on a base map.
library(mapview) # Provides functions for quick visualisation of spatial data
mapviewOptions(fgb = FALSE)
url2 <- parse_url(OCTOPUSdata) # parse URL into list
url2$query <- list(service = "wfs",
version = "2.0.0",
request = "GetFeature",
typename = "be10-denude:sahulsed_fluvial_osl",
srsName = "EPSG:900913") # set parameters for url$query
request2 <- build_url(url2) # build request URL from 'url' list
SahulSed.FLV.OSL <- read_sf(request2) # read simple features using 'request' URL. Takes few secs...
SahulSed.FLV.OSL <- st_set_crs(SahulSed.FLV.OSL, 900913) # Set Coordinate Reference System
SahulSed.FLV.OSL = st_transform(SahulSed.FLV.OSL,
crs = "+proj=longlat +datum=WGS84") # Transform geometry to geographic coordinates, WGS84
mapview(SahulSed.FLV.OSL, xcol = "X_WGS84", ycol = "Y_WGS84",
zcol = "OSL_AGE", at = seq(0, 350, 50), alpha = .25, # set range (0 to 350 ka) and bins (50 ka)
alpha.regions = 0.1, legend = TRUE) # Display on map using "mapview" package