Open MatthieuStigler opened 6 years ago
As for now the dissagregate->extract->aggregate path is probably the best option. A clean implementation in velox would probably require the implementation of a C++ disaggregation method. This isn't at the top of my priority list right now, but I'll keep the issue open until it is.
Hi
I am interested in obtaining the weights of each cell with the function extract, when it is used with fun=NULL (although it could also be useful for fun=fo, weighting results).
I can see two ways:
raster::extract
does it in pseudo-code (see true code in rasterizePolygons.R):r2 <- disaggregate(raster(x), 10) r3 <- "rasterize"(r2) aggregate(r3, 10, sum)
This could be used, although so far the aggregate does not seem to handle NAs (see Issue 9)?
Another approach is to do:
r2 <- raster::disaggregate(raster(x), 10) r3 <- velox::extract(r2, df=TRUE) aggregate the data-frame on cell
I use this approach, and I get identical results to the extract ones. Before going into details, is this necessarily the most efficient? Can you think of a faster way?
Code (based on pull request 14 allowing df=TRUE). This for now uses
raster
package (for disaggregate) andtidyverse
.