r-spatialecology/landscapemetrics

Processing LPI with missing values

Closed this issue · 1 comments

Hi,

Since my question seems to be related to this discussion, I decided to post it here.

I'm using landscapemetrics_1.5.2 and R-version is 4.0.3 on OSx.

I have these:

  • A classified raster with 4 categories (1-4).
  • A 5m grid
    My goal:
    To get the LPI values at each 5-m grid for one specific class(i.e. 3)

This is the resulting LPI (point shape) where each point has the corresponding LPI value at each cell based on the classified raster.

image

There are two cases where I get NA's. First, at the edges where no presence of any of the classes (i.e. in the image at the top left corner) and the other case, within the imagery (examples in red rectangles in image), where my class(3) is not present or just few pixels scattered. In the latter case, I have been just wrangling the resulting tables to switch LPI value from NA to a 0 in those cases when another class is present within the cell-grid, so I can discern from those truly NA's (top)?

Is there any way to get 0's instead of NA's in those cases where there's other classes within a cell-grid?

When resulting LPI is too low or 0 (no presence of pixels or few scattered ones), it is just set to NA, right?

Best,
Guillermo

Originally posted by @gponce-ars in #215 (comment)

Correct me if I am wrong, but your problem can be shortly described as:

  1. Leave NA where there is no data in a grid cell.

  2. Change values to 0, where just a few scattered pixels exist.

If so - you probably need to do some additional steps. There are many approaches possible, but one would be to calculate some other landscape metric, for example, total area (lsm_l_ta). Using this metric, you will get NA when there is no pixels with values, and some values above zero otherwise. Next, you can use ifelse to update values of LPI - if the total area is not NA but LPI is NA, then change LPI to zero.