Search code examples
rrasterterra

terra and raster package gives flip warning for reading the same raster


I have a raster in working directory:

When I read this using terra package, it reads fine

r1 <- terra::rast(my_rast)
r1 
class       : SpatRaster 
dimensions  : 6000, 6000, 8  (nrow, ncol, nlyr)
resolution  : 0.0008333333, 0.0008333333  (x, y)
extent      : 59.99958, 64.99958, 24.99958, 29.99958  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326) 
source      : n25e060.tif 
names       : n25e060_1, n25e060_2, n25e060_3, n25e060_4, n25e060_5, n25e060_6, ... 
  
      

But If I read the same raster using the raster package, I get the following warning:

r2 <- raster::raster(my_rast)
Warning message:
In .rasterFromGDAL(x, band = band, objecttype, ...) :
data seems flipped. Consider using: flip(x, direction='y')
  
class      : RasterLayer 
band       : 1  (of  8  bands)
dimensions : 6000, 6000, 3.6e+07  (nrow, ncol, ncell)
resolution : 0.0008333333, 0.0008333333  (x, y)
extent     : 59.99958, 64.99958, 25.00042, 30.00042  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : n25e060.tif 
names      : n25e060 
values     : 0, 255  (min, max)
  

Why is this happening?


Solution

  • That suggests that either {terra} can directly use "flipped" raster data, whereas that {raster} cannot or that {terra} does not notice that the data are flipped. I believe the former to be true, but, while this would be easy for you to verify, I do not have the file so I cannot be 100% sure.