can the results be visualization?
Closed this issue · 2 comments
vicky-c-c commented
mhesselbarth commented
Hey,
Using sf
objects this is quite straightforward. You just need to transform the resulting tibble
to the wide format, i.e. each row corresponds to a sample point and the values are in the columns . Then, you can simply combine the columns of the sf
object and metrics and finally plot the result.
The following code is adapted from an example created by @Nowosad.
library(landscapemetrics)
library(raster)
library(sf)
library(tidyverse)
# create grid (polygons) to sample metrics
sample_grid <- st_make_grid(augusta_nlcd, n = c(5,5))
sample_grid <- st_sf(geom = sample_grid)
# sample metrics for each grid cell
sample_metrics <- sample_lsm(landscape = augusta_nlcd, y = sample_grid,
level = "landscape", type = "aggregation metric",
verbose = FALSE)
# reshape from long to wide
sample_metrics <- pivot_wider(sample_metrics,
names_from = metric,
values_from = value)
# add to sf object
sample_grid <- bind_cols(sample_grid, sample_metrics)
# plot results
plot(sample_grid["split"])
Created on 2020-01-13 by the reprex package (v0.3.0)
Nowosad commented
@VC826 feel free to reopen the issue if the above answer is not enough.