PointToUSNG$() 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 USNG (United States National Grid) coordinate. Only point objects are supported. You can call this function from the MapBasic window in MapInfo Pro.

Syntax

PointToUSNG$(obj, datumid) 

obj is an object expression representing the point to be converted. It must evaluate to a point object.

datumid is a numeric expression representing the datum id. It must evaluate to one of the following values.

	DATUMID_NAD27  (62)
	DATUMID_NAD83  (74)
	DATUMID_WGS84 (104)
Note: DATUMID_* are defines in MapBasic.def. WGS84 and NAD83 are treated as equivalent.

Description

MapInfo Pro automatically converts the input point from the current MapBasic coordinate system to a Long/Lat (WGS84 and NAD27) datum before performing the conversion to an USNG 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 and NAD27) or to the coordinate system of the source data table, so that no unnecessary intermediate conversions are performed.

Return Value

String

Example 1

The following example illustrates the use of USNGToPoint() and PointToUSNG$() functions.

dim obj1 as Object 
dim s_USNG As String 
dim obj2 as Object 

obj1 = CreatePoint(-74.669, 43.263)
s_USNG = PointToUSNG$(obj1)
obj2 = USNGToPoint(s_USNG)

Example 2

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

' When using the PointToUSNG$() or USNGToPoint() 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 USNGfile

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

Update USNGfile
	Set Col2 = PointToUSNG$(obj)

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

Update USNGfile
	Set Col3 = CentroidX(USNGToPoint(Col2))

Update USNGtestfile ' USNGfile
	Set Col4 = CentroidY(USNGToPoint(Col2))

 Table USNGfile
Close Table USNGfile

See Also:

USNGToPoint(string)