6060# ' * [USGSShadedReliefOnly](https://basemap.nationalmap.gov/arcgis/rest/services/USGSShadedReliefOnly/MapServer)
6161# ' * [USGSImageryOnly](https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer)
6262# ' * [USGSHydroCached](https://basemap.nationalmap.gov/arcgis/rest/services/USGSHydroCached/MapServer)
63- # ' * [USGSTNMBlank](https://basemap.nationalmap.gov/arcgis/rest/services/USGSTNMBlank/MapServer)
6463# '
6564# '
6665# nolint end
9695# ' @rdname get_tiles
9796# ' @md
9897# ' @export
99- get_tiles <- function (data ,
100- output_prefix = tempfile(),
101- side_length = NULL ,
102- resolution = 1 ,
103- services = " elevation" ,
104- verbose = FALSE ,
105- georeference = TRUE ,
106- projected = NULL ,
107- ... ) {
98+ get_tiles <- function (
99+ data ,
100+ output_prefix = tempfile(),
101+ side_length = NULL ,
102+ resolution = 1 ,
103+ services = " elevation" ,
104+ verbose = FALSE ,
105+ georeference = TRUE ,
106+ projected = NULL ,
107+ ...
108+ ) {
108109 UseMethod(" get_tiles" )
109110}
110111
111112# ' @rdname get_tiles
112113# ' @export
113- get_tiles.sf <- function (data ,
114- output_prefix = tempfile(),
115- side_length = NULL ,
116- resolution = 1 ,
117- services = " elevation" ,
118- verbose = FALSE ,
119- georeference = TRUE ,
120- projected = NULL ,
121- ... ) {
114+ get_tiles.sf <- function (
115+ data ,
116+ output_prefix = tempfile(),
117+ side_length = NULL ,
118+ resolution = 1 ,
119+ services = " elevation" ,
120+ verbose = FALSE ,
121+ georeference = TRUE ,
122+ projected = NULL ,
123+ ...
124+ ) {
122125 dots <- list (... )
123126
124127 if (is.null(projected )) {
@@ -163,18 +166,21 @@ get_tiles.sf <- function(data,
163166
164167# ' @rdname get_tiles
165168# ' @export
166- get_tiles.sfc <- function (data ,
167- output_prefix = tempfile(),
168- side_length = NULL ,
169- resolution = 1 ,
170- services = " elevation" ,
171- verbose = FALSE ,
172- georeference = TRUE ,
173- projected = NULL ,
174- ... ) {
169+ get_tiles.sfc <- function (
170+ data ,
171+ output_prefix = tempfile(),
172+ side_length = NULL ,
173+ resolution = 1 ,
174+ services = " elevation" ,
175+ verbose = FALSE ,
176+ georeference = TRUE ,
177+ projected = NULL ,
178+ ...
179+ ) {
175180 data <- sf :: st_as_sf(data )
176181
177- get_tiles(data ,
182+ get_tiles(
183+ data ,
178184 output_prefix = output_prefix ,
179185 side_length = side_length ,
180186 resolution = resolution ,
@@ -188,39 +194,45 @@ get_tiles.sfc <- function(data,
188194
189195# ' @rdname get_tiles
190196# ' @export
191- get_tiles.Raster <- function (data ,
192- output_prefix = tempfile(),
193- side_length = NULL ,
194- resolution = 1 ,
195- services = " elevation" ,
196- verbose = FALSE ,
197- georeference = TRUE ,
198- projected = NULL ,
199- ... ) {
197+ get_tiles.Raster <- function (
198+ data ,
199+ output_prefix = tempfile(),
200+ side_length = NULL ,
201+ resolution = 1 ,
202+ services = " elevation" ,
203+ verbose = FALSE ,
204+ georeference = TRUE ,
205+ projected = NULL ,
206+ ...
207+ ) {
200208 data <- terra :: rast(data )
201- get_tiles.SpatRaster(data ,
202- output_prefix = output_prefix ,
203- side_length = side_length ,
204- resolution = resolution ,
205- services = services ,
206- verbose = verbose ,
207- georeference = georeference ,
208- projected = projected ,
209- ... )
209+ get_tiles.SpatRaster(
210+ data ,
211+ output_prefix = output_prefix ,
212+ side_length = side_length ,
213+ resolution = resolution ,
214+ services = services ,
215+ verbose = verbose ,
216+ georeference = georeference ,
217+ projected = projected ,
218+ ...
219+ )
210220}
211221
212222
213223# ' @rdname get_tiles
214224# ' @export
215- get_tiles.SpatRaster <- function (data ,
216- output_prefix = tempfile(),
217- side_length = NULL ,
218- resolution = 1 ,
219- services = " elevation" ,
220- verbose = FALSE ,
221- georeference = TRUE ,
222- projected = NULL ,
223- ... ) {
225+ get_tiles.SpatRaster <- function (
226+ data ,
227+ output_prefix = tempfile(),
228+ side_length = NULL ,
229+ resolution = 1 ,
230+ services = " elevation" ,
231+ verbose = FALSE ,
232+ georeference = TRUE ,
233+ projected = NULL ,
234+ ...
235+ ) {
224236 dots <- list (... )
225237 if (is.null(projected )) {
226238 projected <- ! sf :: st_is_longlat(data )
@@ -270,19 +282,22 @@ get_tiles.SpatRaster <- function(data,
270282
271283# ' @rdname get_tiles
272284# ' @export
273- get_tiles.list <- function (data ,
274- output_prefix = tempfile(),
275- side_length = NULL ,
276- resolution = 1 ,
277- services = " elevation" ,
278- verbose = FALSE ,
279- georeference = TRUE ,
280- projected = NULL ,
281- ... ) {
285+ get_tiles.list <- function (
286+ data ,
287+ output_prefix = tempfile(),
288+ side_length = NULL ,
289+ resolution = 1 ,
290+ services = " elevation" ,
291+ verbose = FALSE ,
292+ georeference = TRUE ,
293+ projected = NULL ,
294+ ...
295+ ) {
282296 .Deprecated(
283297 " get_tiles.list" ,
284298 " terrainr" ,
285- msg = paste(" 'get_tiles.list' is deprecated as of terrainr 0.5.0." ,
299+ msg = paste(
300+ " 'get_tiles.list' is deprecated as of terrainr 0.5.0." ,
286301 " Convert your list to an sf object instead." ,
287302 sep = " \n "
288303 )
@@ -304,16 +319,17 @@ get_tiles.list <- function(data,
304319 )
305320}
306321
307- get_tiles_internal <- function (data ,
308- output_prefix = tempfile(),
309- side_length = NULL ,
310- resolution = 1 ,
311- services = " elevation" ,
312- verbose = FALSE ,
313- georeference = TRUE ,
314- projected = NULL ,
315- ... ) {
316-
322+ get_tiles_internal <- function (
323+ data ,
324+ output_prefix = tempfile(),
325+ side_length = NULL ,
326+ resolution = 1 ,
327+ services = " elevation" ,
328+ verbose = FALSE ,
329+ georeference = TRUE ,
330+ projected = NULL ,
331+ ...
332+ ) {
317333 # short codes are assigned as names; we'll cast them into the full name later
318334 # full names are from the API URL, hence capitalization woes
319335 list_of_services <- c(
@@ -331,19 +347,20 @@ get_tiles_internal <- function(data,
331347 " USGSTopo" ,
332348 " USGSShadedReliefOnly" ,
333349 " USGSImageryOnly" ,
334- " USGSHydroCached" ,
335- " USGSTNMBlank"
350+ " USGSHydroCached"
336351 )
337352
338- stopifnot(all(services %in% list_of_services |
339- services %in% names(list_of_services )))
353+ stopifnot(all(
354+ services %in% list_of_services | services %in% names(list_of_services )
355+ ))
340356
341357 tif_files <- c(" 3DEPElevation" )
342358 png_files <- list_of_services [! (list_of_services %in% tif_files )]
343359
344360 services <- stats :: setNames(services , services )
345361
346- if (any(services %in% names(list_of_services ))) { # cast short codes now
362+ if (any(services %in% names(list_of_services ))) {
363+ # cast short codes now
347364 replacements <- which(services %in% names(list_of_services ))
348365 services [replacements ] <- as.vector(
349366 list_of_services [services [replacements ]]
@@ -379,28 +396,34 @@ get_tiles_internal <- function(data,
379396 x_tiles <- bbox_splits [[2 ]]
380397 y_tiles <- bbox_splits [[3 ]]
381398
382- if (requireNamespace(" progressr" , quietly = TRUE )) { # nocov start
399+ if (requireNamespace(" progressr" , quietly = TRUE )) {
400+ # nocov start
383401 p <- progressr :: progressor(steps = x_tiles * y_tiles * length(services ))
384402 } # nocov end
385403
386404 for (i in seq_len(x_tiles )) {
387405 for (j in seq_len(y_tiles )) {
388- current_box <- tile_boxes [tile_boxes $ x_tiles == i &
389- tile_boxes $ y_tiles == j , ]
406+ current_box <- tile_boxes [
407+ tile_boxes $ x_tiles == i &
408+ tile_boxes $ y_tiles == j ,
409+ ]
390410 current_bbox <- data.frame (
391411 lat = c(current_box $ min_y , current_box $ max_y ),
392412 lng = c(current_box $ min_x , current_box $ max_x )
393413 )
394414 current_bbox <- sf :: st_as_sf(current_bbox , coords = c(" lng" , " lat" ))
395415 current_bbox <- sf :: st_bbox(current_bbox )
396416 for (k in seq_along(services )) {
397- if (requireNamespace(" progressr" , quietly = TRUE )) { # nocov start
398- p(message = sprintf(
399- " Retrieving %s tile (%d, %d)" ,
400- services [[k ]],
401- i ,
402- j
403- ))
417+ if (requireNamespace(" progressr" , quietly = TRUE )) {
418+ # nocov start
419+ p(
420+ message = sprintf(
421+ " Retrieving %s tile (%d, %d)" ,
422+ services [[k ]],
423+ i ,
424+ j
425+ )
426+ )
404427 } # nocov end
405428
406429 if (services [[k ]] %in% tif_files | georeference ) {
@@ -429,9 +452,11 @@ get_tiles_internal <- function(data,
429452 }
430453
431454 counter <- 0
432- while ((! file.exists(cur_path ) ||
433- file.size(cur_path ) == 0 ) &&
434- counter < 5 ) {
455+ while (
456+ (! file.exists(cur_path ) ||
457+ file.size(cur_path ) == 0 ) &&
458+ counter < 5
459+ ) {
435460 img_bin <- hit_national_map_api(
436461 current_bbox ,
437462 current_box [[" img_width" ]],
@@ -465,10 +490,7 @@ get_tiles_internal <- function(data,
465490 img_bin $ extent $ ymax
466491 )
467492
468- terra :: writeRaster(cur_raster ,
469- final_path ,
470- overwrite = TRUE
471- )
493+ terra :: writeRaster(cur_raster , final_path , overwrite = TRUE )
472494 if (rm_path ) unlink(cur_path )
473495 }
474496 }
@@ -503,7 +525,7 @@ handle_bboxSR <- function(data, projected) {
503525 rlang :: warn(c(
504526 " Assuming CRS of EPSG 5071" ,
505527 i = " Set bboxSR explicity to override"
506- ))
528+ ))
507529 5071
508530 } else {
509531 rlang :: warn(c(
0 commit comments