2015-01-09 37 views

回答

0

以下應該工作:

SELECT D + M/60 + S/3600; 

例如,在MySQL:

SELECT 36 + 19/60 + 11.46/3600; 

回報:36.319850

+0

因爲每條線都改變了,我會如何解決這個問題? – Joker327 2015-01-09 20:17:28

+0

沒有看到你的表格結構,很難回答。但是,它可能是這樣的:SELECT degrees + minutes/60 + seconds/3600 FROM tablename; – mti2935 2015-01-09 20:19:41

+0

你需要看到什麼才能使這更容易?每個DMS都位於表格的整個列上。大約有1000行。每行有它自己的像36°19'24.52「N然後下一行將是36°24'12.06」N – Joker327 2015-01-09 20:47:22

1

尼斯實用生活:使用SEC_TO_TIME反向問題的解決方案(度到DMS)建-in MySQL功能:

CREATE FUNCTION `geocoords`(lon double, lat double) RETURNS varchar(24) CHARSET cp1251 
    NO SQL 
    DETERMINISTIC 
begin  
    declare alon double; 
    declare alat double; 
    declare slon varchar(12); 
    declare slat varchar(12); 
    set alon = abs(lon); 
    set alat = abs(lat); 
    set slon = TIME_FORMAT(SEC_TO_TIME(alon*3600), '%H°%i''%s"'); 
    set slat = TIME_FORMAT(SEC_TO_TIME(alat*3600), '%H°%i''%s"'); 
    if lon>0 then 
    set slon = concat(slon, 'E'); 
    elseif lon<0 then 
    set slon = concat(slon, 'W'); 
    end if; 
    if lat>0 then 
    set slat = concat(slat, 'N'); 
    elseif lat<0 then 
    set slat = concat(slat, 'S'); 
    end if; 
    return concat(slat, ' ', slon); 
end 

SELECT geocoords(30.550157546997,50.344024658203)

50°20'38 「N 30°33'01」 E

0

我結束了這個建築,並與我所需要的完美無缺。你會注意到我給數字加了一個C,這是爲了標記它們,所以如果它已經被轉換了,它將不會繼續轉換。

UPDATE 
    MasterTable 
SET 
    MasterTable.Latitude_A = MasterTable.Latitude, 
    MasterTable.Longitude_A = MasterTable.Longitude 
WHERE 
    ProjectID = 'ProjectAlpha' 
    and Sequence = '0' 
    and MasterTable.Latitude NOT LIKE '%C%' 
    and MasterTable.Longitude NOT LIKE '%C%'; 

TRUNCATE TABLE gpsconvert; 
    INSERT into gpsconvert(gpsconvert.`Account Number`,gpsconvert.Latitude,gpsconvert.Longitude) 
SELECT 
     MasterTable.AccountNumber, 
     MasterTable.Latitude, 
     MasterTable.Longitude 
FROM 
    MasterTable 
WHERE 
    MasterTable.ProjectID = 'ProjectAlpha' 
    and MasterTable.Sequence = '0' 
    and MasterTable.Latitude NOT LIKE '%c%' 
    and MasterTable.Longitude NOT LIKE '%c%' 
    and MasterTable.Latitude <> '' 
    and MasterTable.Longitude <> ''; 

UPDATE 
    gpsconvert 
SET 
    gpsconvert.LatDegree = LEFT(gpsconvert.Latitude,2), 
    gpsconvert.LatMinutes = SUBSTRING(gpsconvert.Latitude,-7,2), 
    gpsconvert.LatSeconds = SUBSTRING(gpsconvert.latitude,-5,5), 
    gpsconvert.LatDecimal = gpsconvert.LatDegree + (gpsconvert.LatMinutes/60) + (gpsconvert.LatSeconds/3600), 
    gpsconvert.LongDegree = LEFT(gpsconvert.Longitude,2), 
    gpsconvert.LongMinutes = SUBSTRING(gpsconvert.Longitude,-7,2), 
    gpsconvert.LongSeconds = SUBSTRING(gpsconvert.Longitude,-5,5), 
    gpsconvert.LongDecimal = gpsconvert.LongDegree +  (gpsconvert.LongMinutes/60) + (gpsconvert.LongSeconds/3600); 

UPDATE 
    MasterTable 
INNER JOIN 
    gpsconvert on gpsconvert.`Account Number` = MasterTable.AccountNumber 
SET 
    MasterTable.Latitude = CONCAT(gpsconvert.LatDecimal,'c'), 
    MasterTable.Longitude = CONCAT(gpsconvert.LongDecimal,'c') 
WHERE 
    MasterTable.ProjectID = 'ProjectAlpha' 
    and MasterTable.Sequence = '0' 
    and MasterTable.AccountNumber = gpsconvert.`Account Number` 
相關問題