Title: | Landscape Utility Toolbox |
---|---|
Description: | Provides utility functions for some of the less-glamorous tasks involved in landscape analysis. It includes functions to coerce raster data to the common tibble format and vice versa, it helps with flexible reclassification tasks of raster data and it provides a function to merge multiple raster. Furthermore, 'landscapetools' helps landscape scientists to visualize their data by providing optional themes and utility functions to plot single landscapes, rasterstacks, -bricks and lists of raster. |
Authors: | Marco Sciaini [aut, cre] , Matthias Fritsch [aut], Maximilian H.K. Hesselbarth [aut] , Jakub Nowosad [aut] , Laura Graham [rev] (Laura reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/188), Jeffrey Hollister [rev] (Jeffrey reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/188) |
Maintainer: | Marco Sciaini <[email protected]> |
License: | GPL-3 |
Version: | 0.6.2 |
Built: | 2024-11-27 03:40:22 UTC |
Source: | https://github.com/ropensci/landscapetools |
An example map to show landscapetools functionality generated with the nlm_random() algorithm with factorial values.
classified_landscape
classified_landscape
A raster layer object.
Simulated neutral landscape models with R. https://github.com/ropensci/NLMR/
An example map to show landscapetools functionality generated with the nlm_fbm() algorithm.
fractal_landscape
fractal_landscape
A raster layer object.
Simulated neutral landscape models with R. https://github.com/ropensci/NLMR/
An example map to show landscapetools functionality generated with the nlm_planargradient() algorithm.
gradient_landscape
gradient_landscape
A raster layer object.
Simulated neutral landscape models with R. https://github.com/ropensci/NLMR/
An example map to show landscapetools functionality generated with the nlm_random() algorithm.
random_landscape
random_landscape
A raster layer object.
Simulated neutral landscape models with R. https://github.com/ropensci/NLMR/
Plot a Raster* object with the NLMR default theme (as ggplot).
show_landscape(x, xlab, ylab, discrete, unique_scales, n_col, n_row, ...) ## S3 method for class 'RasterLayer' show_landscape(x, xlab = "Easting", ylab = "Northing", discrete = FALSE, ...) ## S3 method for class 'list' show_landscape( x, xlab = "Easting", ylab = "Northing", discrete = FALSE, unique_scales = FALSE, n_col = NULL, n_row = NULL, ... ) ## S3 method for class 'RasterStack' show_landscape( x, xlab = "Easting", ylab = "Northing", discrete = FALSE, unique_scales = FALSE, n_col = NULL, n_row = NULL, ... ) ## S3 method for class 'RasterBrick' show_landscape( x, xlab = "Easting", ylab = "Northing", discrete = FALSE, unique_scales = FALSE, n_col = NULL, n_row = NULL, ... )
show_landscape(x, xlab, ylab, discrete, unique_scales, n_col, n_row, ...) ## S3 method for class 'RasterLayer' show_landscape(x, xlab = "Easting", ylab = "Northing", discrete = FALSE, ...) ## S3 method for class 'list' show_landscape( x, xlab = "Easting", ylab = "Northing", discrete = FALSE, unique_scales = FALSE, n_col = NULL, n_row = NULL, ... ) ## S3 method for class 'RasterStack' show_landscape( x, xlab = "Easting", ylab = "Northing", discrete = FALSE, unique_scales = FALSE, n_col = NULL, n_row = NULL, ... ) ## S3 method for class 'RasterBrick' show_landscape( x, xlab = "Easting", ylab = "Northing", discrete = FALSE, unique_scales = FALSE, n_col = NULL, n_row = NULL, ... )
x |
Raster* object |
xlab |
x axis label, default "Easting" |
ylab |
y axis label, default "Northing" |
discrete |
If TRUE, the function plots a raster with a discrete legend. |
unique_scales |
If TRUE and multiple raster are to be visualized, each facet can have a unique color scale for its fill |
n_col |
If multiple rasters are to be visualized, n_col controls the number of columns for the facet |
n_row |
If multiple rasters are to be visualized, n_row controls the number of rows for the facet |
... |
Arguments for |
ggplot2 Object
## Not run: x <- gradient_landscape # classify y <- util_classify(gradient_landscape, n = 3, level_names = c("Land Use 1", "Land Use 2", "Land Use 3")) show_landscape(x) show_landscape(y, discrete = TRUE) show_landscape(list(gradient_landscape, random_landscape)) show_landscape(raster::stack(gradient_landscape, random_landscape)) show_landscape(list(gradient_landscape, y), unique_scales = TRUE) ## End(Not run)
## Not run: x <- gradient_landscape # classify y <- util_classify(gradient_landscape, n = 3, level_names = c("Land Use 1", "Land Use 2", "Land Use 3")) show_landscape(x) show_landscape(y, discrete = TRUE) show_landscape(list(gradient_landscape, random_landscape)) show_landscape(raster::stack(gradient_landscape, random_landscape)) show_landscape(list(gradient_landscape, y), unique_scales = TRUE) ## End(Not run)
Opinionated ggplot2 theme to visualize NLM raster.
theme_nlm( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = base_size, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = ggplot2::unit(c(0, 0, 0, 0), "lines"), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE, legend_title = "Z", legend_labels = NULL, legend_text_size = 8, legend_title_size = 10, ratio = 1, viridis_scale = "D", ... ) theme_nlm_discrete( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = base_size, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = ggplot2::unit(c(0, 0, 0, 0), "lines"), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE, legend_title = "Z", legend_labels = NULL, legend_text_size = 8, legend_title_size = 10, ratio = 1, viridis_scale = "D", ... ) theme_nlm_grey( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = base_size, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = ggplot2::unit(c(0, 0, 0, 0), "lines"), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE, legend_title = "Z", legend_labels = NULL, legend_text_size = 8, legend_title_size = 10, ratio = 1, ... ) theme_nlm_grey_discrete( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = base_size, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = ggplot2::unit(c(0, 0, 0, 0), "lines"), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE, legend_title = "Z", legend_labels = NULL, legend_text_size = 8, legend_title_size = 10, ratio = 1, ... ) theme_facetplot( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, ratio = 1, viridis_scale = "D", ... ) theme_facetplot_discrete( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, ratio = 1, viridis_scale = "D", ... )
theme_nlm( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = base_size, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = ggplot2::unit(c(0, 0, 0, 0), "lines"), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE, legend_title = "Z", legend_labels = NULL, legend_text_size = 8, legend_title_size = 10, ratio = 1, viridis_scale = "D", ... ) theme_nlm_discrete( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = base_size, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = ggplot2::unit(c(0, 0, 0, 0), "lines"), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE, legend_title = "Z", legend_labels = NULL, legend_text_size = 8, legend_title_size = 10, ratio = 1, viridis_scale = "D", ... ) theme_nlm_grey( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = base_size, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = ggplot2::unit(c(0, 0, 0, 0), "lines"), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE, legend_title = "Z", legend_labels = NULL, legend_text_size = 8, legend_title_size = 10, ratio = 1, ... ) theme_nlm_grey_discrete( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = base_size, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = ggplot2::unit(c(0, 0, 0, 0), "lines"), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE, legend_title = "Z", legend_labels = NULL, legend_text_size = 8, legend_title_size = 10, ratio = 1, ... ) theme_facetplot( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, ratio = 1, viridis_scale = "D", ... ) theme_facetplot_discrete( base_family = NA, base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = NA, subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip.background = "grey80", caption_family = NA, caption_size = 9, caption_face = "plain", caption_margin = 10, ratio = 1, viridis_scale = "D", ... )
base_family |
base font family size |
base_size |
base font size |
plot_title_family |
plot title family |
plot_title_size |
plot title size |
plot_title_face |
plot title face |
plot_title_margin |
plot title ggplot2::margin |
subtitle_family |
plot subtitle family |
subtitle_size |
plot subtitle size |
subtitle_face |
plot subtitle face |
subtitle_margin |
plot subtitle ggplot2::margin bottom (single numeric value) |
strip_text_family |
facet facet label font family |
strip_text_size |
facet label font family, face and size |
strip_text_face |
facet facet label font face |
strip.background |
strip background |
caption_family |
plot caption family |
caption_size |
plot caption size |
caption_face |
plot caption face |
caption_margin |
plot caption ggplot2::margin |
axis_text_size |
axis text size |
axis_title_family |
axis title family |
axis_title_size |
axis title size |
axis_title_face |
axis title face |
axis_title_just |
axis title justification |
plot_margin |
plot ggplot2::margin (specify with 'ggplot2::margin“) |
grid_col |
grid color |
grid |
grid TRUE/FALSE |
axis_col |
axis color |
axis |
axis TRUE/FALSE |
ticks |
ticks TRUE/FALSE |
legend_title |
Title of the legend (default |
legend_labels |
Labels for the legend ticks, if
used with |
legend_text_size |
legend text size, default 8 |
legend_title_size |
legend text size, default 10 |
ratio |
ratio for tiles (default 1, if your raster is not a square the ratio should
be |
viridis_scale |
Five options are available: "viridis - magma" (= "A"), "viridis - inferno" (= "B"), "viridis - plasma" (= "C"), "viridis - viridis" (= "D", the default option), "viridis - cividis" (= "E") |
... |
optional arguments to ggplot2::theme |
A focused theme to visualize raster data that sets a lot of defaults for the
ggplot2::theme
.
The functions are setup in such a way that you can customize your own one by just wrapping the call and changing the parameters. The theme itself is heavily influenced by hrbrmstr and his package hrbrthemes (https://github.com/hrbrmstr/hrbrthemes/).
Coerces raster values to integers
util_as_integer(x) ## S3 method for class 'RasterLayer' util_as_integer(x)
util_as_integer(x) ## S3 method for class 'RasterLayer' util_as_integer(x)
x |
raster |
Coerces raster values to integers, which is sometimes needed if you want further methods that rely on integer values.
RasterLayer
# Mode 1 util_as_integer(fractal_landscape)
# Mode 1 util_as_integer(fractal_landscape)
Classify continuous raster values into binary map cells based upon given
break(s
).
util_binarize(x, breaks) ## S3 method for class 'RasterLayer' util_binarize(x, breaks)
util_binarize(x, breaks) ## S3 method for class 'RasterLayer' util_binarize(x, breaks)
x |
Raster* object |
breaks |
Vector with one or more break percentages |
Breaks are considered to be habitat percentages (p
). If more than
one percentage is given multiple layers are written in the same brick.
RasterLayer / RasterBrick
breaks <- c(0.3, 0.5) binary_maps <- util_binarize(gradient_landscape, breaks)
breaks <- c(0.3, 0.5) binary_maps <- util_binarize(gradient_landscape, breaks)
Classify continuous landscapes into landscapes with discrete classes
util_classify(x, n, weighting, level_names, real_land, mask_val) ## S3 method for class 'RasterLayer' util_classify( x, n = NULL, weighting = NULL, level_names = NULL, real_land = NULL, mask_val = NULL )
util_classify(x, n, weighting, level_names, real_land, mask_val) ## S3 method for class 'RasterLayer' util_classify( x, n = NULL, weighting = NULL, level_names = NULL, real_land = NULL, mask_val = NULL )
x |
raster |
n |
Number of classes |
weighting |
Vector of numeric values that are considered to be habitat percentages (see details) |
level_names |
Vector of names for the factor levels. |
real_land |
Raster with real landscape (see details) |
mask_val |
Value to mask (refers to real_land) |
Mode 1: Calculate the optimum breakpoints using Jenks natural
breaks optimization, the number of classes is determined with n
.
The Jenks optimization seeks to minimize the variance within categories,
while maximizing the variance between categories.
Mode 2: The number of elements in the weighting vector determines the number of classes in the resulting matrix. The classes start with the value 1. If non-numerical levels are required, the user can specify a vector to turn the numerical factors into other data types, for example into character strings (i.e. class labels). If the numerical vector of weightings does not sum up to 1, the sum of the weightings is divided by the number of elements in the weightings vector and this is then used for the classificat#' .
Mode 3: For a given 'real' landscape the number of classes and the weightings are extracted and used to classify the given landscape (any given weighting parameter is overwritten in this case!). If an optional mask value is given the corresponding class from the 'real' landscape is cut from the landscape beforehand.
RasterLayer
## Not run: # Mode 1 util_classify(fractal_landscape, n = 3, level_names = c("Land Use 1", "Land Use 2", "Land Use 3")) # Mode 2 util_classify(fractal_landscape, weighting = c(0.5, 0.25, 0.25), level_names = c("Land Use 1", "Land Use 2", "Land Use 3")) # Mode 3 real_land <- util_classify(gradient_landscape, n = 3, level_names = c("Land Use 1", "Land Use 2", "Land Use 3")) fractal_landscape_real <- util_classify(fractal_landscape, real_land = real_land) fractal_landscape_mask <- util_classify(fractal_landscape, real_land = real_land, mask_val = 1) landscapes <- list( '1 nlm' = fractal_landscape, '2 real' = real_land, '3 result' = fractal_landscape_real, '4 result with mask' = fractal_landscape_mask ) show_landscape(landscapes, unique_scales = TRUE, nrow = 1) ## End(Not run)
## Not run: # Mode 1 util_classify(fractal_landscape, n = 3, level_names = c("Land Use 1", "Land Use 2", "Land Use 3")) # Mode 2 util_classify(fractal_landscape, weighting = c(0.5, 0.25, 0.25), level_names = c("Land Use 1", "Land Use 2", "Land Use 3")) # Mode 3 real_land <- util_classify(gradient_landscape, n = 3, level_names = c("Land Use 1", "Land Use 2", "Land Use 3")) fractal_landscape_real <- util_classify(fractal_landscape, real_land = real_land) fractal_landscape_mask <- util_classify(fractal_landscape, real_land = real_land, mask_val = 1) landscapes <- list( '1 nlm' = fractal_landscape, '2 real' = real_land, '3 result' = fractal_landscape_real, '4 result with mask' = fractal_landscape_mask ) show_landscape(landscapes, unique_scales = TRUE, nrow = 1) ## End(Not run)
This function creates a series of circular buffers around spatial points and computes
the frequency of each value of a raster within the buffers; the results are printed in
a data.frame
.
util_extract_multibuffer( landscape, points, buffer_width, max_width = NULL, rel_freq = FALSE, fun = NULL, point_id_text = TRUE, ... )
util_extract_multibuffer( landscape, points, buffer_width, max_width = NULL, rel_freq = FALSE, fun = NULL, point_id_text = TRUE, ... )
landscape |
|
points |
Point(s) represented by a two-column matrix or |
buffer_width |
Buffer widths in which the frequency of landscape values is measured.
It might be either a single value or a vector of buffer sizes, if |
max_width |
Maximum distance to which buffer_width is summed up. If |
rel_freq |
Logical. If |
fun |
Function to apply to raster values within the buffer (e.g. "median", "mean"). |
point_id_text |
Logical. If |
... |
additional arguments (none implemented) |
A tibble with the frequency of each raster value within the buffers of different sizes
around each point. Alternatively, a tibble with the relative frequency of raster values, if rel_freq = TRUE
,
or a function from the raster values, if fun
is provided.
# create single point new_point = matrix(c(75,75), ncol = 2) # show landscape and point of interest show_landscape(classified_landscape, discrete = TRUE) + ggplot2::geom_point(data = data.frame(x = new_point[,1], y = new_point[,2]), ggplot2::aes(x = x, y = y), col = "grey", size = 3) # extract frequency of each pixel value within each buffer from 10 to 50 m width util_extract_multibuffer(classified_landscape, new_point, 10, 50) # use irregular buffer sizes util_extract_multibuffer(classified_landscape, new_point, c(5, 10, 20, 30)) # also returns relative frequency util_extract_multibuffer(classified_landscape, new_point, 10, 50, rel_freq = TRUE) # use a given function - e.g. median in each buffer width util_extract_multibuffer(classified_landscape, new_point, 10, 50, fun = "median") # show multiple points share new_points = matrix(c(75, 110, 75, 30), ncol = 2) util_extract_multibuffer(classified_landscape, new_points, c(5, 10, 20, 30))
# create single point new_point = matrix(c(75,75), ncol = 2) # show landscape and point of interest show_landscape(classified_landscape, discrete = TRUE) + ggplot2::geom_point(data = data.frame(x = new_point[,1], y = new_point[,2]), ggplot2::aes(x = x, y = y), col = "grey", size = 3) # extract frequency of each pixel value within each buffer from 10 to 50 m width util_extract_multibuffer(classified_landscape, new_point, 10, 50) # use irregular buffer sizes util_extract_multibuffer(classified_landscape, new_point, c(5, 10, 20, 30)) # also returns relative frequency util_extract_multibuffer(classified_landscape, new_point, 10, 50, rel_freq = TRUE) # use a given function - e.g. median in each buffer width util_extract_multibuffer(classified_landscape, new_point, 10, 50, fun = "median") # show multiple points share new_points = matrix(c(75, 110, 75, 30), ncol = 2) util_extract_multibuffer(classified_landscape, new_points, c(5, 10, 20, 30))
Merge a primary raster with other rasters weighted by scaling factors.
util_merge(primary_nlm, secondary_nlm, scalingfactor = 1, rescale) ## S3 method for class 'RasterLayer' util_merge(primary_nlm, secondary_nlm, scalingfactor = 1, rescale = TRUE)
util_merge(primary_nlm, secondary_nlm, scalingfactor = 1, rescale) ## S3 method for class 'RasterLayer' util_merge(primary_nlm, secondary_nlm, scalingfactor = 1, rescale = TRUE)
primary_nlm |
Primary |
secondary_nlm |
A list or stack of |
scalingfactor |
Weight for the secondary |
rescale |
If |
Rectangular matrix with values ranging from 0-1
x <- util_merge(gradient_landscape, random_landscape) show_landscape(x)
x <- util_merge(gradient_landscape, random_landscape) show_landscape(x)
Writes spatial raster values into tibble and adds coordinates.
util_raster2tibble(x, format = "long") util_raster2tibble(x, format = "long")
util_raster2tibble(x, format = "long") util_raster2tibble(x, format = "long")
x |
Raster* object |
format |
Either "long" (default) or "wide" output for the resulting tibble |
You will loose any resolution, extent or reference system. The output is raw tiles.
a tibble
maptib <- util_raster2tibble(fractal_landscape) ## Not run: library(ggplot2) ggplot(maptib, aes(x,y)) + coord_fixed() + geom_raster(aes(fill = z)) ## End(Not run)
maptib <- util_raster2tibble(fractal_landscape) ## Not run: library(ggplot2) ggplot(maptib, aes(x,y)) + coord_fixed() + geom_raster(aes(fill = z)) ## End(Not run)
Linearly rescale element values in a raster to a range between 0 and 1.
util_rescale(x) util_rescale(x)
util_rescale(x) util_rescale(x)
x |
Raster* object |
Rasters generated by nlm_
functions are scaled between 0 and 1 as default, this option can be set to FALSE
if needed.
Raster* object with values ranging from 0-1
unscaled_landscape <- gradient_landscape + fractal_landscape util_rescale(unscaled_landscape)
unscaled_landscape <- gradient_landscape + fractal_landscape util_rescale(unscaled_landscape)
Writes spatial tibble values into a raster.
util_tibble2raster(x) util_tibble2raster(x)
util_tibble2raster(x) util_tibble2raster(x)
x |
a tibble |
Writes tiles with coordinates from a tibble into a raster. Resolution is set to 1 and the extent will be c(0, max(x), 0, max(y)).
You can directly convert back the result from 'util_raster2tibble()' without problems. If you have altered the coordinates or otherwise played with the data, be careful while using this function.
Raster* object
maptib <- util_raster2tibble(random_landscape) mapras <- util_tibble2raster(maptib) all.equal(random_landscape, mapras)
maptib <- util_raster2tibble(random_landscape) mapras <- util_tibble2raster(maptib) all.equal(random_landscape, mapras)
Export raster objects as ESRI ascii files.
util_writeESRI(x, filepath) ## S3 method for class 'RasterLayer' util_writeESRI(x, filepath)
util_writeESRI(x, filepath) ## S3 method for class 'RasterLayer' util_writeESRI(x, filepath)
x |
Raster* object |
filepath |
path where to write the raster to file |
raster::writeRaster
or SDMTools::write.asc
both
export files that are recognised by most GIS software, nevertheless
they both have UNIX linebreaks.
Some proprietary software (like SPIP for example) require an exact 1:1
replica of the output of ESRI's ArcMap, which as a Windows software
has no carriage returns at the end of each line.
util_writeESRI
should therefore only be used if you need this,
otherwise raster::writeRaster
is the better fit for exporting
raster data in R.
## Not run: util_writeESRI(gradient_landscape, "gradient_landscape.asc") ## End(Not run)
## Not run: util_writeESRI(gradient_landscape, "gradient_landscape.asc") ## End(Not run)