gohols
asked on
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,"g ps latitude") />
<cfset longitude = ImageGetEXIFTag(myImage,"g ps longitude") />
<cfset latref = ImageGetEXIFTag(myImage,"g ps latitude ref") />
<cfset lonref = ImageGetEXIFTag(myImage,"g ps 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
<cfimage action="read" source="IMG_6384.jpg" name="myImage" />
<cfset latitude = ImageGetEXIFTag(myImage,"g
<cfset longitude = ImageGetEXIFTag(myImage,"g
<cfset latref = ImageGetEXIFTag(myImage,"g
<cfset lonref = ImageGetEXIFTag(myImage,"g
<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
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
[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
ASKER
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. "
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. "
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
http://www.codingforums.com/showthread.php?t=9709