Gps Degrees to Decimal Help

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
rootx
Posts: 7
Joined: 2017-09-13T12:53:42-07:00
Authentication code: 1151

Gps Degrees to Decimal Help

Post by rootx »

Hi, there is a way to have in identify -format the lat and long in decimal format?? THX
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gps Degrees to Decimal Help

Post by fmw42 »

What is your exact command line? What is your IM version and platform? Can you provide an example image? Are the lat/lon coming from the EXIF data? You can always get the data and convert using "%[fx:xxxxx]" calculations.
rootx
Posts: 7
Joined: 2017-09-13T12:53:42-07:00
Authentication code: 1151

Re: Gps Degrees to Decimal Help

Post by rootx »

Thx, windows 10 64bit last version ImageMagik
identify -format "%[EXIF:GPSLatitude],% [EXIF:GPSLongitude]\n"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gps Degrees to Decimal Help

Post by fmw42 »

rootx wrote: 2017-09-13T14:24:07-07:00 Thx, windows 10 64bit last version ImageMagik
identify -format "%[EXIF:GPSLatitude],% [EXIF:GPSLongitude]\n"
That is not a valid command. You need an image. Can you post an example image so I can test and show how to convert. You cannot change the format of the lat/lon in identify, since it just reads what is in the EXIF data. It would need a special -define to be created to tell it to use fractional degrees. But you can convert afterwards with existing code commands.

What is your exact IM version.
rootx
Posts: 7
Joined: 2017-09-13T12:53:42-07:00
Authentication code: 1151

Re: Gps Degrees to Decimal Help

Post by rootx »

Ok Thx, I explain to you step by step
ImageMagick 7.0.6 Q16 (64-bit)
Windows 10 64
cmd shell

Well my question is.. I need to calculate decimal lat lng "d + m/60 + s/3600" but the IM output is in Degrees Format, like this

Code: Select all

identify -format "%[EXIF:GPSLatitude],%[EXIF:GPSLongitude]\n" *.jpg > log.txt

38/1, 42/1, 2485/100,9/1, 8/1, 1115/100
45/1, 5946/100, 0/1,8/1, 5697/100, 0/1
35/1, 42/1, 5079/100,139/1, 47/1, 4815/100
First, why on the second line the order is wrong??? Deg Sec MIn and not Deg Min Sec?? Anyway can you sho me if exist a way to have directly in the output the lat,lng in Decimal format? Thx again

PS: use this links 4 the images with the exif included

https://ibb.co/cMzDDk
https://ibb.co/eZTUm5
https://ibb.co/iMdvR5

ImageImageImage
Last edited by rootx on 2017-09-14T09:18:46-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Gps Degrees to Decimal Help

Post by snibgo »

I have no devices that know their latitude and longitude, so I've never researched this, but you might find that:

- some devices record in degrees and minutes (including fractions) only
- some record in degrees, minutes and seconds (including fractions).

Thus, "45/1, 5946/100, 0/1" is 45 degrees and 59.46 minutes, and zero seconds.

A minute is 1/60 of a degree. A second is 1/60 of a minute. So you need to parse each lat or long into the six numbers, and do the arithmetic.

A lat or long is: A/B, C/D, E/F

In degrees this is: A/B + (C/D)/60 + (E/F)/3600
snibgo's IM pages: im.snibgo.com
rootx
Posts: 7
Joined: 2017-09-13T12:53:42-07:00
Authentication code: 1151

Re: Gps Degrees to Decimal Help

Post by rootx »

Thx, but, the question is, IM is able to return the decimal format directly or not?
IMG OUTPUT
38/1, 42/1, 2485/100,9/1, 8/1, 1115/100
45/1, 5946/100, 0/1,8/1, 5697/100, 0/1
35/1, 42/1, 5079/100,139/1, 47/1, 4815/100

Formula
DD = d + m/60 + s/3600

Result
38.7069027777778,-9.13643055555555
45.991,8.9495
35.7141083333333,139.796708333333

-9.13643055555555 this is because if the GPSLatitudeRef or GPSLongitudeRef is "W" OR "S".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Gps Degrees to Decimal Help

