-
Notifications
You must be signed in to change notification settings - Fork 86
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
Resample() cuts off pixels when extents are different #847
Comments
Here is a reproducible example of this issue that does not depend on files. It shows that cells that cross the boundaries of cells they are resampled to are not treated consistently. Example data
There are 25 cells of Aggregate and resample give the same result if the rasters are aligned
The red blocks are the cells in Now shift
But with the "right" tweaking, it can be really terrible
At this point, I am just trying to understand the problem. I do not know where this goes wrong (in terra or the GDALwarp method that is called in this case) |
The same happens when directly calling the gdalwarp tool (via sf). I created the input file with the code above and
And you can download it herehttps://github.com/rspatial/files/blob/master/f.tif
|
The same problem with using "max", but with an older version of gdalwarp
And
The results are good. In this case, each cell has the value 1. The option "-r sum" is not available in this version of GDAL,
But not with GDAL 3.4.3
And with the R script I get a good result too on the system with GDAL 2.2.3
|
Thank you very much for looking into this so thoroughly! |
This should now work with the development version of GDAL. The current version is 3.5.2; it was released in Sept 2022. It may take a while (several months at least) before the new version of GDAL is released and incorporated into the windows version of terra. |
Hello, I am not sure if this is a user-side error, but I wanted to report it in case it is not.
I have two rasters, a fine raster with resolution 0.1m (link) and a rough raster with resolution 0.5m (link). I want to resample the fine raster to the rough raster using the maximum value per cell. Also, I want the cells of the new raster to overlap with the cells of the old rough raster. I tried this using
resample()
, but it cuts off cells at the edges which contain only few cells in the fine raster:Plotting the rough and fine raster on top of each other:
Plotting the new raster which is missing 4 pixels:
I noticed I don't have this issue when changing the extent of the fine raster previously:
(Though here, I end up with too many cells, most likely because of #844.)
I don't know if this is intended behaviour or not. I think I was mislead by the documentation of
resample()
because it says "If the origin and extent of the input and output are the same, you should consider using these other functions instead: aggregate, disagg, extend or crop.", which sounds like resample would be able to handle the different extents.)The text was updated successfully, but these errors were encountered: