|
Given [Table] with columns [Longitude], [Latitude] in the format you specify, this query will return decimal degrees in [DDx] and [DDy]. The key thing is that the format is a hybrid: a number expressed as a string, re-expressed as a "number" (a fake one). It turns out to be better to parse it as a string from the start. This avoids floating-point rounding errors, so that you wind up with the same "number" you started with. The query handles either "." or "," as decimal separator. SELECT [Longitude], [sgnX] * ([dX] + [mX] / 60 + [sX] / 3600) AS [DDx], [Latitude], [sgnY] * ([dY] + [mY] / 60 + [sY] / 3600) AS [DDy] FROM (SELECT [Longitude], [sgnX], CAST(Left([dmsX], [dotX] - 1) AS DOUBLE) AS [dX], CAST(Mid([dmsX], [dotX] + 1, 2) AS DOUBLE) AS [mX], CAST(Right([dmsX], Len([dmsX]) - [dotX] - 2) AS DOUBLE) / 10000 AS [sX], [Latitude], [sgnY], CAST(Left([dmsY], [dotY] - 1) AS DOUBLE) AS [dY], CAST(Mid([dmsY], [dotY] + 1, 2) AS DOUBLE) AS [mY], CAST(Right([dmsY], Len([dmsY]) - [dotY] - 2) AS DOUBLE) / 10000 AS [sY] FROM (SELECT [Longitude], [sgnX], [dmsX], MAX(InStr([dmsX], "."), InStr([dmsX], ",")) AS [dotX], [Latitude], [sgnY], [dmsY], MAX(InStr([dmsY], "."), InStr([dmsY], ",")) AS [dotY] FROM (SELECT [Longitude], SGN([Longitude]) AS [sgnX], CAST(ABS([Longitude]) AS TEXT) AS [dmsX], [Latitude], SGN([Latitude]) AS [sgnY], CAST(ABS([Latitude]) AS TEXT) AS [dmsY] FROM [Table] ) ) ); Attachments:
 DMS (as number) to DD.txt
|