Post by snibgo »

As I say, I have no devices that know their latitude and longitude, so I can't test it, but I assume IM just spits out the EXIF data, with no arithmetic.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gps Degrees to Decimal Help

Post by fmw42 »

Here is a Unix syntax shell script to compute the latitude. You can do the same for longitude

Code: Select all

lat=`identify -format "lat=%[EXIF:GPSLatitude]\n" IMG_0448.jpg`
echo "lat=$lat"
lat=lat=38/1, 42/1, 2485/100
lat_deg1=`echo $lat | cut -d, -f1 | cut -d/ -f1`
lat_deg2=`echo $lat | cut -d, -f1 | cut -d/ -f2`
lat_min1=`echo $lat | cut -d, -f2 | cut -d/ -f1`
lat_min2=`echo $lat | cut -d, -f2 | cut -d/ -f2`
lat_sec1=`echo $lat | cut -d, -f3 | cut -d/ -f1`
lat_sec2=`echo $lat | cut -d, -f3 | cut -d/ -f2`
latitude=`convert xc: -format "%[fx:($lat_deg1/$lat_deg2) + ($lat_min1/$lat_min2)/60 + ($lat_sec1/$lat_sec2)/3600]" info:`
echo "latitude=$latitude"
latitude=38.7069
This code could be used to create your own custom identify_gps as a script. I have several such custom identify scripts that I use to report selected information.
ozbigben
Posts: 27
Joined: 2012-03-25T02:15:27-07:00
Authentication code: 8675308

Re: Gps Degrees to Decimal Help

Post by ozbigben »

Are you doing anything with the images in IM or just reading the metadata? If the latter, then you might be better off with Exiftool. You'll still get DMS but the format will be consistent regardless of device and you can customise list format easily. https://sno.phy.queensu.ca/~phil/exifto ... ml#Inverse
rootx
Posts: 7
Joined: 2017-09-13T12:53:42-07:00
Authentication code: 1151

Re: Gps Degrees to Decimal Help

Post by rootx »

Thx, I know Exiftool ..... Problem is when Exiftool try to read a folder in another languages with special char FAIL... you can try to use in your cmd filename=utf8 etc... but belive me It doesn't works!! For that reason I come here!
I know a way with a script to do it, but why IM is not able to do it directly in a line cmd?? And the result look very strange 4 me...
IMG OUTPUT

Code: Select all

38/1, 42/1, 2485/100,9/1, 8/1, 1115/100
45/1, 5946/100, 0/1,8/1, 5697/100, 0/1<--------------------------- ???? The right order is  DMS(d + m/60 + s/3600) and not DSM
35/1, 42/1, 5079/100,139/1, 47/1, 4815/100
If IM change the position order evrery script need another if condition to regulate it, Exiftool 4example respect the output order.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Gps Degrees to Decimal Help

Post by el_supremo »

45/1, 5946/100, 0/1,8/1, 5697/100, 0/1<--------------------------- ???? The right order is DMS(d + m/60 + s/3600) and not DSM
Why do you say that this is in DSM order? It isn't.
IM simply prints the text that is in the EXIF GPS tag:
45/1, 5946/100, 0/1,8/1, 5697/100, 0/1n
5946/100 minutes is 59.46 which is 59 minutes 27.6 seconds.

From the exif.org spec: http://www.exif.org/Exif2-2.PDF
GPSLatitude
Indicates the latitude. The latitude is expressed as three RATIONAL values giving the degrees, minutes, and seconds, respectively. If latitude is expressed as degrees, minutes and seconds, a typical format would be dd/1,mm/1,ss/1. When degrees and minutes are used and, for example, fractions of minutes are given up to two decimal places, the format would be dd/1,mmmm/100,0/1.
In this case the EXIF tag, as printed by IM, is in "dd/1,mmmm/100,0/1" format. It is then up to you to convert it to whatever format you require.

BTW. Neither Exiftool nor IM find any GPS info in the third image.

Oh great. After all this I find that the OP has crossposted that the problem is solved.
https://www.imagemagick.org/discourse-s ... =3&t=32703

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
Post Reply