Convert geographic coordinates (longitude/latitude) to MGRS grid reference strings, or convert MGRS strings back to coordinates.

mgrs_fwd(x, precision = 5L)

mgrs_rev(code)

Arguments

x

A two-column matrix or data frame of coordinates (longitude, latitude) in decimal degrees, or a list with longitude and latitude components. Can also be a length-2 numeric vector for a single point.

precision

Integer between 0 and 5 (default 5) specifying the precision of the MGRS grid reference:

  • 0: 100 km precision

  • 1: 10 km precision

  • 2: 1 km precision

  • 3: 100 m precision

  • 4: 10 m precision

  • 5: 1 m precision (full precision)

Can be a vector to specify different precisions for each point.

code

Character vector of MGRS grid reference strings to convert back to coordinates.

Value

  • mgrs_fwd(): Character vector of MGRS grid reference strings

  • mgrs_rev(): Data frame with columns:

    • lon: Longitude in decimal degrees

    • lat: Latitude in decimal degrees

    • x: Easting in meters (UTM/UPS projection)

    • y: Northing in meters (UTM/UPS projection)

    • zone: UTM zone number (0 for polar UPS regions)

    • northp: Logical, TRUE for northern hemisphere, FALSE for southern

    • precision: Integer precision level (0-5) encoded in the MGRS string

    • convergence: Meridian convergence in degrees (angle between true north and grid north)

    • scale: Scale factor at the point (dimensionless, typically near 1.0)

    • grid_zone: Grid zone designator (e.g., "51P", "04L")

    • square_100km: 100km square identifier (e.g., "SM", "GH")

    • crs: EPSG code string for the appropriate UTM/UPS projection (e.g., "EPSG:32755" for UTM zone 55S, "EPSG:32661" for UPS North)

Details

The Military Grid Reference System (MGRS) is a geocoordinate standard used by NATO militaries for locating points on Earth. It is an alternative to latitude/longitude that uses a hierarchical grid system.

Both functions are fully vectorized. Missing values (NA) are not currently supported.

For polar regions (latitude > 84°N or < 80°S), the Universal Polar Stereographic (UPS) system is used instead of UTM, indicated by zone = 0.

Examples

# Single point conversion
(code <- mgrs_fwd(cbind(147.325, -42.881)))
#> [1] "55GEN2654152348"
mgrs_rev(code)
#>       lon     lat        x       y zone northp precision convergence     scale
#> 1 147.325 -42.881 526541.5 5252348   55  FALSE         5  -0.2211584 0.9996087
#>   grid_zone square_100km        crs
#> 1       55G           EN EPSG:32755

# Multiple points with varying precision
x <- cbind(lon = c(-63.22, 34.02, 49.45, 45.67, 47.4),
           lat = c(17.62, -1.9, 37.47, 39.84, 33.15))
codes <- mgrs_fwd(x, precision = c(5, 4, 3, 2, 1))
codes
#> [1] "20QME7666048158" "36MXC13448995"   "39SUB629481"     "38SNK5710"      
#> [5] "38SQB27"        

# Reverse conversion returns detailed coordinate information
result <- mgrs_rev(codes)
result
#>         lon       lat        x       y zone northp precision convergence
#> 1 -63.22000 17.620003 476660.5 1948158   20   TRUE         5 -0.06659575
#> 2  34.02000 -1.900033 613445.0 9789955   36  FALSE         4 -0.03382266
#> 3  49.45015 37.470082 362950.0 4148150   39   TRUE         3 -0.94299085
#> 4  45.67208 39.842567 557500.0 4410500   38   TRUE         2  0.43059783
#> 5  47.41350 33.190489 725000.0 3675000   38   TRUE         1  1.32176235
#>       scale grid_zone square_100km        crs
#> 1 0.9996067       20Q           ME EPSG:32620
#> 2 0.9997593       36M           XC EPSG:32736
#> 3 0.9998314       39S           UB EPSG:32639
#> 4 0.9996407       38S           NK EPSG:32638
#> 5 1.0002242       38S           QB EPSG:32638

# Polar regions use UPS (zone 0)
polar_codes <- mgrs_fwd(cbind(c(147, -100), c(88, -88)))
mgrs_rev(polar_codes)
#>         lon lat       x       y zone northp precision convergence     scale
#> 1 146.99996  88 2120948 2186242    0   TRUE         5   146.99996 0.9943028
#> 2 -99.99989 -88 1781304 1961438    0  FALSE         5    99.99989 0.9943028
#>   grid_zone square_100km        crs
#> 1         Z           BJ EPSG:32661
#> 2         A           XM EPSG:32761