Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two wfs #143

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/utils-classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ print.bcdc_record <- function(x, ...) {
record_print_helper <- function(r, n, print_avail = FALSE){
cat(n, ") ", clean_wfs(r$name), "\n", sep = "")
#cat(" description:", r$description, "\n")
cat(" warehouse name:", ifelse(is_whse_object_name(r$whse_name), r$whse_name, NA_character_), "\n")
cat(" format:", clean_wfs(formats_from_resource(r)), "\n")
if (r$format != "wms") cat(" url:", r$url, "\n")
cat(" resource:", r$id, "\n")
Expand Down
14 changes: 14 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ get_record_warn_once <- function(...) {
clean_wfs <- function(x){
dplyr::case_when(
x == "WMS getCapabilities request" ~ "WFS request (Spatial Data)",
x == "WMS getCapabilities request (Generalized View)" ~ "WFS request (Spatial Data)",
x == "wms" ~ "wfs",
TRUE ~ x
)
Expand Down Expand Up @@ -231,6 +232,7 @@ resource_to_tibble <- function(x){
dplyr::tibble(
name = purrr::map_chr(x, "name"),
url = purrr::map_chr(x, "url"),
whse_name = parse_url_for_whse_name(url),
id = purrr::map_chr(x, "id"),
format = purrr::map_chr(x, "format"),
ext = purrr::map_chr(x, safe_file_ext),
Expand Down Expand Up @@ -336,3 +338,15 @@ catch_catalogue_error <- function(catalogue_response) {
stop(msg, call. = FALSE)
}
}

get_whse_from_resource <- function(record, resource){

#record <- bcdc_get_record(record)
rdf <- record$resource_df$url[record$resource_df$id == resource]
parse_url_for_whse_name(rdf)

}

parse_url_for_whse_name <- function(x) {
basename(dirname(x))
}
47 changes: 47 additions & 0 deletions scratch/scratch_dem.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2019 Province of British Columbia
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.



bcdc_get_dem <- function(bbox) {

if (inherits(bbox, "bbox")) {
bbox <- paste(bbox, collapse = ",")
}

query_list <- list(
service="WCS",
version="1.0.0",
request="GetCoverage",
coverage="pub:bc_elevation_25m_bcalb",
bbox=bbox,
CRS="EPSG:3005",
RESPONSE_CRS = "EPSG:3005",
Format="GeoTIFF",
resx=25,
resy=25
)

## Drop any NULLS from the list
query_list <- compact(query_list)

## GET and parse data to sf object
cli <- bcdc_http_client(url = "https://delivery.openmaps.gov.bc.ca/om/wcs")



tiff_file <- tempfile(fileext = ".tif")
res <- cli$get(query = query_list, disk = tiff_file)
close(file(tiff_file))

raster::raster(res$content)
}