isciences / exactextractr

R package for fast and accurate raster zonal statistics
https://isciences.gitlab.io/exactextractr/
274 stars 26 forks source link

Can I extract rater values along a polyline or the outline of a polygon? #48

Closed chljl closed 3 years ago

chljl commented 3 years ago

For example along a stream or the boundary of a subbasin in a watershed. This will be a useful functionality for my work.

dbaston commented 3 years ago

Not directly. You can hack it by converting the polygon to a line, then buffering it slightly:

exact_extract(rast, st_buffer(st_cast(poly, 'MULTILINESTRING'), 1e-6), include_cell = TRUE, include_xy = TRUE)

The values of the coverage_fraction column will be meaningless, but this will identify the intersected cells and their values.

I've thought of having exact_extract handle linear inputs directly, providing the length of intersection between the line and each cell in place of the coverage fraction.