Latlon to DGGS
Latitude/Longitude to DGGS Conversion Module
This module provides functions to convert latitude and longitude coordinates to various Discrete Global Grid System (DGGS) cell identifiers. It supports multiple DGGS types including H3, S2, A5, RHEALPix, ISEA4T, ISEA3H, DGGRID, DGGAL, EASE, QTM, OLC, Geohash, GEOREF, MGRS, Tilecode, Quadkey, Maidenhead, GARS, and DIGIPIN.
Each DGGS type has its own resolution range and addressing scheme. The module includes both programmatic functions and command-line interfaces (CLI) for each conversion type.
Each function follows the pattern: latlon2
CLI Usage Examples
latlon2h3 10.775275567242561 106.70679737574993 13 latlon2s2 10.775275567242561 106.70679737574993 21 latlon2dggrid ISEA7H 10.775275567242561 106.70679737574993 13 latlon2dggal gnosis 10.775275567242561 106.70679737574993 8 latlon2digipin 28.6139 77.2090 10
latlon2h3(lat, lon, res)
¶
Convert latitude and longitude to H3 cell identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
H3 resolution level [0-15] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
H3 cell identifier |
Example
latlon2h3(10.775275567242561, 106.70679737574993, 13) '8b194e64992ffff'
Source code in vgrid/conversion/latlon2dggs.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
latlon2s2(lat, lon, res=None)
¶
Convert latitude and longitude to S2 cell identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
S2 resolution level [0-30] |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
S2 cell token |
Example
latlon2s2(10.775275567242561, 106.70679737574993, 21) '1d4b9b0b8c8c8c8c'
Source code in vgrid/conversion/latlon2dggs.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
latlon2a5(lat, lon, res)
¶
Convert latitude and longitude to A5 cell identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
A5 resolution level [0-29] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
A5 cell identifier in hexadecimal format |
Example
latlon2a5(10.775275567242561, 106.70679737574993, 15) 'a5c8b9a8b9a8b9a8'
Source code in vgrid/conversion/latlon2dggs.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
latlon2rhealpix(lat, lon, res)
¶
Convert latitude and longitude to RHEALPix cell identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
RHEALPix resolution level [0-15] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
RHEALPix cell identifier |
Example
latlon2rhealpix(10.775275567242561, 106.70679737574993, 8) 'N:1:8:1:2:3:4:5:6:7:8'
Source code in vgrid/conversion/latlon2dggs.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
latlon2dggal(dggs_type, lat, lon, res)
¶
Convert latitude and longitude to DGGAL zone identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dggs_type
|
str
|
DGGAL DGGS type (e.g., 'gnosis', 'dggrid') |
required |
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
Resolution level. Defaults to type-specific default. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
DGGAL zone identifier |
Example
latlon2dggal('gnosis', 10.775275567242561, 106.70679737574993, 8) '123456789012345'
Source code in vgrid/conversion/latlon2dggs.py
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 | |
latlon2dggrid(dggrid_instance, dggs_type, lat, lon, res, output_address_type='SEQNUM')
¶
Convert latitude and longitude to DGGRID cell identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dggrid_instance
|
DGGRID instance for processing |
required | |
dggs_type
|
str
|
DGGRID DGGS type (e.g., 'ISEA7H', 'ISEA4T') |
required |
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
Resolution level. Defaults to type-specific default. |
required |
output_address_type
|
str
|
Output address format ('SEQNUM', 'INTERLEAVE', etc.) |
'SEQNUM'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
DGGRID cell identifier in specified format |
Example
dggrid_instance = create_dggrid_instance() latlon2dggrid(dggrid_instance, 'ISEA7H', 10.775275567242561, 106.70679737574993, 13) '123456789012345'
Source code in vgrid/conversion/latlon2dggs.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
latlon2isea4t(lat, lon, res)
¶
Convert latitude and longitude to ISEA4T cell identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
ISEA4T resolution level [0-39] (Windows only) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
ISEA4T cell identifier |
Example
latlon2isea4t(10.775275567242561, 106.70679737574993, 20) '0123456789abcdef012345'
Note
This function is only available on Windows systems.
Source code in vgrid/conversion/latlon2dggs.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
latlon2isea3h(lat, lon, res)
¶
Convert latitude and longitude to ISEA3H cell identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
ISEA3H resolution level [0-40] (Windows only) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
ISEA3H cell identifier |
Example
latlon2isea3h(10.775275567242561, 106.70679737574993, 27) '0123456789abcdef012345678'
Note
This function is only available on Windows systems. Resolution 27 is suitable for geocoding applications.
Source code in vgrid/conversion/latlon2dggs.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
latlon2ease(lat, lon, res)
¶
Convert latitude and longitude to EASE-DGGS cell identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
EASE resolution level [0-6] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
EASE-DGGS cell identifier |
Example
latlon2ease(10.775275567242561, 106.70679737574993, 3) '0123456789abcdef'
Source code in vgrid/conversion/latlon2dggs.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | |
latlon2qtm(lat, lon, res)
¶
Convert latitude and longitude to QTM cell identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
QTM resolution level [1-24] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
QTM cell identifier |
Example
latlon2qtm(10.775275567242561, 106.70679737574993, 12) '0123456789ab'
Source code in vgrid/conversion/latlon2dggs.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | |
latlon2olc(lat, lon, res)
¶
Convert latitude and longitude to Open Location Code (OLC/Plus Code).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
OLC code length [2,4,6,8,10-15] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
Open Location Code |
Example
latlon2olc(10.775275567242561, 106.70679737574993, 12) '6P5XQ2+2Q'
Source code in vgrid/conversion/latlon2dggs.py
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 | |
latlon2geohash(lat, lon, res)
¶
Convert latitude and longitude to Geohash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
Geohash precision [1-10] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
Geohash string |
Example
latlon2geohash(10.775275567242561, 106.70679737574993, 6) 'w8k3x2'
Source code in vgrid/conversion/latlon2dggs.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
latlon2georef(lat, lon, res)
¶
Convert latitude and longitude to GEOREF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
GEOREF resolution [0-10] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
GEOREF code |
Example
latlon2georef(10.775275567242561, 106.70679737574993, 5) 'MK1234567890'
Source code in vgrid/conversion/latlon2dggs.py
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
latlon2mgrs(lat, lon, res)
¶
Convert latitude and longitude to MGRS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
MGRS precision [0-5] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
MGRS coordinate |
Example
latlon2mgrs(10.775275567242561, 106.70679737574993, 3) '48PXV123456'
Source code in vgrid/conversion/latlon2dggs.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | |
latlon2tilecode(lat, lon, res)
¶
Convert latitude and longitude to Tilecode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
Tile zoom level [0-29] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
Tilecode identifier |
Example
latlon2tilecode(10.775275567242561, 106.70679737574993, 15) '123456789012345'
Source code in vgrid/conversion/latlon2dggs.py
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 | |
latlon2quadkey(lat, lon, res)
¶
Convert latitude and longitude to Quadkey.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
Quadkey zoom level [0-29] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
Quadkey identifier |
Example
latlon2quadkey(10.775275567242561, 106.70679737574993, 15) '123456789012345'
Source code in vgrid/conversion/latlon2dggs.py
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 | |
latlon2maidenhead(lat, lon, res)
¶
Convert latitude and longitude to Maidenhead grid square.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
Maidenhead precision [1-4] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
Maidenhead grid square |
Example
latlon2maidenhead(10.775275567242561, 106.70679737574993, 2) 'OK12'
Source code in vgrid/conversion/latlon2dggs.py
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | |
latlon2gars(lat, lon, res)
¶
Convert latitude and longitude to GARS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees |
required |
lon
|
float
|
Longitude in decimal degrees |
required |
res
|
int
|
GARS resolution [1-4] (1=30min, 2=15min, 3=5min, 4=1min) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
GARS identifier |
Example
latlon2gars(10.775275567242561, 106.70679737574993, 2) '123456789012345'
Source code in vgrid/conversion/latlon2dggs.py
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | |
latlon2digipin(lat, lon, res=None)
¶
Convert latitude and longitude to DIGIPIN code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude in decimal degrees (must be between 2.5 and 38.5) |
required |
lon
|
float
|
Longitude in decimal degrees (must be between 63.5 and 99.5) |
required |
res
|
int
|
DIGIPIN resolution [1-15] (number of characters in the code) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
DIGIPIN identifier with dashes (e.g., 'F3K-492-6P96') |
Example
latlon2digipin(28.6139, 77.2090, 10) 'F3K-492-6P96'
Note
DIGIPIN is a geocoding system for India. Coordinates outside the bounds (lat: 2.5-38.5, lon: 63.5-99.5) will return 'Out of Bound'.
Source code in vgrid/conversion/latlon2dggs.py
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 | |