Skip to content

Commit

Permalink
feat: add read_sf_felt #5
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed Aug 18, 2023
1 parent bbb274f commit f1cd031
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Imports:
cli,
cliExtras (>= 0.1.0),
dplyr,
feltr (>= 0.1.1.9005),
filenamr (>= 0.1.0.9002),
glue,
grDevices,
Expand Down Expand Up @@ -58,11 +59,12 @@ Suggests:
withr
VignetteBuilder:
knitr
Remotes:
Remotes:
elipousson/cliExtras,
elipousson/esri2sf,
elipousson/filenamr,
qfes/rdeck
qfes/rdeck,
elipousson/feltr
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export(read_sf_esri)
export(read_sf_excel)
export(read_sf_exif)
export(read_sf_ext)
export(read_sf_felt)
export(read_sf_gist)
export(read_sf_gmap)
export(read_sf_gsheet)
Expand Down
38 changes: 35 additions & 3 deletions R/read_sf_ext.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ read_sf_path <- function(path, bbox = NULL, ...) {
}

if (is_excel_fileext(path)) {
return(read_sf_excel(path = path, bbox = bbox, ...))
return(read_sf_excel(path = path, bbox = bbox, ...))
}

if (is_rdata_fileext(path)) {
Expand Down Expand Up @@ -509,9 +509,10 @@ read_sf_url <- function(url,

url_type <-
dplyr::case_when(
is_esri_url(url) ~ "esri",
is_felt_url(url) ~ "felt",
is_csv_fileext(url) ~ "csv",
is_excel_fileext(url) ~ "excel",
is_esri_url(url) ~ "esri",
is_gist_url(url) ~ "gist",
is_gmap_url(url) ~ "gmap",
is_gsheet_url(url) ~ "gsheet",
Expand Down Expand Up @@ -574,6 +575,14 @@ read_sf_url <- function(url,
from_crs = from_crs,
.name_repair = .name_repair
),
"felt" = read_sf_felt(
url = url,
map_id = params[["map_id"]],
bbox = bbox,
token = params[["token"]],
crs = params[["crs"]],
.name_repair = .name_repair
),
"gist" = read_sf_gist(
url = url,
bbox = bbox,
Expand Down Expand Up @@ -676,6 +685,30 @@ read_sf_esri <- function(url,
df_to_sf(data, from_crs = from_crs, coords = coords)
}

#' @name read_sf_felt
#' @rdname read_sf_ext
#' @export
read_sf_felt <- function(url = NULL,
bbox = NULL,
map_id = NULL,
.name_repair = "check_unique",
...) {
check_installed("feltr")

map_id <- map_id %||% url

data <- feltr::read_felt_map(
map_id = map_id,
...
)

data <- set_names_repair(
data,
.name_repair = .name_repair
)

st_filter_ext(data, bbox)
}

#' @name read_sf_gist
#' @rdname read_sf_ext
Expand Down Expand Up @@ -708,7 +741,6 @@ read_sf_gist <- function(url,
)
}


#' @name read_sf_gmap
#' @rdname read_sf_ext
#' @export
Expand Down
9 changes: 9 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,12 @@ has_same_name_col <- function(x,

dplyr::rename(x, "{new_col}" := col)
}

#' Is x a Felt url?
#'
#' Copied from `feltr::is_felt_url`
#'
#' @noRd
is_felt_url <- function(x) {
is_url(x) & grepl("felt.com", x)
}
9 changes: 9 additions & 0 deletions man/read_sf_ext.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f1cd031

Please sign in to comment.