Skip to content

Commit 2127ac5

Browse files
authored
Merge pull request #182 from R-ArcGIS/arc-raster
fix arc_raster
2 parents 6bdde5c + 24476c1 commit 2127ac5

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# arcgislayers (development)
22

3+
- `arc_raster()` now downloads the exported image to a temp file instead of creating a connection to the url returned. This fixes an issue where rasters would stop working after the url had been removed.
34
- Add `alias` argument to `arc_read()` allowing replacement or labelling of field names with alias values (#169)
45
- Add `pull_field_aliases()` utility function
56
- `arc_select()` now uses `arcgisutils::rbind_results()` for faster row-binding if `{collapse}`, `{data.table}`, `{vctrs}` are installed (#175)

R/arc-raster.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ arc_raster <- function(
5454
width = NULL,
5555
height = NULL,
5656
format = "tiff",
57-
token = arc_token()
58-
) {
59-
60-
57+
token = arc_token()) {
6158
# validate and extract CRS object
6259
out_sr <- validate_crs(crs)[["spatialReference"]][["wkid"]]
6360

@@ -82,16 +79,18 @@ arc_raster <- function(
8279

8380
# fetch the response
8481
resp <- httr2::req_perform(req)
85-
8682
resp_meta <- RcppSimdJson::fparse(httr2::resp_body_string(resp))
8783

8884
detect_errors(resp_meta)
8985

86+
tmp <- tempfile(fileext = paste0(".", format))
87+
exported_image_path <- resp_meta[["href"]]
88+
utils::download.file(exported_image_path, tmp, quiet = TRUE)
89+
9090
res <- terra::rast(
91-
resp_meta$href
91+
tmp
9292
)
9393

9494
names(res) <- x[["bandNames"]]
9595
res
96-
9796
}

0 commit comments

Comments
 (0)