Skip to content

Instantly share code, notes, and snippets.

@dbaston

dbaston/test.R Secret

Created March 10, 2020 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbaston/3f21c3c399021f3b5aace12e4f09a495 to your computer and use it in GitHub Desktop.
Save dbaston/3f21c3c399021f3b5aace12e4f09a495 to your computer and use it in GitHub Desktop.
R raster::extract partial coverage
library(raster)
library(sf)
r <- raster(matrix(1:100, nrow=10, ncol=10), xmn=0, xmx=1, ymn=0, ymx=1)
p <- st_as_sfc('POLYGON ((0.90 1.05, 1.05 0.95, 1.05 1.05, 0.90 1.05))')
plot(r)
plot(p, add=TRUE)
extract(r, as(p, 'Spatial'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment