Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow classes for window_lsm() #211

Open
mhesselbarth opened this issue Sep 17, 2020 · 3 comments
Open

Allow classes for window_lsm() #211

mhesselbarth opened this issue Sep 17, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@mhesselbarth
Copy link
Member

Allow also class level metrics for window lsm.

Either specify focal class beforehand or return RasterStack in which each layer represents a class.

@mhesselbarth mhesselbarth added the enhancement New feature or request label Sep 17, 2020
@Nowosad
Copy link
Member

Nowosad commented Sep 18, 2020

I would suggest the second option (RasterStack) or, if possible both options.

(We should also wait for the email reply before committing to any solutions...)

@mhesselbarth
Copy link
Member Author

I think you were not included in the reply, sorry (I just forwarded it to you).

I think something similar to e.g. the class argument in e.g. show_lsm() would be cool. So basically it possible to get all classes or only selected ones. From a computational point, we need to calculate all classes anyways and then either just return one specific class or all.

@bitbacchus
Copy link
Member

From a computational point, we need to calculate all classes anyways and then either just return one specific class or all.

Not necessarily, I think. I'm just hacking a class-level moving-window version of ed for myself and I just reclassify everything except the focal class to NA. Then I added an optional count_background_NA option to lsm_l_ed:

library(landscapemetrics)
library(raster)

landscape <- landscapemetrics::landscape
window <- matrix(1, nrow = 5, ncol = 5)
f_class <- 1
classes <- raster::unique(landscape)
bg_classes <- classes[classes != f_class]

for (bg in bg_classes) {
    landscape <- raster::reclassify(landscape, cbind(bg, NA))
}

ed_map <- landscapemetrics::window_lsm(landscape = landscape, 
                                       window = window, 
                                       what = c("lsm_l_ed"))
ed_map <- ed_map[[1]]
landscapetools::show_landscape(ed_map)

Created on 2022-07-06 by the reprex package (v2.0.1)

This required tweaking lsm_l_ed and raster:::focal_fun, however...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants