Last active
April 17, 2024 06:00
-
-
Save adamhsparks/f8c02d07a6359bad51be09c5494ba442 to your computer and use it in GitHub Desktop.
Get DPIRD CVT Zones as an {sf} Object in Your R Session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get DPIRD CVT zones from the Public Services Slip WA as an {sf} object in R | |
# data are CC 4.0 and available from: <https://data.wa.gov.au/slip> | |
wfs_wa <- | |
"https://public-services.slip.wa.gov.au/public/services/SLIP_Public_Services/Boundaries_WFS/MapServer/WFSServer" | |
url <- httr2::url_parse(wfs_wa) | |
url$query <- list(service = "wfs", | |
#version = "2.0.0", # facultative | |
request = "GetCapabilities") | |
request <- httr2::url_build(url) | |
wa_client <- ows4R::WFSClient$new(wfs_wa, | |
serviceVersion = "2.0.0") | |
wa_features <- wa_client$getFeatureTypes(pretty = TRUE) | |
wa_features <- | |
gsub("SLIP_Public_Services_Boundaries_WFS:", "", wa_features$name) | |
dpird_features <- grep("DPIRD", wa_features, value = TRUE) | |
#' Get a named data set from WA's Web Feature Service | |
#' @param x The name of the desired data set to fetch. | |
#' | |
get_wfs_data <- function(x) { | |
url$query <- list( | |
service = "wfs", | |
version = "2.0.0", | |
request = "GetFeature", | |
typename = x, | |
srsName = "EPSG:4326" | |
) | |
request <- httr2::url_build(url) | |
sf::read_sf(request) | |
} | |
cvt <- get_wfs_data("esri:Crop_Variety_Testing_Zones_of_WA__DPIRD-028_") | |
library("ggplot2") | |
ggplot(cvt) + | |
geom_sf() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to get all DPIRD boundary data sets, use this on line 35.