14 mgrs
Working with MGRS in Vgrid DGGS¶
Full Vgrid DGGS documentation is available at vgrid document.
To work with Vgrid DGGS directly in GeoPandas and Pandas, please use vgridpandas. Full Vgridpandas DGGS documentation is available at vgridpandas document.
To work with Vgrid DGGS in QGIS, install the Vgrid Plugin.
To visualize DGGS in Maplibre GL JS, try the vgrid-maplibre library.
For an interactive demo, visit the Vgrid Homepage.
In [1]:
Copied!
# %pip install vgrid --upgrade
# %pip install vgrid --upgrade
latlon2mgrs¶
In [2]:
Copied!
from vgrid.conversion.latlon2dggs import latlon2mgrs
lat = 10.775276
lon = 106.706797
res = 4
mgrs_id = latlon2mgrs(lat, lon, res)
mgrs_id
from vgrid.conversion.latlon2dggs import latlon2mgrs
lat = 10.775276
lon = 106.706797
res = 4
mgrs_id = latlon2mgrs(lat, lon, res)
mgrs_id
Out[2]:
'48PXS86629165'
MGRS to Polygon¶
In [3]:
Copied!
from vgrid.conversion.dggs2geo.mgrs2geo import mgrs2geo
mgrs_geo = mgrs2geo(mgrs_id)
mgrs_geo
from vgrid.conversion.dggs2geo.mgrs2geo import mgrs2geo
mgrs_geo = mgrs2geo(mgrs_id)
mgrs_geo
Out[3]:
MGRS to GeoJSON¶
In [ ]:
Copied!
from vgrid.conversion.dggs2geo.mgrs2geo import mgrs2geojson
mgrs_geojson = mgrs2geojson(mgrs_id)
# mgrs_geojson
from vgrid.conversion.dggs2geo.mgrs2geo import mgrs2geojson
mgrs_geojson = mgrs2geojson(mgrs_id)
# mgrs_geojson
MGRS Generator¶
In [5]:
Copied!
from vgrid.generator.mgrsgrid import mgrsgrid
mgrs_grid = mgrsgrid(gzd="48P", resolution=1, output_format="gpd")
mgrs_grid.plot(edgecolor="white")
from vgrid.generator.mgrsgrid import mgrsgrid
mgrs_grid = mgrsgrid(gzd="48P", resolution=1, output_format="gpd")
mgrs_grid.plot(edgecolor="white")
Generating MGRS DGGS: 100%|██████████| 14240/14240 [00:11<00:00, 1233.99 cells/s]
Out[5]:
<Axes: >
MGRS Statistics¶
Characteristic Length Scale (CLS - suggested by Ralph Kahn): the diameter of a spherical cap of the same cell's area
In [2]:
Copied!
from vgrid.stats import mgrsstats
mgrsstats("km")
from vgrid.stats import mgrsstats
mgrsstats("km")
Out[2]:
| resolution | number_of_cells | avg_edge_len_km | avg_cell_area_km2 | cls_km | |
|---|---|---|---|---|---|
| 0 | 0 | 7.096896e+04 | 100.000 | 10000.000000 | 1.128379e-04 |
| 1 | 1 | 7.096896e+06 | 10.000 | 100.000000 | 1.128379e-05 |
| 2 | 2 | 7.096896e+08 | 1.000 | 1.000000 | 1.128379e-06 |
| 3 | 3 | 7.096896e+10 | 0.100 | 0.010000 | 1.128379e-07 |
| 4 | 4 | 7.096896e+12 | 0.010 | 0.000100 | 1.128379e-08 |
| 5 | 5 | 7.096896e+14 | 0.001 | 0.000001 | 1.128379e-09 |