Closed goergen95 closed 3 months ago
This appears to be working as expected. There isn't much variation in cell area over this polygon, so taking it into account doesn't change the results by much.
You are right, I now see that this indeed works as documented. I guess what I am asking is if there is a way to calculate the area per category without using an UDF? Initially, I thought combining weighted_frac
with weights = "area"
would do this. Sorry for the noise! Please feel free to close this issue anytime.
Maybe simpler than using a UDF would be to convert the fraction to an area after the fact, like
library(dplyr)
library(stringr)
v$area <- st_area(v)
exact_extract(r2, v, fun='frac', append_cols='area') |>
mutate(across(starts_with('frac'),
~ .x * area)) |>
rename_with(str_replace, 'frac', 'area', .cols=starts_with('frac')) |>
select(-area)
# area_0 area_1 area_2 area_3 area_4
# 1 98683299 [m^2] 1353811417 [m^2] 2033287011 [m^2] 1146165331 [m^2] 104850999 [m^2]
Yes, this does work, however, requires additional code. Over at mapme.biodiversity we frequently are interested in calculating the area per category and I was hoping this was possible in a more generalized way. Would love to see this implemented here (e.g. something like frac_coverage
or similar), but I also understand if you consider this out of scope.
I've added an upstream issue for this.
Awesome, thanks!
Hi,
thank you for this amazing work!!
I am trying to obtain a
weighted_frac
summary withweights = "area"
. The docs state:https://github.com/isciences/exactextractr/blob/efa5d50d0301df1477a883ac6f6c504c1cf5d8a1/R/exact_extract.R#L172-L175
and:
https://github.com/isciences/exactextractr/blob/efa5d50d0301df1477a883ac6f6c504c1cf5d8a1/R/exact_extract.R#L134-L136
So, given the repex below, I assume that we currently cannot obtain area weighted summaries for
weighted_frac
? If that is actually the case, would it be possible to add that feature?Created on 2024-08-10 with reprex v2.1.0