https://github.com/justincally/vicmapr
An R package to easily utilise Victorian Government spatial datasets
https://github.com/justincally/vicmapr
gis r spatial-data wfs wfs-urls
Last synced: about 1 month ago
JSON representation
An R package to easily utilise Victorian Government spatial datasets
- Host: GitHub
- URL: https://github.com/justincally/vicmapr
- Owner: JustinCally
- License: apache-2.0
- Created: 2020-09-03T00:22:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-11T01:20:53.000Z (over 1 year ago)
- Last Synced: 2024-09-11T05:59:11.339Z (over 1 year ago)
- Topics: gis, r, spatial-data, wfs, wfs-urls
- Language: R
- Homepage: https://justincally.github.io/VicmapR
- Size: 5.83 MB
- Stars: 17
- Watchers: 5
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# vicspatial

[](https://app.codecov.io/gh/JustinCally/vicspatial?branch=master)
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://CRAN.R-project.org/package=vicspatial)
[](https://cran.r-project.org/package=vicspatial)
[](https://github.com/JustinCally/vicspatial/actions/workflows/R-CMD-check.yaml)
**In May 2025 (version 0.3.0) `VicmapR` was renamed to `vicspatial`. Unfortunately this change has been requested by the trademark holders of `VICMAP` (Department of Transport and Planning). While redirections should be in place for GitHub and CRAN websites, please check existing code for explicit mentions of `VicmapR`.**
The goal of vicspatial is to provide functions to easily access Victorian Government spatial data through their WFS (Web Feature Service). vicspatial leverages code and a lazy querying approach developed by [Teucher et al. (2021)](https://joss.theoj.org/papers/10.21105/joss.02927) for the [{bcdata} R package](https://bcgov.github.io/bcdata/), which allows for a responsive and precise querying process.
## Migration of Victoria's Open Data Geoserver
**From March 2023 (`vicspatial v0.2.0`) the way `vicspatial` obtains data has changed**
In March 2023 the data platform used by `vicspatial` will be migrated with the legacy platform discontinued. Changes have been to the `vicspatial` package to allow for the conversion and translation of of code in an effort to ensure legacy code still works. However, the migration may have unseen consequences and users are encouraged to review code.
## Installation
You can install the released version from CRAN with:
``` r
install.packages("vicspatial")
```
Or you can install the the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("JustinCally/vicspatial")
```
### Dependencies
Currently, the ability to use accurate geometric filters using `vicspatial` requires GDAL > 3.0. To see how to upgrade your version of GDAL and link it to the `sf` package visit: https://r-spatial.github.io/sf/#installing
```{r dependencies}
library(sf)
sf::sf_extSoftVersion()
```
## Example
### Searching for data
```{r example}
library(vicspatial)
# Check to see if the geoserver is working. It will error if it is not working
check_geoserver()
listLayers(pattern = "watercourse", ignore.case = T)
```
### Reading in data
As of vicspatial version `0.1.0` data is read in using a lazy evaluation method with the convenience of pipe operators (`%>%`). A lot of the methods and code have already been written for a similar package ([bcdata](https://github.com/bcgov/bcdata)) that downloads data from the British Columbia WFS catalogues. Using a similar approach, vicspatial allows users to construct a WFS query in a step-wise format. In doing so a query is reserved until `collect()` is used on the `vicmap_promise`. The example below shows an extensive example of how the to easily read in spatial data:
```{r query_example}
# Read in an example shape to restrict our query to using geometric filtering
melbourne <- sf::st_read(system.file("shapes/melbourne.geojson", package="vicspatial"), quiet = T)
# Obtain a promise of what data will be returned for a given layer
vicmap_query(layer = "open-data-platform:hy_watercourse")
# Build a more specific query and collect the results
vicmap_query(layer = "open-data-platform:hy_watercourse") %>% # layer to query
filter(hierarchy == "L" & feature_type_code == 'watercourse_channel_drain') %>% # simple filter for a column
filter(INTERSECTS(melbourne)) %>% # more advanced geometric filter
select(hierarchy, pfi) %>%
collect()
```
vicspatial translates numerous geometric filter functions available in the Victorian Government's WFS Geoserver supports numerous [geometric filters](https://docs.geoserver.org/stable/en/user/tutorials/cql/cql_tutorial.html#geometric-filters):
+ `EQUALS`
+ `DISJOINT`
+ `INTERSECTS`
+ `TOUCHES`
+ `CROSSES`
+ `WITHIN`
+ `CONTAINS`
+ `OVERLAPS`
+ `DWITHIN`
+ `BEYOND`
+ `BBOX`
These filters can be used within the `filter()` function by providing them an object of class `sf/sfc/sfg/bbox` as shown above with the `melbourne` object.
### Using other WFS urls
Using `options(vicmap.base_url)` vicspatial can query data from other WFS services; while this remains somewhat untested it is relatively easy to point vicspatial to another WFS url. This option would need to be set every session to override the base vicspatial url. For instance, the BOM WFS can be used as follows:
```{r, eval=FALSE}
# set the new base url
options(vicmap.base_url = "http://geofabric.bom.gov.au/simplefeatures/ahgf_shcatch/wfs")
# collect a data sample
catchments <- vicmap_query("ahgf_shcatch:AHGFCatchment") %>%
head(10) %>%
collect()
```
*__Note__: Using other Geoserver WFS urls will not necessarily work as expected due to the potential differences in the capabilities of the Geoserver instance*
### License
Copyright 2018 Province of British Columbia
Modifications Copyright 2020 Justin Cally
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.