View source: R/process_raster.R
match_legend_colors | R Documentation |
Colors provided by the legend do not always correspond exactly with the colors in the coltab of a SpatRaster object. They are usually pretty close, though, so this function finds the closest colors, maps them to the appropriate colors in the Raster* object, and applies that to the legend.
match_legend_colors(legend, raster_cols)
legend |
An object of class raster_legend as returned by
|
raster_cols |
The colortable from a SpatRaster object. Use the first item in the list |
Raster colors in x
are mapped to those in legend
by converting
the RGB hexadecimal values to a 3D vector of values for red, green and blue.
The closest values are then assigned using 3D Pythagorean theorem to compute
the distance among all colors. The minimum distance in three dimensional
space is the color in x
that gets mapped to the appropriate color in
legend
.
A raster_legend object with corrected colors to match those in
x
## Not run:
wi_landcover <- get_map_layer(wi_landcover_url, wis_poly)
legend <- get_layer_legend(wi_landcover_url)
new_legend <- match_legend_colors(legend, wi_landcover_url)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.