PointToMGRS$() function - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Converts an object value representing a point into a string representing an MGRS (Military Grid Reference System) coordinate. Only point objects are supported. You can call this function from the MapBasic window in MapInfo Pro.

Syntax

PointToMGRS$( inputobject ) 

inputobject is an object expression representing a point.

Description

MapInfo Pro automatically converts the input point from the current MapBasic coordinate system to a Long/Lat (WGS84) datum before performing the conversion to an MGRS string. However, by default, the MapBasic coordinate system is Long/Lat (no datum); using this as an intermediate coordinate system can cause a significant loss of precision in the final output, since datumless conversions are much less accurate. As a rule, the MapBasic coordinate system should be set to either Long/Lat (WGS84) or to the coordinate system of the source data table, so that no unnecessary intermediate conversions are performed. See Example 2 below.

Return Value

String

Examples

The following examples illustrate the use of both the MGRSToPoint() and PointToMGRS$() functions.

Example 1:

dim obj1 as Object 
dim s_mgrs As String 
dim obj2 as Object 

obj1 = CreatePoint(-74.669, 43.263)
s_mgrs = PointToMGRS$(obj1)
obj2 = MGRSToPoint(s_mgrs)

Example 2:

Open Table "C:\Temp\MyTable.TAB" as MGRSfile

' When using the PointToMGRS$() or MGRSToPoint() functions,
' it is very important to make sure that the current MapBasic 
' coordsys matches the coordsys of the table where the
' point object is being stored.

'Set the MapBasic coordsys to that of the table used
Set CoordSys Table MGRSfile

'Update a Character column (e.g. COL2) with MGRS strings from
'a table of points

Update MGRSfile
	Set Col2 = PointToMGRS$(obj)

'Update two float columns (Col3 & Col4) with
'CentroidX & CentroidY information 
'from a character column (Col2) that contains MGRS strings.

Update MGRSfile
	Set Col3 = CentroidX(MGRSToPoint(Col2))

Update mgrstestfile ' MGRSfile
	Set Col4 = CentroidY(MGRSToPoint(Col2))

 Table MGRSfile
Close Table MGRSfile

See Also:

MGRSToPoint() function