I have spent sometime researching the forum and other places to resolve this but yielded nothing and I have decided to ask.
I have log files containing NMEA sentences. I have stored this sentences which are in hundreds of thousands in mysql database. I have stored the longitudes and latitudes as double datatype. I want to convert these longitudes and latitudes which are currently in this format:
to the decimal degree format which is:
I would appreciate if someone could help with this. Many thanks.
I came up with an sql select statement using the floor and round functions as follows:
insert into converted_long_lat (new_latitude, new_longitude) select round ((FLOOR(latitude / 100) + (latitude - 100 * FLOOR(latitude / 100)) / 60), 5), round((FLOOR(longitude / 100) + (longitude - 100 * FLOOR(longitude / 100)) / 60),5) FROM `rmc_raw_data`:
The result is ok but the latitude, even before applying the round function returns a rounded integer like 24 leaving out the decimal part. How can I preserve the decimal part?
Are your conversions above correct?
NMEA Sentences have lat and long given as degrees and decimal minutes so 6013.45368 is 60 deg 13.45368 mins, which I make 60+(13.45368/60)=60.22428 deg and 2445.28396 becomes 24.75473 deg.
From Degrees decimal-minutes (D m) to decimal-degrees (d)
I used the following to resolve it:
insert into converted_long_lat (new_latitude, new_longitude) SELECT ROUND((FLOOR(latitude / 100) + (latitude - 100 * FLOOR(latitude / 100)) / 60), 5), ROUND((FLOOR(longitude / 100) + (longitude - 100 * FLOOR(longitude / 100)) / 60),5) FROM rmc_raw_data`
The other issue of having the latitude returning an integer was due to it's column being set to an int type in the database. Hope someone else finds this solution useful.