The purpose of this tutorial is:
The end goal of this tutorial is for R users with minimal spatial experience to be able to search for, download and visualise Vicmap data. While this tutorial is aimed at spatial beginners, it can still be used as a reference for more experienced users.
Vicmap is the Victorian Government’s catalogue of spatial datasets. The catalogue features 651 datasets across land, property, infrastructure and environment and is the most authoritative suite of spatial data in Victoria.
This data catalogue is freely available to the public and can be accessed via several methods. For users of R, the fastest way to access up to date Vicmap datasets is to utilise the Web Feature Service (WFS). WFS is a standardised interface to request geographic information, regardless of the platform on which it is stored.
WFS requires a URL that contains the instructions for the query and is written in WFS specific terminology. This of course requires understanding of the WFS terminology and the time-consuming process of manually building the URL string.
VicmapR simplifies WFS queries by taking user supplied keywords and automatically building the correctly formatted URL string.
The functions in VicmapR therefore provide a much faster and more robust method for acquiring Vicmap data.
VicmapR uses lazy evaluation, in which we query but do not collect the data from the Vicmap database. This is called making a ‘Vicmap Promise’. A Vicmap Promise contains the dataset information but not the data itself. This promise can be filtered for a subset of the data before collecting. Using lazy evaluation we can collect the desired subset, instead of the entire dataset.
To demonstrate VicmapR’s features, we will download and explore a dataset from the Vicmap catalogue.
Australian spring is famous for the presence of swooping birds. Certain species of birds swoop during the breeding season to protect their nest from potential predators. Swooping birds in Victoria include the masked lapwing (plover), butcherbird, magpie-lark, noisy miner and perhaps most famously, the magpie. The Vicmap catalogue has a dataset of ‘swoop’ locations, recorded by members of the public.
First, we need to search for the dataset. We can view all layers, or do a keyword search. Use
ignore.case = TRUE for a case-insensitive search.
#Don't forget to load VicmapR library library(VicmapR) #All layers all_layers <- listLayers() #Case insensitive keyword search search <- listLayers(pattern = "swoop", ignore.case = T)
Viewing our search results shows us the name of the dataset and its description.
|datavic:FLORAFUANA1_SWOOPING_BIRD||Map of Victoria with locations of swooping birds populated by the public|
Once we have the name of the Vicmap dataset we would like to download, in this case ‘datavic:FLORAFUANA1_SWOOPING_BIRD’, we can query the Vicmap database.
If we are still not sure from the name and description that this is the right dataset, we can look at the Vicmap Promise to get a snippet of the dataset contents.
vicmap_query(layer = "datavic:FLORAFUANA1_SWOOPING_BIRD") #> • Using collect() on this object will return 4616 #> • features and 10 fields #> • At most six rows of the record are printed here #> ──────────────────────────────────────────────────────────────────────────────── #> Simple feature collection with 6 features and 9 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 143.5408 ymin: -37.80206 xmax: 145.8742 ymax: -35.36098 #> Geodetic CRS: GDA94 #> # A tibble: 6 × 10 #> id SWOOP_DATE SWOOP_LOCATION NO_OF_BIRDS SPECIES COMMENTS STATUS #> <chr> <date> <chr> <int> <chr> <chr> <chr> #> 1 FLORAFUANA1_SWO… 2017-09-30 Labilliere St 1 Magpie NA HISTO… #> 2 FLORAFUANA1_SWO… 2017-09-21 Creek Trail /… 1 Magpie On the … HISTO… #> 3 FLORAFUANA1_SWO… 2017-02-09 Hall avenue o… 1 Unknown Bird ve… HISTO… #> 4 FLORAFUANA1_SWO… 2017-08-29 Arglye Sq Nth 1 Magpie Pecked … HISTO… #> 5 FLORAFUANA1_SWO… 2017-08-30 NA 1 Magpie NA HISTO… #> 6 FLORAFUANA1_SWO… 2017-08-31 Cnr Yana St a… 1 Magpie Swooped… HISTO… #> # … with 3 more variables: UFI_CREATED <date>, OBJECTID <int>, #> # geometry <POINT [°]>
We can see that the dataset contains, swoop date, location and species. At a glance this data should be adequate to start analysing the spatial distribution of bird swoops.
The summary also shows that there are 9464 rows in this dataset. This isn’t a very large dataset, but if we are using this data in an interactive report or application, waiting to download the full dataset may be impractical.
Using lazy evaluation, we can use pipes to filter and subset the data, so that we only collect the desired subset. For example, let’s just look at the first 10 rows.
query <- vicmap_query(layer = "datavic:FLORAFUANA1_SWOOPING_BIRD") %>% head(10) %>% collect() query #> Simple feature collection with 10 features and 9 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 143.5408 ymin: -38.08512 xmax: 145.8742 ymax: -35.36098 #> Geodetic CRS: GDA94 #> # A tibble: 10 × 10 #> id SWOOP_DATE SWOOP_LOCATION NO_OF_BIRDS SPECIES COMMENTS STATUS #> <chr> <date> <chr> <int> <chr> <chr> <chr> #> 1 FLORAFUANA1_SW… 2017-09-30 Labilliere St 1 Magpie NA HISTO… #> 2 FLORAFUANA1_SW… 2017-09-21 Creek Trail /… 1 Magpie On the … HISTO… #> 3 FLORAFUANA1_SW… 2017-02-09 Hall avenue o… 1 Unknown Bird ve… HISTO… #> 4 FLORAFUANA1_SW… 2017-08-29 Arglye Sq Nth 1 Magpie Pecked … HISTO… #> 5 FLORAFUANA1_SW… 2017-08-30 NA 1 Magpie NA HISTO… #> 6 FLORAFUANA1_SW… 2017-08-31 Cnr Yana St a… 1 Magpie Swooped… HISTO… #> 7 FLORAFUANA1_SW… 2017-09-03 On Grey St Da… 1 Magpie NA HISTO… #> 8 FLORAFUANA1_SW… 2017-09-13 dunlop st 1 Magpie swooped… HISTO… #> 9 FLORAFUANA1_SW… 2017-08-26 1km west of P… 1 Magpie NA HISTO… #> 10 FLORAFUANA1_SW… 2017-09-16 Aintree Ave 3 Magpie Very ag… HISTO… #> # … with 3 more variables: UFI_CREATED <date>, OBJECTID <int>, #> # geometry <POINT [°]>
Now let’s only look at swoops that occurred in 2021, where STATUS is HISTORY2021. For our analysis, we will look only at the swoop date, species, number of birds, comments and geometry. Note that Vicmap datasets will retain id and OBJECTID columns even if not selected in the Vicmap promise. As this a simple features (sf) dataset, the geometry corresponding to the features (in this case, swoops) does not need to be selected as it is always attached. The geometry column can only be removed intentionally, for example, by using the
st_drop_geometry() function in the
library(dplyr) swoops_2021 <- vicmap_query(layer = "datavic:FLORAFUANA1_SWOOPING_BIRD") %>% filter(SWOOP_DATE > "2020-12-31z") %>% filter(STATUS == "HISTORY2021") %>% select(SWOOP_DATE, NO_OF_BIRDS, SPECIES, COMMENTS) %>% collect() swoops_2021 %>% head(5) %>% select(-id) %>% #condense table for viewing kable() %>% kable_styling()
|2021-11-13||2||Magpie||NA||5920||POINT (144.9474 -37.74196)|
|2021-11-13||1||Magpie||Swooped by this bird early in spring and now again in late spring. Loves to come down from tree and flies across to lamp post in middle of carpark.||5921||POINT (144.2497 -36.77707)|
|2021-11-13||2||Magpie||Corner of Myrtleford to Yackandandah Rd and Tunnel Gap Rd. Late in season. Two birds, very persistent following a long way from initial encounter. No physical contact||5922||POINT (146.8573 -36.47347)|
|2021-11-15||1||Magpie||Hit in the head, knocked to the ground. Cut under eye and black eye||5923||POINT (145.056 -37.93734)|
|2021-10-18||3||Magpie||Chased me for about 30m||5924||POINT (144.8661 -37.72732)|
By filtering the Vicmap promise before collecting, we have downloaded only a subset of rows of data.