Skip to content

Commit f40818d

Browse files
committed
Convert tabs to spaces
1 parent c6f3d8f commit f40818d

File tree

2 files changed

+89
-89
lines changed

2 files changed

+89
-89
lines changed

R/layers.R

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ epsg3857 <- "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y
175175

176176
#' Add a raster image as a layer
177177
#'
178-
#' Create an image overlay from a \code{RasterLayer} or a \code{SpatRaster}
178+
#' Create an image overlay from a \code{RasterLayer} or a \code{SpatRaster}
179179
#' object. \emph{This is only suitable for small to medium sized rasters},
180180
#' as the entire image will be embedded into the HTML page (or passed over
181181
#' the websocket in a Shiny context).
@@ -190,13 +190,13 @@ epsg3857 <- "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y
190190
#'
191191
#' To reduce the size of a SpatRaster, you can use \code{\link[terra]{spatSample}}
192192
#' as in \code{x = spatSample(x, 100000, method="regular", as.raster=TRUE)}. With
193-
#' a \code{RasterLayer} you can use \code{\link[raster]{sampleRegular}} as in
193+
#' a \code{RasterLayer} you can use \code{\link[raster]{sampleRegular}} as in
194194
#' \code{sampleRegular(x, 100000, asRaster=TRUE)}.
195195
#'
196196
#' By default, the \code{addRasterImage} function will project the raster data
197-
#' \code{x} to the Pseudo-Mercator projection (EPSG:3857). This can be a
197+
#' \code{x} to the Pseudo-Mercator projection (EPSG:3857). This can be a
198198
#' time-consuming operation for even moderately sized rasters; although it is much
199-
#' faster for SpatRasters than for RasterLayers.
199+
#' faster for SpatRasters than for RasterLayers.
200200
#' If you are repeatedly adding a particular raster to your Leaflet
201201
#' maps, you can perform the projection ahead of time using
202202
#' \code{projectRasterForLeaflet()}, and call \code{addRasterImage} with
@@ -250,37 +250,37 @@ addRasterImage <- function(
250250
maxBytes = 4 * 1024 * 1024,
251251
data = getMapData(map)
252252
) {
253-
if (inherits(x, "SpatRaster")) {
254-
addRasterImage_SpatRaster(
255-
map=map,
256-
x=x,
257-
colors = colors,
258-
opacity = opacity,
259-
attribution = attribution,
260-
layerId = layerId,
261-
group = group,
262-
project = project,
263-
method = method,
264-
maxBytes = maxBytes,
265-
data = data
266-
)
267-
} else if (inherits(x, "RasterLayer")) {
268-
addRasterImage_RasterLayer(
269-
map=map,
270-
x=x,
271-
colors = colors,
272-
opacity = opacity,
273-
attribution = attribution,
274-
layerId = layerId,
275-
group = group,
276-
project = project,
277-
method = method,
278-
maxBytes = maxBytes,
279-
data = data
280-
)
281-
} else {
282-
stop("Don't know how to get path data from object of class ", class(x)[[1]])
283-
}
253+
if (inherits(x, "SpatRaster")) {
254+
addRasterImage_SpatRaster(
255+
map=map,
256+
x=x,
257+
colors = colors,
258+
opacity = opacity,
259+
attribution = attribution,
260+
layerId = layerId,
261+
group = group,
262+
project = project,
263+
method = method,
264+
maxBytes = maxBytes,
265+
data = data
266+
)
267+
} else if (inherits(x, "RasterLayer")) {
268+
addRasterImage_RasterLayer(
269+
map=map,
270+
x=x,
271+
colors = colors,
272+
opacity = opacity,
273+
attribution = attribution,
274+
layerId = layerId,
275+
group = group,
276+
project = project,
277+
method = method,
278+
maxBytes = maxBytes,
279+
data = data
280+
)
281+
} else {
282+
stop("Don't know how to get path data from object of class ", class(x)[[1]])
283+
}
284284
}
285285

286286

