You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/raster.Rmd
+7-13
Original file line number
Diff line number
Diff line change
@@ -4,37 +4,31 @@ pagetitle: Leaflet for R - Raster Images
4
4
5
5
## Raster Images
6
6
7
-
Two-dimensional `RasterLayer` objects (from the [`raster` package](http://CRAN.R-project.org/package=raster)) can be turned into images and added to Leaflet maps using the `addRasterImage` function.
7
+
Two-dimensional `SpatRaster` objects (from the [`terra` package](https://CRAN.R-project.org/package=terra)) or `RasterLayer` objects (from the [`raster` package](https://CRAN.R-project.org/package=raster)) can be turned into images and added to Leaflet maps using the `addRasterImage` function.
8
8
9
-
The `addRasterImage` function works by projecting the `RasterLayer` object to [EPSG:3857](http://spatialreference.org/ref/sr-org/7483/) and encoding each cell to an RGBA color, to produce a PNG image. That image is then embedded in the map widget.
9
+
The `addRasterImage` function works by projecting the `SpatRaster` or `RasterLayer` object to [EPSG:3857](http://spatialreference.org/ref/sr-org/7483/) and encoding each cell to an RGBA color, to produce a PNG image. That image is then embedded in the map widget.
10
10
11
-
It's important that the `RasterLayer` object is tagged with a proper coordinate reference system. Many raster files contain this information, but some do not. Here is how you'd tag a raster layer object "`r`" which contains WGS84 data:
11
+
It's important that the raster object is tagged with a proper coordinate reference system. Many raster files contain this information, but some do not. Here is how you'd tag a raster object "`r`" which contains WGS84 data:
Because the `addRasterImage` function embeds the image in the map widget, it will increase the size of the generated HTML proportionally. In order to avoid unacceptable download times and memory usage, `addRasterImage` will error when the PNG is beyond the size indicated by the `maxBytes` argument (defaults to 4 megabytes).
20
20
21
-
If you have a large raster layer, you can provide a larger number of bytes and see how it goes, or use `raster::resample` or `raster::aggregate` to decrease the number of cells.
21
+
If you have a large raster layer, you can provide a larger number of bytes and see how it goes, or use `terra::resample`, `raster::resample`, or `raster::aggregate` to decrease the number of cells.
22
22
23
23
### Projection Performance
24
24
25
-
The `addRasterImage` function projects using `raster::projectRaster`, which can take a while on all but the smallest rasters. To improve performance, the first thing to do is install a new version of `raster`; version 2.4 includes optimizations that speed up bilinear projection by about 10X. This version has not yet been released to CRAN at the time of this writing (June 17, 2015) but can be installed directly from R-Forge:
If you have a large raster layer or expect to call `addRasterImage` on the same raster layer many times, you can perform the [EPSG:3857](http://spatialreference.org/ref/sr-org/7483/) projection yourself (either using `leaflet::projectRasterForLeaflet` or using another GIS library or program) and call `addRasterImage` with `project = FALSE`.
25
+
The `addRasterImage` function projects using `terra::project` or `raster::projectRaster`, which can take a while on all but the smallest rasters. If you have a large raster layer or expect to call `addRasterImage` on the same raster layer many times, you can perform the [EPSG:3857](http://spatialreference.org/ref/sr-org/7483/) projection yourself (either using `leaflet::projectRasterForLeaflet` or using another GIS library or program) and call `addRasterImage` with `project = FALSE`.
32
26
33
27
Be sure that your pre-projected raster layer is tagged with an accurate extent and CRS, as these values are still needed to place the image in the proper position on the map.
34
28
35
29
### Coloring
36
30
37
-
In order to render the `RasterLayer` as an image, each cell value must be converted to an RGB(A) color. You can specify the color scale using the `colors` argument, which accepts a variety of color specifications:
31
+
In order to render the raster object as an image, each cell value must be converted to an RGB(A) color. You can specify the color scale using the `colors` argument, which accepts a variety of color specifications:
38
32
39
33
* The name of a [Color Brewer 2](http://colorbrewer2.org/) palette. If no `colors` argument is provided, then `"Spectral"` is the default.
40
34
* A vector that represents the ordered list of colors to map to the data. Any color specification that is accepted by `grDevices::col2rgb` can be used, including `"#RRGGBB"` and `"#RRGGBBAA"` forms. Example: `colors = c("#E0F3DB", "#A8DDB5", "#43A2CA")`.
0 commit comments