Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3614
  • Last Modified:

How to Convert DMS (sexagesimal) to Decimal Co-ordinates

I'm trying to get geo-locations (latitudes and longitudes) of photos into a database in a decimal format from EXIF gps data. However, the EXIF fields 'gps latitude' and 'gps longitude' are in a DMS (Degrees, minutes seconds) format. The value of the EXIF field 'gps latitude ref' is either 'N' (north) if the point is north of the equator, or 'S' if it is south of the equator, and 'gps longitude ref' is either 'W' if the point is to the west of the meridian line at Greenwich, or 'E' if it is to the east. The Coldfusion dump of the data looks (for example) like this: 52"15'57.600002 N 3"34'31.799927 W, as in:

<cfimage action="read" source="IMG_6384.jpg" name="myImage" />    
<cfset latitude = ImageGetEXIFTag(myImage,"gps latitude") />
<cfset longitude = ImageGetEXIFTag(myImage,"gps longitude") />
<cfset latref = ImageGetEXIFTag(myImage,"gps latitude ref") />
<cfset lonref = ImageGetEXIFTag(myImage,"gps longitude ref") />

<cfoutput>#latitude# #latref#</cfoutput><br>
<cfoutput>#longitude# #lonref#</cfoutput>

Can anyone come up with a way of converting the DMS values to a decimal number? I think I'm far from being the only person who would find a solution to this useful. I've attached an image file with the required EXIF data.
IMG-6384.jpg
0
gohols
Asked:
gohols
  • 2
  • 2
1 Solution
 
SidFishesCommented:
there's some JS here which could be adapted or cfscript-ed

http://www.codingforums.com/showthread.php?t=9709
0
 
azadisaryevCommented:
it looks like the image you attached does not have any EXIF data in it, so i am going on your description of what the EXIF data looks like:

[code blow uses your LATITUDE and LONGITUDE variables and assumes they are in DD"MM'SS.SSSS format]

<cfset degrees_lat = (listlast(latitude, chr(34)&chr(34))/60 + listgetat(latitude, 2, chr(34)&chr(39)))/60 + listfirst(latitude, chr(34)&chr(39))>

<cfset degrees_lng = (listlast(longitude, chr(34)&chr(34))/60 + listgetat(longitude, 2, chr(34)&chr(39)))/60 + listfirst(longitude, chr(34)&chr(39))>

hth
0
 
goholsAuthor Commented:
Just checked and it looks like EE has stripped out the EXIF and IPTC data. The file with these intact is at http://www.euroads.co.uk/image/IMG_6384.jpg

I tried the solution from azadisaryev and it's probably essentially ok, but it throws an error:

" The value 15'57.600002 cannot be converted to a number. "
0
 
azadisaryevCommented:
sorry, a typo in my code:
i have chr(34)&chr(34), but it should be chr(34)&chr(39)

so, correct code is:

<cfset degrees_lat = (listlast(latitude, chr(34)&chr(39))/60 + listgetat(latitude, 2, chr(34)&chr(39)))/60 + listfirst(latitude, chr(34)&chr(39))>

<cfset degrees_lng = (listlast(longitude, chr(34)&chr(39))/60 + listgetat(longitude, 2, chr(34)&chr(39)))/60 + listfirst(longitude, chr(34)&chr(39))>

fiy, in case you were wondering, chr(34) is an ascii code for " (double quote) and chr(39) for ' (single quote)

hth
0
 
goholsAuthor Commented:
Thanks, Azadisaryev - that works a treat.

Anyone using this should bear in mind that if the value of the IPTC tag 'gps latitude ref' is S, or if the value of 'gps longitude ref' is E, the decimal version of the co-ordinate will be a minus value so you will need to append the '-' character to the start of the number.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now