Cidree / rpostgis

rpostgis: R Interface to a 'PostGIS' Database
http://cidree.github.io/rpostgis/
77 stars 14 forks source link

pgWriteRast SnapToGrid causes Raster resizing and mismatch #14

Closed isoneo closed 5 years ago

isoneo commented 5 years ago

I have been trying to get pgWriteRast to work for some large raster files. Example raster file I'm having issues with https://ufile.io/25trv

I am getting warnings / error "NOTICE: Cannot set value for pixel( x, y) outside raster bounds: X' x Y' ". I dug around a bit and it seems like Line 175 through 180 ST_SnapToGrid is changing the Raster width / height and causing mismatch once you get to Line 189 through 194 where you update pixel values. Could you fix this issue perhaps by adding band within b==1 loop but SnapToGrid after pixel value update?

dnbucklin commented 5 years ago

Hi @isoneo ,

Thanks for trying out rpostgis. We hadn't tested this function on irregular grid resolutions (unequal x/y spacing), as is the case with your example raster. The function ST_SnapToGrid was assuming equal x/y, which was causing the issue. I've patched it in 5b3cec0 and it appears to be working with your test raster.

If you get a chance to test and run into any other issues, that would be great to know. You can install the latest version with:

devtools::install_github("mablab/rpostgis", "dev")

Also, since pgWriteRast is a pure-R solution, it's not very efficient for large rasters. If you have a lot of large raster to process you'll probably want to use command-line raster2pgsql.

isoneo commented 5 years ago

I tried out the dev version and it is working. I will give raster2pgsql a try as well. Thanks