[GIS] Different in distance measurements in MapBasic/MapInfo

mapbasicmapinfo

I am trying to make a custom ToolButton but I am having some problems getting correct measurements.

I have drawn a line (using the normal line tool) and set its length to 1000m. (Double-clicking it and measuring it with the ruler tool both show it to be exactly 1000.00m)

However when I use my tool and drag from one end of the line to the other it gives a distance of 999.8892m. I'm guessing it's some kind of projection issue but I'm using the same settings throughout the system… Where am I going wrong?

Include "mapbasic.def"
Include "icons.def"

Declare Sub Main
Declare Sub LineTool
Declare Sub ExitProg

Sub Main
  Alter ButtonPad "Drawing"
    Add 
      Separator
      ToolButton
        Icon MI_ICON_ARROW_19
        HelpMsg "Click on map to draw a line"
        Cursor MI_CURSOR_CROSSHAIR
        DrawMode DM_CUSTOM_LINE
        Calling LineTool
    Show

  Alter Menu "Tools" Add
    "Close Line Tool" Calling ExitProg
End Sub

Sub ExitProg
  End Program
End Sub

Sub LineTool
  Set Distance Units "m"
  Set Coordsys Earth

  Dim x, y, x2, y2 as float

  x = CommandInfo(CMD_INFO_X)
  y = CommandInfo(CMD_INFO_Y)
  x2 = CommandInfo(CMD_INFO_X2)
  y2 = CommandInfo(CMD_INFO_Y2)
  print x & ", " & y & ", " & x2 & ", " & y2 

  If x <> x2 and y <> y2 Then
    print Distance(x, y, x2, y2, "cm")
  Else
    print "That wasn't a line."
  End if
End Sub

Best Answer

MapInfo has two Distance functions. CartesianDistance and SpericalDistance (and Distance which would be the same as SpericalDistance) Try to use CartesianDistance() in stead of Distance()

Related Question