{"id":16571508,"url":"https://github.com/hrbrmstr/mgrs","last_synced_at":"2025-03-16T20:31:13.991Z","repository":{"id":141238522,"uuid":"87711485","full_name":"hrbrmstr/mgrs","owner":"hrbrmstr","description":":globe_with_meridians: An R Package to Convert 'MGRS' (Military Grid Reference System) References From/To Other Coordiante Systems ","archived":false,"fork":false,"pushed_at":"2024-05-20T10:03:38.000Z","size":1437,"stargazers_count":32,"open_issues_count":3,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-27T13:19:21.339Z","etag":null,"topics":["coordinates","grid-references","mgrs","projection","r","rstats","utm-codes"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hrbrmstr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-09T13:44:27.000Z","updated_at":"2025-01-24T11:40:40.000Z","dependencies_parsed_at":"2023-12-06T11:41:59.438Z","dependency_job_id":null,"html_url":"https://github.com/hrbrmstr/mgrs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fmgrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fmgrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fmgrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fmgrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hrbrmstr","download_url":"https://codeload.github.com/hrbrmstr/mgrs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830912,"owners_count":20354848,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coordinates","grid-references","mgrs","projection","r","rstats","utm-codes"],"created_at":"2024-10-11T21:24:12.654Z","updated_at":"2025-03-16T20:31:13.225Z","avatar_url":"https://github.com/hrbrmstr.png","language":"C","readme":"\n[![Project Status: Active – The project has reached a stable, usable\nstate and is being actively\ndeveloped.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![Signed\nby](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr)\n![Signed commit\n%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg)\n\n![Minimal R\nVersion](https://img.shields.io/badge/R%3E%3D-4.0.0-blue.svg)\n![License](https://img.shields.io/badge/License-MIT-blue.svg)\n\n# mgrs\n\nConvert ‘MGRS’ (‘Military Grid Reference System’) Coordinates From/To\nOther Coordinate Systems\n\n## Description\n\nThe ‘Military Grid Reference System’ (‘MGRS’) is the geocoordinate\nstandard used by ‘NATO’ militaries for locating points on the earth. The\n‘MGRS’ is derived from the ‘Universal Transverse Mercator’ (‘UTM’) grid\nsystem and the universal polar stereographic (‘UPS’) grid system, but\nuses a different labeling convention. The ‘MGRS’ is used for the entire\nearth. Methods are provided to convert ‘MGRS’ coordinates to and from\nother coordinate systems.\n\nEssentially, a lightweight R wrapper around bits of\n\u003chttps://svn.osgeo.org/gdal/trunk/gdal/frmts/nitf/\u003e.\n\nDecent reference on MGRS \u0026 UTM (Universal Transverse Mercator):\n\u003chttps://www.luomus.fi/en/utm-mgrs-atlas-florae-europaeae\u003e.\n\n\u003cfigure\u003e\n\u003cimg src=\"man/figures/mgrs-grid.png\"\nalt=\"The origin of the MGRS grid, in the Pacific. Honolulu is in 4QFJ.\" /\u003e\n\u003cfigcaption aria-hidden=\"true\"\u003eThe origin of the MGRS grid, in the\nPacific. Honolulu is in 4QFJ.\u003c/figcaption\u003e\n\u003c/figure\u003e\n\n[CC-BY-SA\n3.0](https://en.wikipedia.org/wiki/Military_Grid_Reference_System#/media/File:MGRSgridOriginSchemeAA.png)\n\n## What’s Inside The Tin\n\nThe following functions are implemented:\n\n- `latlng_to_mgrs`: Convert latitude/longitude to MGRS string\n- `mgrs_precision`: Return MGRS grid reference precision (in meters)\n- `mgrs_to_latlng`: Convert an MGRS string to latitude/longitude\n- `mgrs_to_ups`: Convert MGRS to UPS\n- `mgrs_to_utm`: Convert MGRS to UTM\n- `ups_to_latlng`: Convert UPS to Latitude/Longitude\n- `ups_to_mgrs`: Convert UPS to MGRS\n- `utm_to_latlng`: Convert UTM to Latitude/Longitude\n- `utm_to_mgrs`: Convert UTM to MGRS\n\n## Installation\n\n``` r\nremotes::install_github(\"hrbrmstr/mgrs\")\n```\n\nNOTE: To use the ‘remotes’ install options you will need to have the\n[{remotes} package](https://github.com/r-lib/remotes) installed.\n\n## Usage\n\n``` r\nlibrary(mgrs)\nlibrary(sf)\nlibrary(ggplot2)\nlibrary(hrbrthemes)\n\n# current version\npackageVersion(\"mgrs\")\n## [1] '0.2.4'\n```\n\n### Basics\n\n``` r\nmgrs_to_latlng(\"33UXP04\")\n##      mgrs      lat      lng\n## 1 33UXP04 48.20535 16.34593\n\nmgrs_to_latlng(\"33UXP04\") |\u003e \n  sf::st_as_sf(\n    coords = c(\"lng\", \"lat\"),\n    crs = 4326\n  )\n## Simple feature collection with 1 feature and 1 field\n## Geometry type: POINT\n## Dimension:     XY\n## Bounding box:  xmin: 16.34593 ymin: 48.20535 xmax: 16.34593 ymax: 48.20535\n## Geodetic CRS:  WGS 84\n##      mgrs                  geometry\n## 1 33UXP04 POINT (16.34593 48.20535)\n\nlatlng_to_mgrs(48.20535, 16.34593)\n## [1] \"33UXP0000040000\"\n\nmgrs_to_latlng(\"33UXP0500444996\")\n##              mgrs      lat      lng\n## 1 33UXP0500444996 48.24947 16.41449\n\nlatlng_to_mgrs(48.24948, 16.41449)\n## [1] \"33UXP0500344996\"\n\nmgrs_to_latlng(\"33UXP0500444996\") |\u003e \n  sf::st_as_sf(\n    coords = c(\"lng\", \"lat\"),\n    crs = 4326\n  )\n## Simple feature collection with 1 feature and 1 field\n## Geometry type: POINT\n## Dimension:     XY\n## Bounding box:  xmin: 16.41449 ymin: 48.24947 xmax: 16.41449 ymax: 48.24947\n## Geodetic CRS:  WGS 84\n##              mgrs                  geometry\n## 1 33UXP0500444996 POINT (16.41449 48.24947)\n\nmgrs_to_latlng(\"24XWT783908\")\n##          mgrs      lat       lng\n## 1 24XWT783908 83.62738 -32.66879\n\nmgrs_to_latlng(\"24XWT783908\") |\u003e \n  sf::st_as_sf(\n    coords = c(\"lng\", \"lat\"),\n    crs = 4326\n  )\n## Simple feature collection with 1 feature and 1 field\n## Geometry type: POINT\n## Dimension:     XY\n## Bounding box:  xmin: -32.66879 ymin: 83.62738 xmax: -32.66879 ymax: 83.62738\n## Geodetic CRS:  WGS 84\n##          mgrs                   geometry\n## 1 24XWT783908 POINT (-32.66879 83.62738)\n\nlatlng_to_mgrs(83.62738, -32.66879)\n## [1] \"25XEN0410486507\"\n\nutm_to_mgrs(48, \"N\", 377299, 1483035)\n## [1] \"48PUV7729983035\"\n\nmgrs_to_utm(\"48PUV7729883034\")\n##              mgrs zone hemisphere easting northing\n## 1 48PUV7729883034   48          N  377298  1483034\n\nups_to_mgrs(\"N\", 2426773, 1530125)\n## [1] \"ZGC2677330125\"\n\nmgrs_to_ups(\"ZGC2677330125\")\n##            mgrs hemisphere easting northing\n## 1 ZGC2677330125          N 2426773  1530125\n\nc(\n  \"4Q\", \"4QFJ\", \"4QFJ16\", \n  \"4QFJ1267\", \"4QFJ123678\",\n  \"4QFJ12346789\", \"4QFJ1234567890\"\n) -\u003e grefs\n\nmgrs_precision(grefs)\n## # A tibble: 7 × 2\n##   grid_ref       precision\n##   \u003cchr\u003e              \u003cdbl\u003e\n## 1 4Q                    NA\n## 2 4QFJ              100000\n## 3 4QFJ16             10000\n## 4 4QFJ1267            1000\n## 5 4QFJ123678           100\n## 6 4QFJ12346789          10\n## 7 4QFJ1234567890         1\n```\n\n### Usage in the {tidyverse}\n\n``` r\ndata.frame(\n  id = 1:50, \n  mgrs = c(\n    \"16SEB20\", \"09UXQ25\", \"12SVC48\", \"15SWU64\", \"11SKA54\", \"13SDC58\", \n    \"18TYM20\", \"18SWH08\", \"17RML38\", \"17SKR77\", \"09RYR61\", \"12TTP62\", \n    \"16TBK93\", \"16TEK73\", \"15TVG64\", \"14SNH75\", \"16SFG94\", \"15RWP68\", \n    \"19TEL05\", \"18SUJ54\", \"19TBG89\", \"16TFN87\", \"15TUM73\", \"16SBB31\", \n    \"15SWC44\", \"12TXS28\", \"14TML57\", \"11SND12\", \"19TCJ00\", \"18SWK62\", \n    \"13SDU11\", \"18TVN87\", \"17SQV22\", \"14TMT13\", \"17TLE65\", \"14SPE73\", \n    \"10TGP36\", \"18TTL93\", \"19TCG20\", \"17SNT42\", \"14TMQ40\", \"16SEE44\", \n    \"14RNV27\", \"12SVJ72\", \"18TXQ90\", \"17SQB46\", \"11TKN95\", \"17SNC25\", \n    \"16TBQ64\", \"13TCH16\"\n    )\n) -\u003e sample_dta\n\nsample_dta |\u003e \n  dplyr::mutate(\n    x = lapply(mgrs, mgrs_to_latlng, include_mgrs_ref = FALSE)\n  ) |\u003e\n  tidyr::unnest(x) |\u003e \n  sf::st_as_sf(\n    coords = c(\"lng\", \"lat\"),\n    crs = 4326\n  )\n## Simple feature collection with 50 features and 2 fields\n## Geometry type: POINT\n## Dimension:     XY\n## Bounding box:  xmin: -127.353 ymin: 27.84288 xmax: -69 ymax: 49.19105\n## Geodetic CRS:  WGS 84\n## # A tibble: 50 × 3\n##       id mgrs                geometry\n##  * \u003cint\u003e \u003cchr\u003e            \u003cPOINT [°]\u003e\n##  1     1 16SEB20 (-86.78701 32.53717)\n##  2     2 09UXQ25  (-127.353 49.19105)\n##  3     3 12SVC48 (-111.6509 34.15921)\n##  4     4 15SWU64 (-92.34486 34.70027)\n##  5     5 11SKA54  (-119.7903 36.4727)\n##  6     6 13SDC58 (-105.5747 38.66717)\n##  7     7 18TYM20 (-72.36334 41.52143)\n##  8     8 18SWH08       (-75 38.66858)\n##  9     9 17RML38  (-81.7109 27.84288)\n## 10    10 17SKR77 (-83.44116 32.24313)\n## # ℹ 40 more rows\n```\n\n### Visual Verification\n\n``` r\n# precision == 1\n\nc(\n  \"16SEB20\", \"09UXQ25\", \"12SVC48\", \"15SWU64\", \"11SKA54\", \"13SDC58\", \n  \"18TYM20\", \"18SWH08\", \"17RML38\", \"17SKR77\", \"09RYR61\", \"12TTP62\", \n  \"16TBK93\", \"16TEK73\", \"15TVG64\", \"14SNH75\", \"16SFG94\", \"15RWP68\", \n  \"19TEL05\", \"18SUJ54\", \"19TBG89\", \"16TFN87\", \"15TUM73\", \"16SBB31\", \n  \"15SWC44\", \"12TXS28\", \"14TML57\", \"11SND12\", \"19TCJ00\", \"18SWK62\", \n  \"13SDU11\", \"18TVN87\", \"17SQV22\", \"14TMT13\", \"17TLE65\", \"14SPE73\", \n  \"10TGP36\", \"18TTL93\", \"19TCG20\", \"17SNT42\", \"14TMQ40\", \"16SEE44\", \n  \"14RNV27\", \"12SVJ72\", \"18TXQ90\", \"17SQB46\", \"11TKN95\", \"17SNC25\", \n  \"16TBQ64\", \"13TCH16\"\n) -\u003e mgrs_conus_state_centers\n\nmgrs_conus_state_centers |\u003e \n  mgrs_to_latlng() |\u003e\n  st_as_sf(\n    coords = c(\"lng\", \"lat\"),\n    crs = 4326\n  ) |\u003e \n  ggplot() +\n  geom_sf(\n    shape = 22,\n    ize = 2, color = \"black\", \n    fill = \"white\"\n  ) +\n  coord_sf(\n    crs = 5070\n  ) +\n  theme_ft_rc(grid=\"XY\")\n```\n\n\u003cimg src=\"man/figures/README-ex3-1.svg\" width=\"960\" /\u003e\n\n## mgrs Metrics\n\n| Lang         | \\# Files |  (%) |  LoC |  (%) | Blank lines |  (%) | \\# Lines |  (%) |\n|:-------------|---------:|-----:|-----:|-----:|------------:|-----:|---------:|-----:|\n| C            |        5 | 0.15 | 1847 | 0.38 |         334 | 0.34 |      918 | 0.26 |\n| C++          |        2 | 0.06 |  346 | 0.07 |          64 | 0.07 |       99 | 0.03 |\n| C/C++ Header |        5 | 0.15 |  188 | 0.04 |          74 | 0.08 |      546 | 0.16 |\n| R            |        5 | 0.15 |   41 | 0.01 |          17 | 0.02 |      198 | 0.06 |\n| SUM          |       17 | 0.50 | 2422 | 0.50 |         489 | 0.50 |     1761 | 0.50 |\n\n{cloc} 📦 metrics for mgrs\n\n## Code of Conduct\n\nPlease note that this project is released with a Contributor Code of\nConduct. By participating in this project you agree to abide by its\nterms.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbrmstr%2Fmgrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhrbrmstr%2Fmgrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbrmstr%2Fmgrs/lists"}