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

jjunju
  • 505
  • 1
  • 5
  • 18
  • Have you tried this? https://gis.stackexchange.com/questions/111226/how-to-assign-crs-to-rasterlayer-in-r – smartse Feb 13 '23 at 11:07
  • Yes I have already tried defining a projection but it doesnt work! – jjunju Feb 13 '23 at 11:46
  • There is nothing we can do without the file (or files if there are additional files associated with the tiff file, such as xml files). Please share it via google drive or something like that. – Robert Hijmans Feb 13 '23 at 14:45
  • here is a link to the file https://drive.google.com/file/d/1YL4rth-iXG0DkMOhRlUbVU9F1UuiDXxP/view – jjunju Feb 13 '23 at 15:25
  • Can you change the permissions such that anyone with the link can see the file? Right now it is not accessible – Robert Hijmans Feb 13 '23 at 16:15
  • Hei, I have updated the permissions. So sorry – jjunju Feb 13 '23 at 23:21
  • 2
    The reason why this fails is that the file is georeferenced with GCPs. I will try to add support for this to terra and will report back. – Robert Hijmans Feb 14 '23 at 03:06

1 Answers1

1

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.

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • I ran into installation problems on windows and Mac. Here is my macOS experience. configure: PROJ: 9.1.1 checking PROJ: checking whether PROJ and sqlite3 are available for linking:... no configure: error: libproj or sqlite3 not found in standard or given locations. ERROR: configuration failed for package ‘terra’ * removing ‘/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/terra’ * restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/terra’ Warning in install.packages : installation of package ‘terra’ had non-zero exit status – jjunju Feb 27 '23 at 15:08
  • I have checked and both projects and sqlite3 are installed. I am not a guru on installing from source – jjunju Feb 27 '23 at 15:10
  • With this `install.packages('terra', repos='https://rspatial.r-universe.dev')` you are not installing from source on Windows and most OSX if you have current R etc. – Robert Hijmans Feb 27 '23 at 15:58
  • Finally it worked. I installed the latest version of R 4.2.2 and reinstalled the packages. The rectify function was a bit slow but it worked. – jjunju Mar 01 '23 at 10:42