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 Shapely 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 [4]:
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
Out[4]:
{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'geometry': {'type': 'Polygon', 'coordinates': (((106.70677205985224, 10.775261919692996), (106.70686399813559, 10.775261919692996), (106.70686399813559, 10.775351817067037), (106.70677205985224, 10.775351817067037), (106.70677205985224, 10.775261919692996)),)}, 'properties': {'mgrs': '48PXS86629165', 'resolution': 4, 'center_lat': 10.7753069, 'center_lon': 106.706818, 'cell_width': 10.055, 'cell_height': 9.944, 'cell_area': 99.988, 'cell_perimeter': 39.998}}]}
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:25<00:00, 553.86 cells/s]
Out[5]:
<Axes: >
MGRS Statistics¶
In [6]:
Copied!
from vgrid.stats import mgrsstats
mgrsstats('km')
from vgrid.stats import mgrsstats
mgrsstats('km')
Out[6]:
resolution | number_of_cells | avg_edge_len_km | avg_cell_area_km2 | |
---|---|---|---|---|
0 | 0 | 7.096896e+04 | 100.000 | 10000.000000 |
1 | 1 | 7.096896e+06 | 10.000 | 100.000000 |
2 | 2 | 7.096896e+08 | 1.000 | 1.000000 |
3 | 3 | 7.096896e+10 | 0.100 | 0.010000 |
4 | 4 | 7.096896e+12 | 0.010 | 0.000100 |
5 | 5 | 7.096896e+14 | 0.001 | 0.000001 |