Happy #MapInfoMonday,
I have in
a previous post discussed the new option in MapInfo Pro v2021 to use Smart Text adornments in the map window. Today, we will take this capability to solve a request from an end-user that I received through
@Ian Drury from our partner Ultranyx.
The request sounded like this:
We have a client who has a question. They are asking if it is possible to change a view of digital lat/long to MGRS in smart text/adornments on the layout? The projection is WGS84. They are using MapInfo 2021.
MGRS refers to Military Grid Reference System, a standard used by NATO militaries to locate points on Earth. It consists of three base elements: a grid zone designator, a 100,000-meter square identifier, and finally a numerical location that can specify a location through a grid from 10-kilometers down to a 1-meter resolution.
In the previous article, I linked to at the top of this post, I mentioned that you can create a Smart Text that extracts and shows coordinates from the current map extent:
$mb{MapperInfo(CurContext(4), MAPPER_INFO_CENTERY)}
: X coordinate of the center of the map
$mb{MapperInfo(CurContext(4), MAPPER_INFO_CENTERY)}
: Y coordinate of the center of the map
This will return the coordinates of the map center as two separate values.
You can create this Smart Text adornment via
Smart Text Adornment command from the
Add to Map dropdown on the
Map tab.
It will present you with the Smart Text dialog where you can enter the expression for your Smart Text. I have combined the two expressions to be able to pull together the X and Y coordinate of the map window.
The expression you see in the dialog is this:
$mb{MapperInfo(CurContext(4), MAPPER_INFO_CENTERX) + " " + MapperInfo(CurContext(4), MAPPER_INFO_CENTERY)}
It extracts the two coordinates from the map center and concatenated them with a space in between.
The coordinates are extracted using your session projection. By default, I'm using a UTM-based coordinate system for Denmark and countries on a similar longitude (Zone 32). This is reflected in the coordinates, I see in my map window.
If I change my session coordinate system to Longitude/Latitude WGS84, the coordinates shown also change to this coordinate system.
If my end result was to show the coordinates, I would consider using another MapBasic function,
FormatNumber$()
, to format my numbers in respect to my regional settings:
$mb{FormatNumber$(MapperInfo(CurContext(4), MAPPER_INFO_CENTERX)) + " " + FormatNumber$(MapperInfo(CurContext(4), MAPPER_INFO_CENTERY))}
In this specific case, we do not care too much about what coordinate system is being used as we want to convert the values into an MGRS string representing the position.
MapBasic has a function that can extract an MGRS string from a point. This means we will have to create a point from the center coordinates and then extract the MGRS string from this point. Luckily we can build a single expression doing all this.
This is the expression used:
$mb{PointToMGRS$(CreatePoint(MapperInfo(CurContext(4), MAPPER_INFO_CENTERX), MapperInfo(CurContext(4), MAPPER_INFO_CENTERY)))}
The resulting string looks like this on the map.
As you can see, the Smart Text adornments for the map window, allow you to extract and convert values from the map in various ways.
I showed how to do this by inserting the MGRS string into the map window. You can also do the same via a Smart Text in the layout window.
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
------------------------------