0

I have a series of images (.tiff) that are only georeference at the true centroid of the picture. I have calculated the missing coordinates (top right, top left, bottom right and bottom left) in the X and Y plain, and now I will like to write those coordinates in each image.

In order to do that, I was told that the exifr package in R has a function call exiftool_call that could be helpful to complete that task. I have tried different things, but they don't seem to be working, so I was wondering if anyone knows how to accomplish this task using exiftool_call

Here is what I have tried so far:

coordinates.data<-read.csv("...",header=TRUE)

list.pics <- list.files(path ="...",pattern = "*.tif",full.names = TRUE)

exiftool_call(args = coordinates.data, fnames = list.pics)  

exiftool_call(args = c(coordinates.data$TopLeftx,coordinates.data$TopLefty,coordinates.data$TopRightx,
                      coordinates.data$TopRighty,coordinates.data$BottomLeftx,coordinates.data$BottomLefty,
                      coordinates.data$BottomRightx,coordinates.data$BottomRighty),fnames = list.pics)

exiftool_call(args = c("coordinates.data$TopLeftx","coordinates.data$TopLefty","coordinates.data$TopRightx",
                       "coordinates.data$TopRighty","coordinates.data$BottomLeftx","coordinates.data$BottomLefty",
                       "coordinates.data$BottomRightx","coordinates.data$BottomRighty"),fnames = list.pics)

Output str(coordinates.data)

'data.frame':   5 obs. of  16 variables:
 $ X                          : int  1 2 3 4 5
 $ meta.df.FileName           : Factor w/ 5 levels "IMG_0000_1.tif",..: 1 2 3 4 5
 $ meta.df.FileInodeChangeDate: Factor w/ 3 levels "2018:07:11 14:16:48-05:00",..: 1 3 1 2 2
 $ meta.df.BandName           : Factor w/ 5 levels "Blue","Green",..: 1 2 4 3 5
 $ coorMetric.lon             : num  329878 329878 329878 329878 329878
 $ coorMetric.lat             : num  4057023 4057023 4057023 4057023 4057023
 $ ImageWidth                 : num  88.8 88.8 88.8 88.8 88.8
 $ ImageHeight                : num  66.7 66.7 66.7 66.7 66.7
 $ TopLeftx                   : num  329833 329833 329833 329833 329833
 $ TopLefty                   : num  4057056 4057056 4057056 4057056 4057056
 $ TopRightx                  : num  329922 329922 329922 329922 329922
 $ TopRighty                  : num  4057056 4057056 4057056 4057056 4057056
 $ BottomLeftx                : num  329833 329833 329833 329833 329833
 $ BottomLefty                : num  4056989 4056989 4056989 4056989 4056989
 $ BottomRightx               : num  329922 329922 329922 329922 329922
 $ BottomRighty        

   : num  4056989 4056989 4056989 4056989 4056989

One File Example

one.Image<-read_exif(path = "...")
one.Image

coordinate.one.Image<-read.csv("...", header = TRUE)
head(coordinate.one.Image)

exiftool_call(args = coordinate.one.Image, fnames = one.Image) 

Output str(coordinate.one.Image)

'data.frame':   1 obs. of  15 variables:
 $ meta.df.FileName           : Factor w/ 1 level "IMG_0001_1.tif": 1
 $ meta.df.FileInodeChangeDate: Factor w/ 1 level "2018:07:11 14:16:49-05:00": 1
 $ meta.df.BandName           : Factor w/ 1 level "Blue": 1
 $ coorMetric.lon             : num 329860
 $ coorMetric.lat             : num 4056981
 $ ImageWidth                 : num 88.8
 $ ImageHeight                : num 66.7
 $ TopLeftx                   : num 329815
 $ TopLefty                   : num 4057015
 $ TopRightx                  : num 329904
 $ TopRighty                  : num 4057015
 $ BottomLeftx                : num 329815
 $ BottomLefty                : num 4056948
 $ BottomRightx               : num 329904
 $ BottomRighty               : num 4056948
2
  • Where is it not going wrong? Are you seeing an error message? Do you understand how the exiftool command line works and which exif tags you want to set for your coordinates? Can you make a simpler example with one file and lets get that working before confusing the system with a load of files and metadata?
    – Spacedman
    Commented Sep 14, 2018 at 6:59
  • @Spacedman thank you for your response. As suggested by you I tried to do a more simpler example, only using one image and a set of coordinates for that particular image (please refer to code on original post). After running that, I get a series of Warning: Invalid tag name and Error: File not found. Do you happen to know what could be wrong?
    – Perro
    Commented Sep 16, 2018 at 1:08

1 Answer 1

0

You are trying to set tags that aren't valid on a file that doesn't exist.

The exiftool command line works like this:

exiftool -ISO=1600 photo.tif

to set the ISO tag to "1600" on "test.tif". The equivalent in the exifr package is:

exiftool_call("-ISO=3200", "test.tif")

You need to construct that first string of tag-value pairs from the things you want to tag the tif with. Tag names are not arbitrary - see the exiftool docs for valid ones: https://sno.phy.queensu.ca/~phil/exiftool/

So you are trying to call it with what looks like a list of name-value pairs:

> opts = list(ISO=3200)
> exiftool_call(opts, "../test.tif")
'perl' '/home/rowlings/R/x86_64-pc-linux-gnu-library/3.4/exifr/exiftool/exiftool.pl' 3200 '../test.tif'
Error: File not found - 3200
======== ../test.tif

which isn't valid.

If you want to georeference TIFF files, and the image is axis-aligned (ie forms a rectangle in your coordinate system) you want to create GeoTIFF files - this is a TIFF with the GeoTIFF metadata. You can possibly add this using exiftool, but its easier to read the TIFF into R using the raster package, setting the coordinates, projection, etc, and then writing it out.

4
  • Thank you so much for your answer @Spacedman; however, I have a question regarding the last paragraph of your message. After creating a GeoTIFF file, setting up the coordinates, projection, etc, can the missing coordinates be written using exifttool_call or is there other way?
    – Perro
    Commented Sep 16, 2018 at 16:45
  • If you want to use exiftool_call to do this you need to set the tags specified here: sno.phy.queensu.ca/~phil/exiftool/TagNames/GeoTiff.html - I don't quite understand " GeoTIFF tags are not writable individually, but they may be copied en mass via the block tags GeoTiffDirectory" but the docs for exiftool should explain it somewhere.
    – Spacedman
    Commented Sep 16, 2018 at 17:54
  • I see what you are saying. One more thing, so is there a way to set coordinates using the raster package? I get the impression that is what you are referring to on your original answer (I might be mistaken).
    – Perro
    Commented Sep 16, 2018 at 18:05
  • r=raster("foo.tif"); extent(r)=c(xmin, xmax, ymin, ymax)); writeRaster(r,"bar.tif") and now bar.tif is a geoTiff with spatial coordinates. Should also add a projection...
    – Spacedman
    Commented Sep 16, 2018 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.