MapInfo Pro Developers User Group

 View Only
  • 1.  CENTROIDX, CENTROIDY not returning sufficient precision

    Posted 01-26-2022 19:39
    Hello,
    I have an app that selects a polygon, gets the centroid and pastes a custom label and point at that same coordinate on a different layer/table.

    Code:

    frmMI64._application.RunMapBasicCommand("select obj from bpoly where bpoly.lotplan = " & """" & lp & """" & "into xxx", False, False)
    Dim nn As Integer = frmMI64._application.EvalMapBasicCommand("tableinfo(xxx ,8)", False)
    If nn <> 1 Then
            frmErrors.tbErrors.Text += "*Error - LotPlan - " & lp & " - could not be located in BPoly" & vbCrLf
    End If
    frmMI64._application.RunMapBasicCommand("fetch first from xxx", False, False)

    '??? why is this not returning enough precision?
    Dim ee As String = frmMI64._application.EvalMapBasicCommand("centroidx(xxx.obj)", False)
    Dim ss As String = frmMI64._application.EvalMapBasicCommand("centroidy(xxx.obj)", False)

    The trouble  I am having is  the returned values are only to 3 or four deep decimals of degrees, and so the points are in the vicinity, but not right.
    I thought this might be a string conversion issue so I tried other data types to no avail.

    Thanks for any assistance
    Paul

    ------------------------------
    Paul Thomas
    Cook Shire Council
    Cooktown QLD
    ------------------------------


  • 2.  RE: CENTROIDX, CENTROIDY not returning sufficient precision

    Employee
    Posted 01-27-2022 01:58
    Edited by Peter Møller 01-27-2022 02:01
    Hi Paul

    It is a formatting issue.

    Try using the Format$() function to return 5-6 decimals: Format$(CentroidX(xxx.obj), "#.######")

    Dim ee As String = frmMI64._application.EvalMapBasicCommand("Format$(centroidx(xxx.obj), "#.######")", False)
    Dim ss As String = frmMI64._application.EvalMapBasicCommand("Format$(centroidy(xxx.obj), "#.######")", False)

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------