Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: strict implementation of extract(<SpatRaster>, <polygons>, touches = FALSE) #1419

Closed
florisvdh opened this issue Feb 5, 2024 · 2 comments

Comments

@florisvdh
Copy link

With regard to terra::extract() I now understand (from https://stackoverflow.com/a/67666183):

Note that terra also returns a value for a polygon that does not cover any cell center. In effect the option touches=TRUE is always used for such polygons to avoid returning NA.

I have a use case where I need to extract cell values for the polygons that effectively intersect with cell centers, returning NA when a polygon is not intersecting cell centers.

  • I think this cannot currently be done with terra::extract()?
  • I'd be happy to see the small = FALSE argument of raster::extract() – or some equivalent implementation – appear in terra::extract().

Actually I'm in doubt whether the default approach – to mix touches = FALSE for polygons that intersect cell centers and touches = TRUE for polygons that don't intersect cell centers – matches the user's expectation of terra::extract(x, y, touches = FALSE). At least it is not documented in ?terra::extract that a hybrid approach is implemented.

An alternative to adding a small argument could be to distinguish a third value touches = "hybrid" to reflect current behaviour instead of FALSE, but then having a strict implementation of touches = FALSE would be a breaking change.

@rhijmans
Copy link
Member

rhijmans commented Feb 6, 2024

Thanks. That was indeed a bit loose. I have opted for adding argument "small=TRUE".

@florisvdh
Copy link
Author

Thanks; the updated package does this well 👍.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants