Convert geographic coordinates (longitude/latitude) to GARS codes, or convert GARS codes back to coordinates.

gars_fwd(x, precision = 2L)

gars_rev(gars)

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 specifying the precision level (0, 1, or 2):

  • 0: 30-minute cells (5-character code)

  • 1: 15-minute quadrants (6-character code)

  • 2: 5-minute keypads (7-character code, maximum precision)

gars

Character vector of GARS codes to convert back to coordinates.

Value

  • gars_fwd(): Character vector of GARS codes.

  • gars_rev(): Data frame with columns:

    • lon: Longitude of cell center in decimal degrees

    • lat: Latitude of cell center in decimal degrees

    • precision: Precision level (0, 1, or 2)

    • lat_resolution: Cell half-height in degrees

    • lon_resolution: Cell half-width in degrees

Details

GARS (Global Area Reference System) is a standardized geospatial reference system used by the US military. It divides the Earth into cells using a hierarchical grid:

  • 30-minute cells: The base grid (720 × 360 cells globally)

  • 15-minute quadrants: Each 30-minute cell divided into 4 quadrants (1-4)

  • 5-minute keypads: Each quadrant divided into 9 keypads (1-9, like a phone keypad)

A GARS code consists of:

  • 3-digit longitude band (001-720)

  • 2-letter latitude band (AA-QZ)

  • Optional 1-digit quadrant (1-4)

  • Optional 1-digit keypad (1-9)

Example: "006AG39" = 5-minute cell at approximately (-177°, -89.5°)

See also

mgrs_fwd() for Military Grid Reference System, another military grid system.

Examples

# Basic conversion
gars_fwd(c(-74, 40.7))
#> [1] "213LX31"

# Different precision levels
gars_fwd(c(-74, 40.7), precision = 0)  # 30-minute
#> [1] "213LX"
gars_fwd(c(-74, 40.7), precision = 1)  # 15-minute
#> [1] "213LX3"
gars_fwd(c(-74, 40.7), precision = 2)  # 5-minute
#> [1] "213LX31"

# Multiple points
pts <- cbind(lon = c(-74, 139.7, 0), lat = c(40.7, 35.7, 51.5))
gars_fwd(pts, precision = 2)
#> [1] "213LX31" "640LM33" "361MV37"

# Reverse conversion
gars_rev(c("213LR29", "498MH18", "361NS47"))
#>           lon      lat precision lat_resolution lon_resolution
#> 1 -73.5416667 37.79167         2     0.08333333     0.08333333
#> 2  68.6250000 45.79167         2     0.08333333     0.08333333
#> 3   0.2916667 62.04167         2     0.08333333     0.08333333