Happy #MapInfoMonday!I got a question from @Charlen McCarthy. She wants to label points in a map with coordinates. Her challenge is that the table is saved using a Longitude/Latitude projection but she wants the coordinates in GDA2020.Here is a map where the points are labeled with the coordinates in Longitude/Latitude.
There are a couple of ways to do this. One depends on the Session Projection and the other requires you to extract the coordinates and store them in two columns. But first, let's revisit projections in MapInfo Pro as this is important for your understanding.
MapInfo Pro supports various coordinate systems, often referred to as projections. These are all described in the projection file, MapInfow.prj. You can add additional coordinates to this file if the one you want is missing. Feel free to let us know when you run into a missing coordinate system and we will add it in the next release.I'll not go into the details around coordinate systems as that's not needed here. There is a good article on the topic here: Confused by Coordinate Systems and the help system also comes with a lot of details around projections, datums, and coordinate systems.MapInfo Pro transforms between various projections on the fly. That's why you easily can combine tables with various projections in one map.Projections are handled at a number of levels in MapInfo Pro.Your mappable tables are saved using a projection. You can change this projection by saving a copy of your table and in this process define a different projection.Your map windows are configured to use a projection, typically defined by the table first added to the map. However, You can easily change your map's projection, either through Map Options or by clicking the projection name in the statusbar.
MapInfo Pro itself, often referred to as the session, is also working in a projection. You can change this through the Map Window Preferences under Projection.It's the latter that is being used when you use MapBasic functions to extract coordinates from objects. This also means that you need to change the session projection if you want to influence the projection of the coordinates.
In my example, I have a table stored in UTM Zone 32 ETRS89. I want to label the points in this table using Longitude/Latitude WGS89.I create a label expression to extract the coordinates from my points using the MapBasic functions CentroidX() and CentroidY(). I concatenate these with some text and show them on separate lines. I also format the coordinates to use a digit group separator and only have two decimals using the Format$() function. It the second parameter string that controls the number formatting: ",0.00". You can read more about the options in the MapBasic Reference Guide under Format$().
"X: "+Format$(CentroidX(obj), ",0.00")+Chr$(10)+"Y: "+Format$(CentroidY(obj), ",0.00")
In the Expression dialog, it looks like this:
The resulting map looks like this with labels in a bold red font.
Now the coordinates in the map above are shown in UMT Zone 32 ETRS89 because that's my session projection. It is the projection that is widely used in Denmark and there I have set up MapInfo Pro to use this by default.If I want to label my points using Longitude/Latitude WGS84, I will have to change my session projection. Let's try that.Click on the Pro tab to get to the Backstage. Now click on the Options tab. From here, you will have to click on Map Window to access the Map Preferences.
In the Map Preferences dialog, click on the Projection tab. From here you can control the default projection for new tables and for the MapInfo session.
Click on Session Projection... to open up the Choose Projection dialog where you can select the default projection for the MapInfo session. This will affect the current and future MapInfo sessions. Click OK to accept the selected projection, and OK to store the map preferences too.
Back in your map window, you may already see the coordinates change on the map. I will recommend that you turn auto labels off for the map and then turn auto labels back on again. This will clear the label cache which may hold labels created using the previous projection.Your resulting map should look like this
The benefit of using the method is that you don't have to store the coordinates in columns and make sure these are kept up-to-date. If you move a point, you will see the label change instantly.The downside is that the projection of the coordinates depends on the session projection. If colleagues of yours open the workspace, the coordinates will be shown using their session projection which may be different.
There is another way as I said at the beginning of this article. You can store the coordinates in two columns in your table.I'd recommend that you use the Coordinate Extractor tool to extract the coordinates. I recommend this as this gives you better control over the projection used when extracting the coordinates. You can also do it through the Update Column dialog but this will require that you again set the session projection as this affects the coordinates.From the Tools window, double-click on the Coordinate Extractor tool on the Registered tab. This tool is typically not set to autoload so you need to load it before you can use it.
When the Coordinate Extractor tool has been loaded, you can find it on the Running tab. You can now either right-click on the tool and choose Coordinate Extractor from the context menu or just double-click the tool to run it.
In the Coordinate Extractor dialog, you need to select the table and columns to update. You must also change the projection type to Use None-Native Projection which basically means it will not use the projection from the table. Then use the Select Projection button to select the projection you want.
If your table doesn't have the columns for the coordinates, you can click Create new columns to hold coordinates... to create two new columns. In the Create Coordinate Columns dialog, you can specify the names for these two columns.
Back in the Coordinate Extractor dialog, click OK to update the columns with the coordinates from the objects. Remember to save the changes to the table.Now you just need to modify the label expression to use your two columns instead of extracting the coordinates from the objects.
"X: "+Format$(Longitude, ",0.00")+Chr$(10)+"Y: "+Format$(Latitude, ",0.00")
and the resulting map should look very similar to the result you got by changing the session projection earlier. You can get more decimals by adding more 0's after the . in the expression. This will give you four decimals: ",0.0000". Remember to change this for both of your coordinates.