Closed Sm665 closed 4 months ago
Hey,
Thanks for your question but I am not sure I understand the issue. You can calculate landscape-level metrics using the moving window approach.
library(landscapemetrics)
library(terra)
#> terra 1.7.78
# import example landscape
landscape <- terra::rast(landscape)
# # show all metrics on landscape level
# list_lsm(level = "landscape")
# define window
window <- matrix(1, nrow = 5, ncol = 5)
# calculate moving window using two landscape level metrics
res <- window_lsm(landscape, window = window, what = c("lsm_l_pr", "lsm_l_joinent"))
# plot one example result
plot(res$layer_1$lsm_l_pr)
Created on 2024-07-01 with reprex v2.1.0
If you still have a problem, please reopen this issue.
res <- window_lsm(landscape, window = window, what = c("lsm_l_pr", "lsm_l_joinent")) after ran the code i got the error- Error in Use Method("landscape_as_list") : no applicable method for 'landscape_as_list' applied to an object of class "PackedSpatRaster
@Sm665 have you run this line beforehand: landscape <- terra::rast(landscape)
?
yes after run i got these---
> terra 1.7.78
import example landscape
201 < - terra::rast("Landcover_4.tif") class : SpatRaster dimensions : 1148, 1478, 1 (nrow, ncol, nlyr) resolution : 30, 30 (x, y) extent : 479265, 523605, 2606865, 2641305 (xmin, xmax, ymin, ymax) coord. ref. : WGS 84 / UTM zone 45N (EPSG:32645) source(s) : memory varname : Landcover_4 name : Name min value : FALSE max value : FALSE
define window
window <- matrix(1, nrow = 5, ncol = 5)
calculate moving window using two landscape level metrics
res <- window_lsm(landscape, window = window, what = c("lsm_l_pr", "lsm_l_joinent")) Error in UseMethod("landscape_as_list") : no applicable method for 'landscape_as_list' applied to an object of class "PackedSpatRaster"
plot one example result
res <- window_lsm(landscape, window = window, what = c("lsm_l_pr", "lsm_l_joinent")) when i replaced landscape by 201 (R directory/folder) i got
calculate moving window using two landscape level metrics
res <- window_lsm(201, window = window, what = c("lsm_l_pr", "lsm_l_joinent")) Error: unable to find an inherited method for function ‘res’ for signature ‘x = "numeric"’
You can't name an object using a numeric number. So please exchange the following line 201 <- terra::rast("Landcover_4.tif")
with something like landcover_4 <- terra::rast("Landcover_4.tif")
and then run window_lsm(landcover_4 , window = window, what = c("lsm_l_pr", "lsm_l_joinent"))
again
I made the changes you asked for and the code is working. Thanks for the code and help. I got the image Can you tell me from the image how I can do such a gradient analysis. see the image for your understanding, I attached the paper GIS based Gradient Analysis.pdf
@Sm665 the GitHub issues are for bug reports and other code discussions (e.g., enchantments); there are other places to ask questions, such as https://gis.stackexchange.com/
I want to moving window analysis, and for that I need landscape-level metrics but R Studio only shows patch-level metrics, not landscape-level. How will I solve the problem? I installed raster, sf, sp, landscapemetrics, landscapetools, ggplot2 packages.