Search code examples
rrasterterrasentinel1

Problems with R raster package handling of coordinates, resolution and extent of a raster read from a "tiff" file from Sentinel-1


I am trying to create a automating process in R to analyse a large number of tiff files from Sentinel-1. I read the raster in R using

r <-raster("s1a-iw-grd-vh-20230208t052407-20230208t052432-047140-05a7dd-002.tiff")

The file is read but R shows that it has no projection. Note that R raster thinks that the extent of the raster is the dimensions (rows,columns) and assigns values 1:nrow and 1.ncol as coordinates and also gives a wrong resolution.

class      : RasterLayer 
dimensions : 16668, 26588, 443168784  (nrow, ncol, ncell)
resolution : 1, 1  (x, y)
extent     : 0, 26588, 0, 16668  (xmin, xmax, ymin, ymax)
crs        : NA 
source     : s1a-iw-grd-vh-20230208t052407-20230208t052432-047140-05a7dd-002.tiff 
names      : s1a.iw.grd.vh.20230208t052407.20230208t052432.047140.05a7dd.002 
values     : 0, 25771  (min, max)

Plotting the raster using mapview(r) plots it south of Ghana and Togo in Africa yet it is supposed to be in the south of Sweden.

Here is the mapview image.enter image description here

Using ArcGIS placed the image in the correct geogrtaphical region which implies that R raster package is not able to read ceratin attributes of the "tiff" file.

Here is the ArcGIS plot. enter image description here

ArcGIS shows that the source file has spatial attributes as shown here enter image description here

How can I get R to read and map this "tiff" file properly. I would love solutions only in R. I have also tried the terra and stars packages without much luck

here is a link to the tiff file TIFF_FILE


Solution

  • terra v 1.7.10 can now handle files that are georeferenced with Ground Control Points (GCPs). This is currently the development version that you can install with install.packages('terra', repos='https://rspatial.r-universe.dev')

    With your file, I see

    library(terra)
    #terra 1.7.10
    
    x <- rast("s1a-iw-grd-vh-20230208t052407-20230208t052432-047140-05a7dd-002.tiff"
    x <- rast(f)
    #Warning message:
    #[rast] the data in this file are rotated. Use 'rectify' to fix that 
    r <- rectify(x)
                                              
    r
    #class       : SpatRaster 
    #dimensions  : 21480, 29751, 1  (nrow, ncol, nlyr)
    #resolution  : 0.0001656102, 8.934863e-05  (x, y)
    #extent      : 11.47043, 16.3975, 56.93446, 58.85367  (xmin, xmax, ymin, ymax)
    #coord. ref. : lon/lat WGS 84 
    #source      : spat_kxvbxy0YqI5GrWE_4932.tif 
    #name        : spat_IbFSRebuQNX93z9_4932_rect 
    #min value   :                           0.00 
    #max value   :                       21275.04 
    

    See

    plet(r)
    

    This is still somewhat experimental. And feedback appreciated.