Skip to content

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(lat, lon, res=) and returns the corresponding cell identifier as a string or appropriate data type.

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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def latlon2h3(lat, lon, res):
    """
    Convert latitude and longitude to H3 cell identifier.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): H3 resolution level [0-15]

    Returns:
        str: H3 cell identifier

    Example:
        >>> latlon2h3(10.775275567242561, 106.70679737574993, 13)
        '8b194e64992ffff'
    """
    if res is None:
        res = DGGS_TYPES["h3"]["default_res"]
    res = validate_h3_resolution(res)
    h3_id = h3.latlng_to_cell(lat, lon, res)
    return h3_id

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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
def latlon2s2(lat, lon, res=None):
    """
    Convert latitude and longitude to S2 cell identifier.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): S2 resolution level [0-30]

    Returns:
        str: S2 cell token

    Example:
        >>> latlon2s2(10.775275567242561, 106.70679737574993, 21)
        '1d4b9b0b8c8c8c8c'
    """
    if res is None:
        res = DGGS_TYPES["s2"]["default_res"]
    res = validate_s2_resolution(res)
    lat_lng = s2.LatLng.from_degrees(lat, lon)
    s2_cell= s2.CellId.from_lat_lng(lat_lng)  # return S2 cell at max level 30
    s2_cell_res = s2_cell.parent(res)  # get S2 cell at resolution  
    s2_token = s2.CellId.to_token(s2_cell_res)  # get Cell ID Token, shorter than cell_id.id()
    return s2_token

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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
def latlon2a5(lat, lon, res):
    """
    Convert latitude and longitude to A5 cell identifier.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): A5 resolution level [0-29]

    Returns:
        str: A5 cell identifier in hexadecimal format

    Example:
        >>> latlon2a5(10.775275567242561, 106.70679737574993, 15)
        'a5c8b9a8b9a8b9a8'
    """
    if res is None:
        res = DGGS_TYPES["a5"]["default_res"]
    res = validate_a5_resolution(res)
    a5_id = a5.lonlat_to_cell((lon, lat), res)
    a5_hex = a5.u64_to_hex(a5_id)
    return a5_hex

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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
def latlon2rhealpix(lat, lon, res):
    """
    Convert latitude and longitude to RHEALPix cell identifier.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): RHEALPix resolution level [0-15]

    Returns:
        str: RHEALPix cell identifier

    Example:
        >>> latlon2rhealpix(10.775275567242561, 106.70679737574993, 8)
        'N:1:8:1:2:3:4:5:6:7:8'
    """
    res = validate_rhealpix_resolution(res)
    E = WGS84_ELLIPSOID
    rhealpix_dggs = RHEALPixDGGS(ellipsoid=E, north_square=1, south_square=3, N_side=3)
    point = (lon, lat)
    rhealpix_cell = rhealpix_dggs.cell_from_point(res, point, plane=False)
    rhealpix_id = str(rhealpix_cell)
    return rhealpix_id

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
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
def latlon2dggal(dggs_type, lat, lon, res):
    """
    Convert latitude and longitude to DGGAL zone identifier.

    Args:
        dggs_type (str): DGGAL DGGS type (e.g., 'gnosis', 'dggrid')
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int, optional): Resolution level. Defaults to type-specific default.

    Returns:
        str: DGGAL zone identifier

    Example:
        >>> latlon2dggal('gnosis', 10.775275567242561, 106.70679737574993, 8)
        '123456789012345'
    """
    dggs_type = validate_dggal_type(dggs_type)
    if res is None:
        res = DGGAL_TYPES[dggs_type]["default_res"]
    res = validate_dggal_resolution(dggs_type, res)
    dggs_class_name = DGGAL_TYPES[dggs_type]["class_name"]
    dggrs = globals()[dggs_class_name]()
    dggal_zone = dggrs.getZoneFromWGS84Centroid(res, GeoPoint(lat, lon))
    dggal_zoneid = dggrs.getZoneTextID(dggal_zone)
    return dggal_zoneid

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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
def latlon2dggrid(
    dggrid_instance, dggs_type, lat, lon, res, output_address_type="SEQNUM"
):
    """
    Convert latitude and longitude to DGGRID cell identifier.

    Args:
        dggrid_instance: DGGRID instance for processing
        dggs_type (str): DGGRID DGGS type (e.g., 'ISEA7H', 'ISEA4T')
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int, optional): Resolution level. Defaults to type-specific default.
        output_address_type (str): Output address format ('SEQNUM', 'INTERLEAVE', etc.)

    Returns:
        str: DGGRID cell identifier in specified format

    Example:
        >>> dggrid_instance = create_dggrid_instance()
        >>> latlon2dggrid(dggrid_instance, 'ISEA7H', 10.775275567242561, 106.70679737574993, 13)
        '123456789012345'
    """
    point = Point(lon, lat)
    dggs_type = validate_dggrid_type(dggs_type)
    if res is None:
        res = DGGRID_TYPES[dggs_type]["default_res"]
    res = validate_dggrid_resolution(dggs_type, res)
    geodf_points_wgs84 = gpd.GeoDataFrame([{"geometry": point}], crs="EPSG:4326")

    dggrid_cell = dggrid_instance.cells_for_geo_points(
        geodf_points_wgs84=geodf_points_wgs84,
        cell_ids_only=True,
        dggs_type=dggs_type,
        resolution=res,
        output_address_type=output_address_type,
    )
    # seqnum = dggrid_cell.loc[0, "name"]
    # if output_address_type == "SEQNUM":
    #     return seqnum
    # address_type_transform = dggrid_instance.address_transform(
    #     [seqnum],
    #     dggs_type=dggs_type,
    #     resolution=res,
    #     mixed_aperture_level=None,
    #     input_address_type="SEQNUM",
    #     output_address_type=output_address_type,
    # )
    # dggrid_id = address_type_transform.loc[0, output_address_type]
    # return dggrid_id
    return dggrid_cell.loc[0, "name"]

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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
def latlon2isea4t(lat, lon, res):
    """
    Convert latitude and longitude to ISEA4T cell identifier.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): ISEA4T resolution level [0-39] (Windows only)

    Returns:
        str: ISEA4T cell identifier

    Example:
        >>> latlon2isea4t(10.775275567242561, 106.70679737574993, 20)
        '0123456789abcdef012345'

    Note:
        This function is only available on Windows systems.
    """
    if res is None:
        res = DGGS_TYPES["isea4t"]["default_res"]
    res = validate_isea4t_resolution(res)
    max_accuracy = ISEA4T_RES_ACCURACY_DICT[
        39
    ]  # maximum cell_id length with 41 characters
    lat_long_point = LatLongPoint(lat, lon, max_accuracy)
    isea4t_cell_max_accuracy = isea4t_dggs.convert_point_to_dggs_cell(lat_long_point)
    cell_id_len = res + 2
    isea4t_cell = DggsCell(isea4t_cell_max_accuracy._cell_id[:cell_id_len])
    return isea4t_cell._cell_id

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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
def latlon2isea3h(lat, lon, res):
    """
    Convert latitude and longitude to ISEA3H cell identifier.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): ISEA3H resolution level [0-40] (Windows only)

    Returns:
        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.
    """
    # res: [0..40], res=27 is suitable for geocoding
    if res is None:
        res = DGGS_TYPES["isea3h"]["default_res"]
    res = validate_isea3h_resolution(res)
    accuracy = ISEA3H_RES_ACCURACY_DICT.get(res)
    lat_long_point = LatLongPoint(lat, lon, accuracy)
    isea3h_cell = isea3h_dggs.convert_point_to_dggs_cell(lat_long_point)
    return str(isea3h_cell.get_cell_id())

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
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
def latlon2ease(lat, lon, res):
    """
    Convert latitude and longitude to EASE-DGGS cell identifier.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): EASE resolution level [0-6]

    Returns:
        str: EASE-DGGS cell identifier

    Example:
        >>> latlon2ease(10.775275567242561, 106.70679737574993, 3)
        '0123456789abcdef'
    """
    if res is None:
        res = DGGS_TYPES["ease"]["default_res"]
    res = validate_ease_resolution(res)
    ease_cell = geos_to_grid_ids([(lon, lat)], level=res)
    ease_id = ease_cell["result"]["data"][0]
    return ease_id

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
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
def latlon2qtm(lat, lon, res):
    """
    Convert latitude and longitude to QTM cell identifier.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): QTM resolution level [1-24]

    Returns:
        str: QTM cell identifier

    Example:
        >>> latlon2qtm(10.775275567242561, 106.70679737574993, 12)
        '0123456789ab'
    """
    if res is None:
        res = DGGS_TYPES["qtm"]["default_res"]
    res = validate_qtm_resolution(res)
    qtm_id = qtm.latlon_to_qtm_id(lat, lon, res)
    return qtm_id

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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
def latlon2olc(lat, lon, res):
    """
    Convert latitude and longitude to Open Location Code (OLC/Plus Code).

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): OLC code length [2,4,6,8,10-15]

    Returns:
        str: Open Location Code

    Example:
        >>> latlon2olc(10.775275567242561, 106.70679737574993, 12)
        '6P5XQ2+2Q'
    """
    if res is None:
        res = DGGS_TYPES["olc"]["default_res"]
    res = validate_olc_resolution(res)
    olc_id = olc.encode(lat, lon, res)
    return olc_id

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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
def latlon2geohash(lat, lon, res):
    """
    Convert latitude and longitude to Geohash.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): Geohash precision [1-10]

    Returns:
        str: Geohash string

    Example:
        >>> latlon2geohash(10.775275567242561, 106.70679737574993, 6)
        'w8k3x2'
    """
    if res is None:
        res = DGGS_TYPES["geohash"]["default_res"]
    res = validate_geohash_resolution(res)
    geohash_id = geohash.encode(lat, lon, res)
    return geohash_id

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
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
def latlon2georef(lat, lon, res):
    """
    Convert latitude and longitude to GEOREF.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): GEOREF resolution [0-10]

    Returns:
        str: GEOREF code

    Example:
        >>> latlon2georef(10.775275567242561, 106.70679737574993, 5)
        'MK1234567890'
    """
    res = validate_georef_resolution(res)   
    georef_id = georef.encode(lat, lon, res)
    return georef_id

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
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
def latlon2mgrs(lat, lon, res):
    """
    Convert latitude and longitude to MGRS.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): MGRS precision [0-5]

    Returns:
        str: MGRS coordinate

    Example:
        >>> latlon2mgrs(10.775275567242561, 106.70679737574993, 3)
        '48PXV123456'
    """
    if res is None:
        res = DGGS_TYPES["mgrs"]["default_res"]
    res = validate_mgrs_resolution(res)
    mgrs_cell = mgrs.toMgrs(lat, lon, res)
    return mgrs_cell

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
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
def latlon2tilecode(lat, lon, res):
    """
    Convert latitude and longitude to Tilecode.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): Tile zoom level [0-29]

    Returns:
        str: Tilecode identifier

    Example:
        >>> latlon2tilecode(10.775275567242561, 106.70679737574993, 15)
        '123456789012345'
    """
    if res is None:
        res = DGGS_TYPES["tilecode"]["default_res"]
    res = validate_tilecode_resolution(res)
    tilecode_id = tilecode.latlon2tilecode(lat, lon, res)
    return tilecode_id

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
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
def latlon2quadkey(lat, lon, res):
    """
    Convert latitude and longitude to Quadkey.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): Quadkey zoom level [0-29]

    Returns:
        str: Quadkey identifier

    Example:
        >>> latlon2quadkey(10.775275567242561, 106.70679737574993, 15)
        '123456789012345'
    """
    if res is None:
        res = DGGS_TYPES["quadkey"]["default_res"]
    res = validate_quadkey_resolution(res)
    quadkey_id = tilecode.latlon2quadkey(lat, lon, res)
    return quadkey_id

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
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
def latlon2maidenhead(lat, lon, res):
    """
    Convert latitude and longitude to Maidenhead grid square.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): Maidenhead precision [1-4]

    Returns:
        str: Maidenhead grid square

    Example:
        >>> latlon2maidenhead(10.775275567242561, 106.70679737574993, 2)
        'OK12'
    """
    if res is None:
        res = DGGS_TYPES["maidenhead"]["default_res"]
    res = validate_maidenhead_resolution(res)
    maidenhead_id = maidenhead.toMaiden(lat, lon, res)
    # maidenhead_id = maidenhead.to_maiden(lat, lon, res)
    return maidenhead_id

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
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
def latlon2gars(lat, lon, res):
    """
    Convert latitude and longitude to GARS.

    Args:
        lat (float): Latitude in decimal degrees
        lon (float): Longitude in decimal degrees
        res (int): GARS resolution [1-4] (1=30min, 2=15min, 3=5min, 4=1min)

    Returns:
        str: GARS identifier

    Example:
        >>> latlon2gars(10.775275567242561, 106.70679737574993, 2)
        '123456789012345'
    """
    if res is None:
        res = DGGS_TYPES["gars"]["default_res"]
    res = validate_gars_resolution(res)
    # Convert res to minutes: 1->30, 2->15, 3->5, 4->1
    minutes_map = {1: 30, 2: 15, 3: 5, 4: 1}
    minutes = minutes_map[res]
    gars_cell = GARSGrid.from_latlon(lat, lon, minutes)
    return str(gars_cell)

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
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
def latlon2digipin(lat, lon, res=None):
    """
    Convert latitude and longitude to DIGIPIN code.

    Args:
        lat (float): Latitude in decimal degrees (must be between 2.5 and 38.5)
        lon (float): Longitude in decimal degrees (must be between 63.5 and 99.5)
        res (int): DIGIPIN resolution [1-15] (number of characters in the code)

    Returns:
        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'.
    """
    if res is None:
        res = DGGS_TYPES["digipin"]["default_res"]
    res = validate_digipin_resolution(res)
    digipin_id = latlon_to_digipin(lat, lon, res)
    return digipin_id