rspatial / raster

R raster package https://rspatial.github.io/raster/reference/raster-package.html
GNU General Public License v3.0
161 stars 53 forks source link

Bilinear resample is slow, and surprisingly faster than ngb (nearest neighbour). #327

Closed gluijk closed 8 months ago

gluijk commented 8 months ago

I needed to do a fast resample of a raster and tried ngb (nearest neighbour) which should be nearly instantaneous since NN doesn't compute anything, just picks preexisting values. To my surprise it took ages to finish. I then tried bilinear just in case (expecting even longer times), and to my surprise again it was faster than ngb. It was considerably slow anyway. Not sure if resizing functions are very well optimised in the package.

rhijmans commented 8 months ago

"raster" is no longer further developed. It has been replaced by "terra" and I think you will find that these methods are much faster in "terra".

gluijk commented 8 months ago

Thanks Robert. I installed the terra package and compared speed execution vs raster. Times improved dramatically, specially resample. I expected a bit more on reproject but still fine.

# IMPROVEMENTS terra/raster
# action          raster      terra       unit  terra/raster
# REPROJECT       4.666385    1.858117    min   39.8%
# PLOT            103.1214    10.92895    s     10.6%
# CROP            4.796154    2.65933     s     55.4%
# RESAMPLE        25.8529     1.710264    s     6.6%