@@ -298,7 +298,7 @@ addRasterImage_RasterLayer <- function(
298298
data = getMapData(map)
299299
) {
300300

301-
301+
302302
raster_is_factor <- raster::is.factor(x)
303303
method <- match.arg(method)
304304
if (method == "auto") {
@@ -373,10 +373,10 @@ addRasterImage_SpatRaster <- function(
373373
) {
374374

375375
if (terra::nlyr(x) > 1) {
376-
x <- x[[1]]
377-
warning("using the first layer in 'x'", call. = FALSE)
376+
x <- x[[1]]
377+
warning("using the first layer in 'x'", call. = FALSE)
378378
}
379-
379+
380380
raster_is_factor <- terra::is.factor(x)
381381
method <- match.arg(method)
382382
if (method == "ngb") method = "near"
@@ -395,13 +395,13 @@ addRasterImage_SpatRaster <- function(
395395
# do not project data
396396
projected <- x
397397
}
398-
398+
399399
bounds <- terra::ext(
400400
terra::project(
401-
terra::project(
402-
terra::as.points(terra::ext(x), crs=terra::crs(x)),
403-
epsg3857),
404-
epsg4326)
401+
terra::project(
402+
terra::as.points(terra::ext(x), crs=terra::crs(x)),
403+
epsg3857),
404+
epsg4326)
405405
)
406406

407407
if (!is.function(colors)) {
@@ -444,30 +444,30 @@ addRasterImage_SpatRaster <- function(
444444
#' @export
445445
projectRasterForLeaflet <- function(x, method) {
446446
if (inherits(x, "SpatRaster")) {
447-
if (method=="ngb") {
447+
if (method=="ngb") {
448448
method = "near"
449-
}
449+
}
450450
terra::project(
451-
x,
452-
y=epsg3857,
453-
method=method
454-
)
451+
x,
452+
y=epsg3857,
453+
method=method
454+
)
455455
} else {
456-
raster_is_factor <- raster::is.factor(x);
457-
projected <- raster::projectRaster(
458-
x,
459-
raster::projectExtent(x, crs = sp::CRS(epsg3857)),
460-
method = method
456+
raster_is_factor <- raster::is.factor(x);
457+
projected <- raster::projectRaster(
458+
x,
459+
raster::projectExtent(x, crs = sp::CRS(epsg3857)),
460+
method = method
461461
)
462462
# if data is factor data, make the result factors as well.
463-
# only meaningful if ngb was used
463+
# only meaningful if ngb was used
464464
if ((raster_is_factor) && (method == "ngb")) {
465465
raster::as.factor(projected)
466466
} else {
467-
projected
468-
}
469-
470-
}
467+
projected
468+
}
469+
470+
}
471471
}
472472

473473
#' @rdname remove

R/normalize-terra.R

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,42 @@ metaData.SpatVector <- function(obj) {
88

99
#' @export
1010
pointData.SpatVector <- function(obj) {
11-
check_crs_terra(obj)
12-
xy = data.frame(terra::crds(obj))
13-
names(xy) = c("lng", "lat")
14-
structure(
15-
xy,
16-
bbox = terra_bbox(obj)
17-
)
11+
check_crs_terra(obj)
12+
xy = data.frame(terra::crds(obj))
13+
names(xy) = c("lng", "lat")
14+
structure(
15+
xy,
16+
bbox = terra_bbox(obj)
17+
)
1818
}
1919

2020

2121
# polygonData -------------------------------------------------------------
2222

2323
#' @export
2424
polygonData.SpatVector <- function(obj) {
25-
check_crs_terra(obj)
26-
27-
# this is a bit convoluted. I will add a simpler
28-
# and more efficient method to terra to replace the below
29-
xy = data.frame(terra::geom(obj))
30-
names(xy)[3:4] = c("lng", "lat")
31-
xy = split(xy[,2:5], xy[,1]) # polygons
32-
names(xy) = NULL # won't work with names
33-
xy = lapply(xy, function(p) {
34-
d = split(p[,-1], p[,1]) # parts
35-
names(d) = NULL
36-
lapply(d, function(p) { # ring and holes
37-
s = split(p[,1:2], p[,3])
38-
names(s) = NULL
39-
lapply(s, function(i) { rownames(i) = NULL; i }) # for expect_maps_equal
40-
})
41-
})
42-
43-
structure(
44-
xy,
45-
bbox = terra_bbox(obj)
46-
)
25+
check_crs_terra(obj)
26+
27+
# this is a bit convoluted. I will add a simpler
28+
# and more efficient method to terra to replace the below
29+
xy = data.frame(terra::geom(obj))
30+
names(xy)[3:4] = c("lng", "lat")
31+
xy = split(xy[,2:5], xy[,1]) # polygons
32+
names(xy) = NULL # won't work with names
33+
xy = lapply(xy, function(p) {
34+
d = split(p[,-1], p[,1]) # parts
35+
names(d) = NULL
36+
lapply(d, function(p) { # ring and holes
37+
s = split(p[,1:2], p[,3])
38+
names(s) = NULL
39+
lapply(s, function(i) { rownames(i) = NULL; i }) # for expect_maps_equal
40+
})
41+
})
42+
43+
structure(
44+
xy,
45+
bbox = terra_bbox(obj)
46+
)
4747
}
4848

4949

0 commit comments

Comments
 (0)