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

Should "simple" and "bilinear" methods in extract return the same results? #884

Closed
kadyb opened this issue Nov 8, 2022 · 4 comments
Closed

Comments

@kadyb
Copy link
Contributor

kadyb commented Nov 8, 2022

I thought "bilinear" method would smooth out the values compared to "simple". Is this expected?

library("terra")

f = system.file("ex/logo.tif", package = "terra")
r = rast(f)[[1]]
pts = spatSample(r, 100, method = "regular", values = FALSE, as.points = TRUE)

smp1 = extract(r, pts, method = "simple", ID = FALSE)
smp2 = extract(r, pts, method = "bilinear", ID = FALSE)

all.equal(smp1, smp2)
#> TRUE
@rhijmans
Copy link
Member

rhijmans commented Nov 8, 2022

It does, except when a point is smack in the middle of a cell, because in that case that cell gets infinite weight (1/0). And that is what you get when you sample raster cells. But if sample the extent things are different.

library("terra")
f = system.file("ex/logo.tif", package = "terra")
r = rast(f)[[1]]

pts = spatSample(as.polygons(r, ext=TRUE), 100)
smp1 = extract(r, pts, method = "simple", ID = FALSE)
smp2 = extract(r, pts, method = "bilinear", ID = FALSE)

all.equal(smp1, smp2)

@kadyb
Copy link
Contributor Author

kadyb commented Nov 8, 2022

Thanks for the explanation!

@kadyb kadyb closed this as completed Nov 8, 2022
@kadyb
Copy link
Contributor Author

kadyb commented Nov 9, 2022

BTW: I get:

pts = spatSample(as.polygons(r, ext=TRUE), 100)
Error: [] Cannot do this transformation
In addition: Warning message:
Cannot find coordinate operations from `ENGCRS["Cartesian (Meter)",EDATUM[""],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]]]' to `EPSG:4326' (GDAL error 6) 

I have GDAL 3.5.2 and terra 1.6.38.

Edit: This works in terra 1.6.17. This is regression from #797.

@rhijmans
Copy link
Member

rhijmans commented Nov 9, 2022

Thanks. That is because I changed the crs to "local". It works now, albeit with a warning.

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