pe_geog_to_mgrs

Converts geographic coordinates into MGRS strings.

Usage syntax

int pe_geog_to_mgrs(PE_GEOGCS geogcs, int n, double coord[][2], int num_digits, int numeric_rounding, char *mgrs_str[]);
 

Parameters
geogcs A valid geographic coordinate system object
n Number of points in the coord array
coord Array of points
num_digits The precision of output MGRS string
numeric_rounding If TRUE, round the UTM coordinates to the precision value. If FALSE, truncate the UTM coordinates to the precision value.
mgrs_str A pointer to an array of MGRS strings
Description

The military grid reference system (MGRS) is a method of representing positions with a alphanumeric string. The MGRS string is based on UTM (universal transverse Mercator) coordinates. The num_digits parameter will determine the precision of the output string. A value of 5 represents a position to the nearest meter. A value of zero is the nearest 100 kilometers. The largest possible value is 8 which is 0.001 meters. The numeric_rounding parameter is particularly important when the num_digits value is small. Truncating the UTM coordinates will mean that MGRS string will be in the same square, for instance the 100 km square. Rounding the UTM coordinates might mean that the MGRS string uses the next 100 km square, compared to an MGRS string that is truncated or is more precise.

Returns

The number of points converted.

Examples

int i,n;
int ndigits, qround;
double coord[N_MAX][2];
char *mgrs_string[N_MAX];
PE_GEOGCS gcs;

n = 1;
ndigits = 5; /* nearest meter */
qround = 0; /* truncate */
gcs = pe_factory_geogcs(4326); /* WGS 1984 */

coord[0][PE_COORD_LAM] = -117.0;
coord[0][PE_COORD_PHI] = 34.0;

/* MGRS result is 11SNT0000062155 */
i = pe_geog_to_mgrs(gcs, n, coord, ndigits, qround, mgrs_string);

pe_geogcs_del(gcs);