Pages

Friday 21 February 2014

Degrees Minutes and Decimal Seconds (MapInfo Mapbasic SQL Query)

This is just a quick post to show you how to add use MapBasic functions inside an SQL query in MapInfo to return Latitude and Longitude in Degrees Minutes and Decimal Seconds (DMS).

Just copy the code below into your MapBasic window and modify the sections highlighted to create a query table with columns displaying DMS. Feel free to add as many columns separating with a comma (,).


SELECT
      Col1,
      Col2,
      Fix(CentroidY(obj)) & "°" &
      Fix((Abs(CentroidY(obj)) - Abs(Fix(CentroidY(obj))))*60) & "'" &
      Round(((((Abs(CentroidY(obj)) - Abs(Fix(CentroidY(obj))))*60) - Fix((Abs(CentroidY(obj)) - Abs(Fix(CentroidY(obj))))*60)) * 60),0.01) & Chr$(34) "Latitude_DMS",      
      Fix(CentroidX(obj)) & "°" &
      Fix((CentroidX(obj) - Fix(CentroidX(obj)))*60) & "'" &
      Round(((((CentroidX(obj) - Fix(CentroidX(obj)))*60) - Fix((CentroidX(obj) - Fix(CentroidX(obj)))*60))*60),0.01) & Chr$(34) "Longitude_DMS"
FROM Table_Name
INTO
Result_Table_Name

BROWSE
* FROM Result_Table_Name

COL1COL2Latitude_DMSLongitude_DMS
Value 11-26°27'52.4"149°0'15.54"
Value 22-26°28'3.66"148°59'47.76"
Value 33-26°28'2.72"148°59'51.7"
Value 44-26°28'10.89"148°59'47.51"
Value 55 -26°30'29.1"148°58'55.66"

1 comment:

  1. Very nice, James.
    I'm sure I would have missed some brackets in my first shot at this ;-)

    ReplyDelete