mgrs-0.2.0 has been yanked.
mgrs
Bidirectional MGRS/lat-long coordinate conversion CLI and Rust library. Reads CSV files and outputs to CSV, GeoJSON, KML, or GPX.
Author
Albert Hui albert@securityronin.com
Features
- Bidirectional conversion: MGRS to lat/lon (
to-latlon) and lat/lon to MGRS (to-mgrs) - Multiple output formats: CSV, GeoJSON, KML, GPX
- Auto-detection: Finds MGRS columns automatically, no configuration needed
- Streaming: Processes rows one at a time — handles large files without loading everything into memory
- Strict mode: Optionally abort on first conversion error
- Library API: Use as a Rust library in your own projects
Installation
From crates.io
From source
The binary will be at target/release/mgrs.
Usage
MGRS to Lat/Lon
# Output CSV to stdout
# Output GeoJSON to a file
# Output KML with custom name column
# Output GPX waypoints
# Specify the MGRS column explicitly
# Abort on first error
Lat/Lon to MGRS
# Append MGRS column to CSV
# Control MGRS precision (1-5, default 6)
Backward Compatibility
Running without a subcommand defaults to to-latlon:
Flags
| Flag | Short | Description | Default |
|---|---|---|---|
--format |
-f |
Output format: csv, geojson, kml, gpx |
csv |
--output |
-o |
Output file path (omit for stdout) | stdout |
--column |
-c |
Column name or index containing coordinates | auto-detect |
--precision |
-p |
Decimal places in output coordinates | 6 |
--strict |
Abort on first conversion error | off | |
--name-column |
Column for placemark/waypoint names (KML/GPX) | first text column |
Input Format
CSV files with either:
- An MGRS column (for
to-latlon): values like18SUJ2337006519or18S UJ 23370 06519 - Latitude/Longitude columns (for
to-mgrs): columns with names containing "lat" and "lon"/"lng"
Output Formats
| Format | Description |
|---|---|
| CSV | Original columns plus appended Latitude/Longitude (or MGRS) columns |
| GeoJSON | FeatureCollection with Point features; all CSV columns become properties |
| KML | Placemark elements with ExtendedData carrying all CSV fields |
| GPX | wpt (waypoint) elements with names from --name-column or first text column |
Exit Codes
| Code | Meaning |
|---|---|
0 |
All rows converted successfully |
1 |
Fatal error (bad input file, unknown format, etc.) |
2 |
Partial success — some rows failed conversion |
Library Usage
Add to your Cargo.toml:
[]
= "0.2"
use ;
// MGRS to Lat/Lon
let coord = mgrs_to_latlon.unwrap;
println!;
// Lat/Lon to MGRS
let mgrs = latlon_to_mgrs.unwrap;
println!;
License
Dual-licensed under MIT or Apache-2.0, at your option.