parseUTM
Parses Universal Transverse Mercator (UTM) coordinate strings into latitude/longitude values.
Parses Universal Transverse Mercator (UTM) coordinate strings and converts them to latitude/longitude decimal degrees with detailed validation.
Usage
import { parseUTM } from '@accelint/geo';
// Parse UTM coordinate
const [coords, errors] = parseUTM(null, '18 N 585628 4511322');
// coords: ['40.74839601188732', 'N', '/', '73.98570490632135', 'W']
// errors: []Reference
function parseUTM(
_format: any,
input: string
): [tokens: string[], errors: string[]]Parameters
| Parameter | Type | Description |
|---|---|---|
_format | any | Unused format parameter (kept for interface compatibility) |
input | string | UTM coordinate string to parse (e.g., '18 N 585628 4511322') |
Returns
Returns a tuple containing:
tokens: Array with latitude/longitude values and bearing indicatorserrors: Array of validation error messages (empty if valid)
UTM Format
UTM coordinates consist of:
- Zone Number (1-60): UTM longitudinal zone
- Hemisphere (N or S): North or South hemisphere
- Easting (0-999999): Meters east from zone's central meridian
- Northing (0-9999999): Meters north from equator (N) or south from 10,000km (S)
Expected format: ZZ N|S EEEEE NNNNN
Example: 18 N 585628 4511322
Validation Rules
Validates that:
- Zone number is between 1 and 60
- Hemisphere letter is N (North) or S (South)
- Easting is a valid non-negative number
- Northing is a valid non-negative number
Examples
Example: Valid UTM coordinate (New York City)
import { parseUTM } from '@accelint/geo';
const [coords, errors] = parseUTM(null, '18 N 585628 4511322');
// coords: ['40.74839601188732', 'N', '/', '73.98570490632135', 'W']
// errors: []Example: London coordinates
import { parseUTM } from '@accelint/geo';
const [coords, errors] = parseUTM(null, '30 N 585358 5669660');
// coords: ['51.17199279600467', 'N', '/', '1.7790080009934', 'W']
// errors: []Example: Southern hemisphere
import { parseUTM } from '@accelint/geo';
const [coords, errors] = parseUTM(null, '56 S 334786 6252080');
// coords: ['33.8688', 'S', '/', '151.2093', 'E']
// errors: []Example: Without spaces (automatic normalization)
import { parseUTM } from '@accelint/geo';
const [coords, errors] = parseUTM(null, '18N 585628 4511322');
// Automatically normalized to '18 N 585628 4511322'
// coords: ['40.74839601188732', 'N', '/', '73.98570490632135', 'W']
// errors: []Example: Invalid zone number
import { parseUTM } from '@accelint/geo';
const [coords, errors] = parseUTM(null, '65 N 585628 4511322');
// coords: []
// errors: ['[ERROR] Invalid Zone number (65) found; expected format ZZ N|S DDD DDD.']Example: Zone too low
import { parseUTM } from '@accelint/geo';
const [coords, errors] = parseUTM(null, '-1 N 585628 4511322');
// coords: []
// errors: ['[ERROR] Invalid Zone number (-1) found; expected format ZZ N|S DDD DDD.']Example: Invalid hemisphere
import { parseUTM } from '@accelint/geo';
const [coords, errors] = parseUTM(null, '18 X 585628 4511322');
// coords: []
// errors: ['[ERROR] Invalid Latitude band letter (X) found; expected format ZZ N|S DDD DDD.']Example: Missing easting
import { parseUTM } from '@accelint/geo';
const [coords, errors] = parseUTM(null, '18 N');
// coords: []
// errors: ['[ERROR] Invalid Easting number () found; expected format ZZ N|S DDD DDD.']Example: Missing northing
import { parseUTM } from '@accelint/geo';
const [coords, errors] = parseUTM(null, '18 N 585628');
// coords: []
// errors: ['[ERROR] Invalid Northing number () found; expected format ZZ N|S DDD DDD.']Example: Empty input
import { parseUTM } from '@accelint/geo';
const [coords, errors] = parseUTM(null, '');
// coords: []
// errors: ['[ERROR] Invalid Zone number () found; expected format ZZ N|S DDD DDD.']Good to know: UTM divides the Earth into 60 longitudinal zones, each 6° wide. Zone 1 starts at 180° West. The parser automatically normalizes input by ensuring proper spacing between zone and hemisphere.
Good to know: UTM uses the geodesy library for conversion. The coordinate system handles zone-specific calculations and converts to precise latitude/longitude values.
Good to know: The parser accepts both
18Nand18 Nformats (with or without space between zone and hemisphere). Internally, it normalizes to the format expected by the geodesy library.
Related
- parseMGRS - Parse Military Grid Reference System coordinates
- parseDecimalDegrees - Parse Decimal Degrees coordinates
- createCoordinate - Create coordinate with automatic parsing
- coordinateSystems - Available coordinate systems