rspatial / raster

R raster package https://rspatial.github.io/raster/reference/raster-package.html
GNU General Public License v3.0
161 stars 52 forks source link

Upside down raster #95

Closed vlarmet closed 4 years ago

vlarmet commented 4 years ago

s5p_no2_20180701T161259_20180707T175356.zip

Hi,

When I import this raster (attached file) to R and plot it, the latitude are flipped. It's a NO2 raster from sentinel in WGS84. However, it is correctly displayed in QGIS.

no2_QGIS

library(raster)  
rs<-raster('s5p_no2_20180701T161259_20180707T175356.tif',band=1)  
plot(rs)  
projection(rs)

My session info :

R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C                   LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] raster_3.0-12 sp_1.4-0     

loaded via a namespace (and not attached):
[1] compiler_3.5.3   rgdal_1.4-8      parallel_3.5.3   tools_3.5.3      Rcpp_1.0.1       codetools_0.2-16
[7] grid_3.5.3       lattice_0.20-38 
rhijmans commented 4 years ago

Thank you for reporting this. The data are written from bottom to top instead of the other (more common) way. I deal with that for some "native" formats, and I assumed that rgdal would handle that for data read via GDAL. But, alas, it does not (it does give a warning).

library(rgdal)
f <- "9s5p_no2_20180701T161259_20180707T175356.tif"
a <- readGDAL(f)
# s5p_no2_20180701T161259_20180707T175356.tif has GDAL driver GTiff 
# and has 148 rows and 475 columns
# Warning message:
# In readGDAL(f) : Y axis resolution positive, examine data for flipping

I'll investigate fixing this; but will add a warning for now, suggesting to use flip in a work-around:

library(raster)
x <- brick(f)
x <- flip(x, "y")
rhijmans commented 4 years ago

The terra package (>= 0.7-4) reads these data correctly.