MapInfo Pro

Expand all | Collapse all

Longitudes and Latitudes

  • 1.  Longitudes and Latitudes

    Posted 19 days ago
    Hi All,

    I have a points file and I would like to add Longitude and Latitude for each point. I realise I can use the coordinate extractor to do this. However....

    I'm doing a number of different processing steps to create the data I want. I'm trying to write a MI workspace so that my processing is repeatable. I'm using the MapBasic window to capture the code and copy it into the workspace file I'm building.

    If I use the coordinate extractor tool to populate the fields the code does NOT appear in the MapBasic window. Therefore, I cannot copy and paste it into my workspace file.

    So, my question is...is there a way of adding fields for X and Y coords (and populating them) that will appear in the MapBasic window; so i can copy the code into my workspace.

    Can I use the update column process? I had a look but couldn't find an option that would do what I want.

    If this is the subject of another thread please point me in the right direction.

    regards,
    Neil

    ------------------------------
    Neil Adamson
    GIS Officer
    Mitchell Shire Council
    Broadford
    ------------------------------


  • 2.  RE: Longitudes and Latitudes

    Posted 19 days ago
    Hi Neil,

    Yes, you can use the Update Column.  First you may need to issue the following statement:

    Set CoordSys Table PointsTab

    This will ensure you are dealing with the correct coordinate system.  Then, within the Value field of the Update Column dialogue, use the following:

    If extracting X coordinates: CentroidX(obj)
    If extracting Y coordinates: CentroidY(obj)

    This will generate statements similar to the following:

    Update PointsTab Set XCoord = CentroidX(obj) DropIndex Auto
    Update PointsTab Set YCoord = CentroidY(obj) DropIndex Auto

    (where "PointsTab" is the table you are updating, and "XCoord" and "YCoord" are the fields in your table).

    This Update could be combined into a single statement in your workspace if you like:

    Update PointsTab Set XCoord = CentroidX(obj), YCoord = CentroidY(obj)

    ------------------------------
    James Nolet
    Dooley Mitchell & Morrison Pty Ltd
    Mentone, VIC, Australia
    ------------------------------



  • 3.  RE: Longitudes and Latitudes

    Posted 15 days ago
    Hi James and Peter,

    Thanks for your responses.  It worked well.

    I had tried to use the CentroidY(obj) and CentroidY(obj) manually in Mapinfo but the fields didn't populate - this is why I posed the question to begin with. However, when I put the code into my .wor file and ran it the fields populated correctly.

    I have another question but i'll try to figure it out for myself before I post it on here.

    Regards,
    Neil

    ------------------------------
    Neil Adamson
    GIS Officer
    Mitchell Shire Council
    Broadford
    ------------------------------



  • 4.  RE: Longitudes and Latitudes

    Posted 19 days ago

    Hi Neil

    I like your thinking: use MapInfo Pro to create the MapBasic code for you. That's probably the way many of us started when we wanted to learn MapBasic.

    Adding columns can be done using the Table Structure that you can access via the context menu on the table in the Table List or from the Table dropdown in the Maintenance group on the TABLE tab.

    This is the MapBasic code you are looking for:

    Alter Table MyTable (Add Latitude Float, Longitude Float)
    Set CoordSys Earth Projection 1, 104
    Update MyTable Set Latitude = CentroidY(obj), Longitude = CentroidX(obj)


    Note that the first statement will fail if the columns already exist.

    PS: If you are doing this with MapInfo Pro v2019, you can use the new SQL Window and save it to a MapBasic script, a new file format we just added.



    ------------------------------
    Peter Horsbøll Møller
    Distinguished Engineer
    Pitney Bowes Software & Data
    ------------------------------