ecohealthalliance / fasterize

High performance raster conversion for modern spatial data 🚀🌏▦
https://ecohealthalliance.github.io/fasterize/
Other
182 stars 15 forks source link

Faster rasterToPolygons() #12

Closed adrfantini closed 5 years ago

adrfantini commented 7 years ago

I know a faster alternative to rasterToPolygons was in the plans, is this still true? Using st_as_sf(stars(file)) instead of as(rasterToPolygons(raster(file)), "sf") is an option, but still it's not as fast as one would like (about 2x faster in my limited tests), and stars is still in it's infancy so bugs and incompatibilities are present.

EDIT: maybe something similar, through GDAL, has already been attempted: https://gist.github.com/johnbaums/26e8091f082f2b3dd279#file-polygonizer-r https://johnbaumgartner.wordpress.com/2012/07/26/getting-rasters-into-shape-from-r/

EDIT2: spex::polygonize might be the answer. It's crazy fast compared to rasterToPolygons, about 10x as fast from my tests.

noamross commented 6 years ago

I'm catching up on issues in this repo after a long delay, sorry! Yes, this is in the works, I've done some initial testing and it will be considerably faster than spex. But I don't think it'll happen until early summer.

adrfantini commented 6 years ago

Awesome :)

See my stars issue where I delineate performance numbers. Edzer was thinking of building gdal_polygonize into gdal_utils.

fabien-w commented 5 years ago

Dear Noam, is your faster alternative to RasterToPolygon available ? Thank you very much.

adrfantini commented 5 years ago

If you can use stars instead of raster, st_as_sf(..., point = FALSE, merge = TRUE, connect8 = TRUE) is now very fast, since it uses GDAL directly.

noamross commented 5 years ago

Claus Wilke's isoband package also has a fast implementation now: https://github.com/wilkelab/isoband . I don't think I am likely to implement this given the options available.