Created
July 31, 2018 20:11
-
-
Save ateucher/8bdc1a5ceb3d34e97b5c559c882daaf4 to your computer and use it in GitHub Desktop.
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
bcdc_to_sf <- function(layer, crs = 3005) { | |
if (!requireNamespace("httr") || !requireNamespace("sf")) { | |
stop("You must have the sf and httr packages installed.") | |
} | |
base_url <- sprintf("https://openmaps.gov.bc.ca/geo/pub/%s/ows", layer) | |
srs <- paste0("epsg:", crs) | |
response <- httr::GET(base_url, | |
query = list(service = "WFS", | |
version = "2.0.0", | |
request = "GetFeature", | |
typeName = layer, | |
outputFormat = "json", | |
SRSNAME = srs)) | |
httr::stop_for_status(response) | |
sf::read_sf(httr::content(response, as = "text")) | |
} | |
# Example usage | |
herds <- bcdc_to_sf("WHSE_WILDLIFE_INVENTORY.GCPB_CARIBOU_POPULATION_SP") | |
plot(herds[, "HERD_NAME"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment