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

support for terra rasters in fasterize? #39

Open
jldupouey opened this issue Jan 13, 2021 · 2 comments
Open

support for terra rasters in fasterize? #39

jldupouey opened this issue Jan 13, 2021 · 2 comments

Comments

@jldupouey
Copy link

jldupouey commented Jan 13, 2021

fasterize is a great package and I used it intensively with the couple sf/raster. But raster became terra. I checked for different cases, and fasterize is still very competitive in runtime with terra:rasterize (see an example below). But all of the fasterize time savings (and more) are lost in conversions between classes. Thus, it would be useful if fasterize could accept indifferently a vector of sf or SpatVector type, and a raster of raster or terra flavor as input. Is this conceivable?

MyVectTerr
#  class       : SpatVector 
#  geometry    : polygons 
#  dimensions  : 36570, 15  (geometries, attributes)
#  extent      : 99040, 1242445, 6046546, 7110480  (xmin, xmax, ymin, ymax)
#  ...

# rasterize with terra::rasterize:

MyRastTerr <- rast(MyVectTerr)
res(MyRastTerr) <- 100
system.time({
 Res1 <- rasterize(MyVectTerr, MyRastTerr, field="MyField")
 })
#    user  system elapsed 
#   13.81    0.97   14.80

# rasterize with fasterize:

MyVectSp <- as(MyVectTerr, "Spatial")  
MyVectSf <- st_as_sf(MyVectSp)

MyRastRaster <- raster(MyVectSf)
res(MyRastRaster) <- 100 
system.time({
 Res1 <- fasterize(MyVectSf, MyRastRaster, field="MyField")
 })
#    user  system elapsed 
#    1.90    0.04    1.95
@nikosGeography
Copy link

Any news regarding the issue?

@mdsumner
Copy link
Collaborator

it will take a fair bit of work to set up the writing out of blocks to a file. It's on my radar but with no timeline.

I'd prefer to fold the fasterize logic into GDAL itself, then it would be available to terra and other packages automatically also with memory management.

(I would recommend following up on what Even mentioned here: OSGeo/gdal#7200 (comment) that might help performance of terra, but final point - what about exactextractr? - this function should be pretty fast: https://isciences.gitlab.io/exactextractr/reference/rasterize_polygons.html)

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

No branches or pull requests

3 participants