-
Notifications
You must be signed in to change notification settings - Fork 8
Spanner PatchMorph Raster Processing Example
This script demonstrates the process of manipulating and visualizing rasters using spanner
library's patch morphology functionalities. The example includes setting up suitability levels, gap and spur distances, processing rasters, and visualizing the results.
library(spanner)
The input raster is set using the system.file
function to point to an example raster within the spanner
package.
# Set the path to the input raster and read it as a terra::rast
r <- system.file("extdata", "FtValleyClipCHM.tif", package="spanner")
r <- terra::rast(r)
Set the suitability levels, gap distances, and spur distances to define the conditions for patch morphology analysis.
# Define the suitability levels, gap distances, and spur distances
suitList <- c(-Inf, 2, Inf)
gapList <- seq(2, 10, by = 2)
spurList <- seq(2, 10, by = 2)
-
suitList
: Suitability levels defining thresholds for raster processing. -
gapList
: Range of gap distances in the raster. -
spurList
: Range of spur distances.
This function processes the rasters based on the patchmorph parameters defined above.
# Process the rasters based on the patchmorph parameters
rasters <- process_rasters_patchmorph(r, suitList, gapList, spurList)
You can plot a specific raster from the result using its name, as shown below.
# Plot the raster named "suit_2_gap_2_spur_10"
plot_raster_by_name(rasters, "suit_2_gap_2_spur_10")
This function generates a list of summed rasters based on suitability levels.
# Get a list of summed rasters
rSumList <- sum_rasters_by_suitability(rasters, suitList)
You can plot a specific summed raster by its name.
# Plot the raster named "suit_2_sum"
plot_raster_by_name(rSumList, "suit_2_sum")