I need to convert to a specific format some gps coordinates which are the output of the exif information of a picture.
This is the typical output:
exif:GPSLatitude: 10/1, 10/1, 10/1 exif:GPSLatitudeRef: N exif:GPSLongitude: 10/1, 10/1, 10/1 exif:GPSLongitudeRef: E
and this is the string I need to obtain:
10 10 10N 10 10 10E
I have been able to do so with the following script:
cat $somefile | sed "s/ /$nul/g" | sed "s/exif:GPSLatitudeRef: /$nul/g" | sed "s/exif:GPSLongitude:/$nul/g" | sed "s/exif:GPSLongitudeRef: /$nul/g" | sed "s/exif:GPSLatitude: /$nul/g" | sed "s/\/1/$nul/g" | sed "s/,/$nul/g" | tr -d '\n'
However I realised that some pictures have a slightly different output like this:
exif:GPSLatitude: 10/1, 10/1, 1099/100 exif:GPSLatitudeRef: N exif:GPSLongitude: 10/1, 10/1, 1088/100 exif:GPSLongitudeRef: E
I understood that the
/100 (perhaps a
/1000 as well) are denominators of the number before.
Given the following considerations:
- I don't need a huge accuracy, therefore I can afford to loose the last two decimals of the last number (ie:
- I would like to have that accuracy;
- I am not totally sure that also the first two numbers of the coordinates (degrees and minutes, ie:
10/1 10/1) can have decimals. In this case, the accuracy of the coordinates would be totally messed up pointing to a different place in the world.
How can I modify that script (and maybe make it a bit more elegant) to make the calculations and actually substitute a fraction by a number with a point?