MapInfo Pro Developers User Group

Expand all | Collapse all

SQL Server connection with MapInfo - Coordinates Update

  • 1.  SQL Server connection with MapInfo - Coordinates Update

    Posted 03-28-2019 00:49
    Hi everyone.

    Hope someone can help with this.

    We use MapInfo Pro v16 and we built a custom ribbon tool for our team to use. One of the buttons allows users to open a database table/layer and update it directly in MapInfo, by adding dots on a map ( as in clicking on a map window directly and getting the coords with CommandInfo statements).

    For some reason the coordinates values (we use GDA 94 for projection) get rounded to 4 decimals places, which forces the new dots to a different location than the chosen one. The database table has those columns as decimals (18,8), and MapInfo seems to read them the same way.
    Anyone knows why this might be happening?

    Many thanks
    Maria

    ------------------------------
    Maria Sousa
    Network GIS Analyst
    ------------------------------


  • 2.  RE: SQL Server connection with MapInfo - Coordinates Update

    Pitney Bowes
    Posted 03-28-2019 19:54
    Hi Maria,

    Great work creating the custom tool!

    There's several possible sources of the behaviour you describe, a few that come to mind are:
    • Variable used to store the coords after the click event
    • Projection of the MapBasic session (best practice is to explicitly set to GDA)
    • The process used to update the new row in the db table

    would be worth seeing if you can debug at each step to check what the coords are as they go through the process. You could insert some simple "Print" statements to output the values at each step and track where the extra coords are dropped. Hope this helps to isolate the source of the problem - please let us know how you go.

    Thanks, Ashley

    ------------------------------
    Ashley Crane
    Regional Director, Software Support
    Pitney Bowes
    ------------------------------



  • 3.  RE: SQL Server connection with MapInfo - Coordinates Update

    Pitney Bowes
    Posted 03-29-2019 08:32
    ​Maria,
    I think the key is how the information is returned from CommandInfo and making sure the value is formatted before it becomes a string. This means the MapBasic variable type must be float for this to work.

    Let me explain.
    Internally, the full precision that we have is stored in the geometry and nothing reduces it via MapBasic. If you were writing a MapBasic program, then you would store the value in a "float" again with no loss of precision. However, if you display the value like in a "browser" or in a Print statement, that code no longer knows it is dealing with a coordinate value. It is just like any float and the default formatting of that uses up to 4 decimals. For example, if the real value was 458.18293646553 you would see 458.1829. If this was a coordinate value, you would use a formatting function like Format$().  Note that in a browser when you edit a float value, the full precision is displayed.

    For example, I took a random selection in MapInfo Pro and did this in the MapBasic window.
    print centroidx(selection.obj)  and it printed  82.795  (only 3 decimals)
    But print format$(centroidx(selection.obj), "#####.######") returns 82.794998

    My suggestion is to try this directly with CommandInfo.  Format$( CommandInfo( CMD_INFO_X), "####.######")

    Let us know if this works.

    ------------------------------
    Eric Blasenheim
    Spectrum Spatial Technical Product Manager
    Troy, NY
    ------------------------------



  • 4.  RE: SQL Server connection with MapInfo - Coordinates Update

    Posted 03-31-2019 18:06
    Hi All.

    Seems like Eric's solution worked.
    Thank you both for the suggestion!

    Maria

    ------------------------------
    Maria Sousa
    Network GIS Analyst
    ------------------------------