gars_fwd: Global Area Reference System (GARS)

View source: R/gars.R

gars_fwdR Documentation

Global Area Reference System (GARS)

Description

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

Usage

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.

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°)

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

See Also

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

Examples

# Basic conversion
gars_fwd(c(-74, 40.7))

# Different precision levels
gars_fwd(c(-74, 40.7), precision = 0)  # 30-minute
gars_fwd(c(-74, 40.7), precision = 1)  # 15-minute
gars_fwd(c(-74, 40.7), precision = 2)  # 5-minute

# Multiple points
pts <- cbind(lon = c(-74, 139.7, 0), lat = c(40.7, 35.7, 51.5))
gars_fwd(pts, precision = 2)

# Reverse conversion
gars_rev(c("213LR29", "498MH18", "361NS47"))

geographiclib documentation built on March 4, 2026, 9:07 a.m.