|
4 | 4 | #' @param properties A vector of requested columns |
5 | 5 | #' @param service character, can be any existing collection such |
6 | 6 | #' as "daily", "monitoring-locations", "time-series-metadata" |
| 7 | +#' @param skipGeometry A logical for whether to return geometry |
| 8 | +#' @param convertType A logical for whether to convert value to numeric |
7 | 9 | #' |
8 | 10 | #' @return data.frame |
9 | 11 | #' @noRd |
|
17 | 19 | #' properties = NA, |
18 | 20 | #' service = "daily") |
19 | 21 | #' |
20 | | -deal_with_empty <- function(return_list, properties, service){ |
| 22 | +deal_with_empty <- function(return_list, properties, service, |
| 23 | + skipGeometry, |
| 24 | + convertType){ |
| 25 | + |
21 | 26 | if(nrow(return_list) == 0){ |
22 | 27 |
|
23 | 28 | if(all(is.na(properties))){ |
24 | 29 | schema <- check_OGC_requests(endpoint = service, type = "schema") |
25 | 30 | properties <- names(schema$properties) |
26 | 31 | } |
27 | | - return_list <- data.frame(matrix(nrow = 0, ncol = length(properties))) |
| 32 | + return_list <- data.frame(matrix(nrow = 0, |
| 33 | + ncol = length(properties))) |
| 34 | + return_list <- lapply(return_list, as.character) |
28 | 35 | names(return_list) <- properties |
| 36 | + |
| 37 | + single_params <- c("datetime", "last_modified", "begin", "end", "time") |
| 38 | + |
| 39 | + for(i in single_params){ |
| 40 | + if(i %in% names(return_list)){ |
| 41 | + return_list[[i]] <- as.POSIXct(as.character(), origin = "1970-01-01") |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + if(convertType && service == "daily"){ |
| 46 | + return_list$time <- as.Date(as.character()) |
| 47 | + } |
| 48 | + |
| 49 | + if(convertType && "value" %in% names(return_list)){ |
| 50 | + return_list$value <- as.numeric() |
| 51 | + } |
| 52 | + |
| 53 | + if(convertType && "contributing_drainage_area" %in% names(return_list)){ |
| 54 | + return_list$contributing_drainage_area <- as.numeric() |
| 55 | + } |
| 56 | + |
| 57 | + return_list <- data.frame(return_list) |
| 58 | + return_list$geometry <- NULL |
| 59 | + |
| 60 | + if(!skipGeometry){ |
| 61 | + return_list <- sf::st_as_sf(return_list, geometry = sf::st_sfc()) |
| 62 | + } |
| 63 | + |
29 | 64 | } |
30 | | - |
| 65 | + |
31 | 66 | return(return_list) |
32 | 67 | } |
33 | 68 |
|
@@ -271,7 +306,14 @@ get_ogc_data <- function(args, |
271 | 306 |
|
272 | 307 | return_list <- walk_pages(req, max_results) |
273 | 308 |
|
274 | | - return_list <- deal_with_empty(return_list, properties, service) |
| 309 | + if(is.na(args[["skipGeometry"]])){ |
| 310 | + skipGeometry <- FALSE |
| 311 | + } else { |
| 312 | + skipGeometry <- args[["skipGeometry"]] |
| 313 | + } |
| 314 | + |
| 315 | + return_list <- deal_with_empty(return_list, properties, service, |
| 316 | + skipGeometry, convertType) |
275 | 317 |
|
276 | 318 | if(convertType) return_list <- cleanup_cols(return_list, service = service) |
277 | 319 |
|
|
0 commit comments