mstrimas / smoothr

Spatial Feature Smoothing in R
http://strimas.com/smoothr
GNU General Public License v3.0
96 stars 5 forks source link

Support for raster::RasterLayer #5

Open michelk opened 3 years ago

michelk commented 3 years ago

This is a follow up of https://github.com/wilkelab/isoband/issues/17, where I wanted to smooth contour lines of a digital terrain model. Since your smooth function operates on the polygons separately, the resulting data sets contain little overlaps and gaps.

Does it make sens in your opinion to add raster support in the smooth R-package?

mstrimas commented 3 years ago

Smoothing isolines is an interesting use case. As you've already discovered, smoothr uses a very simple approach to smoothing where each feature is treated independently, which means it doesn't preserve the relationships between features. In addition to not being suitable for isolines, this also means smoothr doesn't work on things like country borders where you'd want to preserve the boundary between countries. It would be amazing if the package did preserve topological relationships, however, implementing that is way beyond what I'm capable of. I've added a warning to the package README that smoothing doesn't preserve topological relationships so shouldn't be used on isolines.

Regarding your specific question in this issue about adding raster smoothing to the package. The intention of the package was to be for vector data, but I suppose I'm potentially open to adding a smooth_raster() method. I have no experience smoothing raster data though, so I'd need to understand what the best approach for smoothing is. I see in the linked issue you disaggregate the raster then apply a moving window filter via focal(), is that generally considered the best practice for this sort of task?

michelk commented 3 years ago

I'm also not into those topics and couldn't tell anything about best-practices. Maybe the raster::interpolate function could also be used for that.

mstrimas commented 3 years ago

Ok, I'll leave this issue open for now, when I have some spare time I'll investigate the best approach for this and consider adding a function for raster smoothing.

michelk commented 3 years ago

https://geocompr.robinlovelace.net/geometric-operations.html#simplification mentions rmapshaper::ms_simplify, where topology is preserved in the simplification process. Maybe this could also inspire smoothing where topology is preserved.