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

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

latlon2a5_cli()

Command-line interface for latlon2a5.

Source code in vgrid/conversion/latlon2dggs.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
def latlon2a5_cli():
    """
    Command-line interface for latlon2a5.
    """
    min_res = DGGS_TYPES["a5"]["min_res"]
    max_res = DGGS_TYPES["a5"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to A5 code at a specific Resolution [0..29]. \
                                     Usage: latlon2a5 <lat> <lon> <res> [0..29]. \
                                     Ex: latlon2a5 10.775275567242561 106.70679737574993 15"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["a5"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon

    a5_hex = latlon2a5(lat, lon, res)
    print(a5_hex)

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
1150
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
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

latlon2dggal_cli()

Command-line interface for latlon2dggal.

Usage: latlon2dggal

Source code in vgrid/conversion/latlon2dggs.py
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
def latlon2dggal_cli():
    """
    Command-line interface for latlon2dggal.

    Usage: latlon2dggal <dggs_type> <lat> <lon> <res>
    """
    parser = argparse.ArgumentParser(
        description=(
            "Convert Lat, Long to DGGAL ZoneID via dgg CLI (zone). "
            "Usage: latlon2dggal <dggs_type> <lat> <lon> <res>. "
            "Ex: latlon2dggal gnosis 10.775275567242561 106.70679737574993 8"
        )
    )
    parser.add_argument(
        "dggs_type", type=str, choices=DGGAL_TYPES.keys(), help="DGGAL type"
    )

    dggs_type = args.dggs_type
    min_res = DGGAL_TYPES[f"{dggs_type}"]["min_res"]
    max_res = DGGAL_TYPES[f"{dggs_type}"]["max_res"]
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGAL_TYPES[f"{dggs_type}"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )

    args = parser.parse_args()

    # Default res=8
    zone_id = latlon2dggal(args.dggs_type, args.lat, args.lon, args.res)
    if zone_id is None:
        raise SystemExit(
            "Failed to compute DGGAL ZoneID. Ensure `dgg` is installed and on PATH."
        )
    print(zone_id)

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
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,
    )
    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

latlon2dggrid_cli()

Command-line interface for latlon2dggrid.

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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
def latlon2dggrid_cli():
    """
    Command-line interface for latlon2dggrid.
    """
    dggs_type = args.dggs_type
    min_res = DGGRID_TYPES[f"{dggs_type}"]["min_res"]
    max_res = DGGRID_TYPES[f"{dggs_type}"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to DGGRID cell at a specific Resolution. \
                                     Usage: latlon2dggrid <lat> <lon> <dggs_type> <res>. \
                                     Ex: latlon2dggrid  10.775275567242561 106.70679737574993 ISEA7H 13"
    )
    parser.add_argument(
        "dggs_type",
        choices=DGGRID_TYPES.keys(),
        help="Select a DGGS type from the available options.",
    )

    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGRID_TYPES[f"{dggs_type}"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    parser.add_argument(
        "output_address_type",
        choices=output_address_types,
        default="SEQNUM",
        nargs="?",  # This makes the argument optional
        help="Select an output address type from the available options.",
    )
    args = parser.parse_args()
    dggs_type = args.dggs_type
    res = args.res
    output_address_type = args.output_address_type
    dggrid_instance = create_dggrid_instance()
    dggrid_cell_id = latlon2dggrid(
        dggrid_instance, dggs_type, args.lat, args.lon, res, output_address_type
    )
    print(dggrid_cell_id)

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
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
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

latlon2digipin_cli()

Command-line interface for latlon2digipin.

Source code in vgrid/conversion/latlon2dggs.py
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
def latlon2digipin_cli():
    """
    Command-line interface for latlon2digipin.
    """
    min_res = DGGS_TYPES["digipin"]["min_res"]
    max_res = DGGS_TYPES["digipin"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to DIGIPIN code at a specific resolution [1..10]. \
                                     Usage: latlon2digipin <lat> <lon> <res> [1..10]. \
                                     Ex: latlon2digipin 17.414718, 78.482992 10"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["digipin"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    digipin_id = latlon2digipin(lat, lon, res)
    print(digipin_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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
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

latlon2ease_cli()

Command-line interface for latlon2isea3h.

Source code in vgrid/conversion/latlon2dggs.py
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
def latlon2ease_cli():
    """
    Command-line interface for latlon2isea3h.
    """
    min_res = DGGS_TYPES["ease"]["min_res"]
    max_res = DGGS_TYPES["ease"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to EASE-DGGS cell at a specific Resolution [0..6]. \
                                     Usage: latlon2ease <lat> <lon> <res> [0..6]. \
                                            Ex: latlon2ease 10.775275567242561 106.70679737574993 3"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["ease"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon

    ease_id = latlon2ease(lat, lon, res)
    print(ease_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
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
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)

latlon2gars_cli()

Command-line interface for latlon2gars.

Source code in vgrid/conversion/latlon2dggs.py
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
def latlon2gars_cli():
    """
    Command-line interface for latlon2gars.
    """
    min_res = DGGS_TYPES["gars"]["min_res"]
    max_res = DGGS_TYPES["gars"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to GARS code at a specific resolution [1..4]. \
                                     Usage: latlon2gars <lat> <lon> <res> [1..4]. \
                                     Ex: latlon2gars 10.775275567242561 106.70679737574993 2"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["gars"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}] (1=30min, 2=15min, 3=5min, 4=1min)",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    gars_id = latlon2gars(lat, lon, res)
    print(gars_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

latlon2geohash_cli()

Command-line interface for latlon2geohash.

Source code in vgrid/conversion/latlon2dggs.py
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
def latlon2geohash_cli():
    """
    Command-line interface for latlon2geohash.
    """
    min_res = DGGS_TYPES["geohash"]["min_res"]
    max_res = DGGS_TYPES["geohash"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to Geohash code at a specific resolution [1..10]. \
                                    Usage: latlon2geohash <lat> <lon> <res>[1..10]. \
                                    Ex: latlon2geohash 10.775275567242561 106.70679737574993 6"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["geohash"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    geohash_id = latlon2geohash(lat, lon, res)
    print(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 = str(georef.encode(lat, lon, res))
    return georef_id

latlon2georef_cli()

Command-line interface for latlon2georef.

Source code in vgrid/conversion/latlon2dggs.py
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
def latlon2georef_cli():
    """
    Command-line interface for latlon2georef.
    """
    min_res = DGGS_TYPES["georef"]["min_res"]
    max_res = DGGS_TYPES["georef"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to GEOREF code at a specific resolution [0..10]. \
                                     Usage: latlon2georef <lat> <lon> <res> [0..10]. \
                                    Ex: latlon2georef 10.775275567242561 106.70679737574993 5"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["georef"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    georef_id = latlon2georef(lat, lon, res)
    print(georef_id)

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
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

latlon2h3_cli()

Command-line interface for latlon2h3.

Source code in vgrid/conversion/latlon2dggs.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def latlon2h3_cli():
    """
    Command-line interface for latlon2h3.
    """
    min_res = DGGS_TYPES["h3"]["min_res"]
    max_res = DGGS_TYPES["h3"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to H3 code at a specific Resolution [{min_res}..{max_res}]. \
                                    Usage: latlon2h3 <lat> <lon> <res> [{min_res}..{max_res}]. \
                                    Ex: latlon2h3 10.775275567242561 106.70679737574993 13"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["h3"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    h3_id = latlon2h3(lat, lon, res)
    print(h3_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())

latlon2isea3h_cli()

Command-line interface for latlon2isea3h.

Source code in vgrid/conversion/latlon2dggs.py
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
def latlon2isea3h_cli():
    """
    Command-line interface for latlon2isea3h.
    """
    min_res = DGGS_TYPES["isea3h"]["min_res"]
    max_res = DGGS_TYPES["isea3h"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to OpenEaggr ISEA3H code at a specific Resolution [0..40]. \
                                     Usage: latlon2isea3h <lat> <lon> <res> [0..40]. \
                                     Ex: latlon2isea3h 10.775275567242561 106.70679737574993 27"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["isea3h"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    if platform.system() == "Windows":
        isea3h_id = latlon2isea3h(lat, lon, res)
        print(isea3h_id)
    else:
        print("ISEA3H is only supported on Windows systems")

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

latlon2isea4t_cli()

Command-line interface for latlon2isea4t.

Source code in vgrid/conversion/latlon2dggs.py
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
def latlon2isea4t_cli():
    """
    Command-line interface for latlon2isea4t.
    """
    min_res = DGGS_TYPES["isea4t"]["min_res"]
    max_res = DGGS_TYPES["isea4t"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to OpenEaggr ISEA4T code at a specific Resolution [0..39]. \
                                     Usage: latlon2isea4t <lat> <lon> <res> [0..39]. \
                                     Ex: latlon2isea4t 10.775275567242561 106.70679737574993 20"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["isea4t"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    if platform.system() == "Windows":
        isea4t_id = latlon2isea4t(lat, lon, res)
        print(isea4t_id)
    else:
        print("ISEA4T is only supported on Windows systems")

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
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
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

latlon2maidenhead_cli()

Command-line interface for latlon2maidenhead.

Source code in vgrid/conversion/latlon2dggs.py
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
def latlon2maidenhead_cli():
    """
    Command-line interface for latlon2maidenhead.
    """
    min_res = DGGS_TYPES["maidenhead"]["min_res"]
    max_res = DGGS_TYPES["maidenhead"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to Tile code at a specific resolution [1..4]. \
                                    Usage: latlon2maidenhead <lat> <lon> <res> [1..4]. \
                                    Ex: latlon2maidenhead 10.775275567242561 106.70679737574993 2"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["maidenhead"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    maidenhead_id = latlon2maidenhead(lat, lon, res)
    print(maidenhead_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
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
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

latlon2mgrs_cli()

Command-line interface for latlon2mgrs.

Source code in vgrid/conversion/latlon2dggs.py
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
def latlon2mgrs_cli():
    """
    Command-line interface for latlon2mgrs.
    """
    min_res = DGGS_TYPES["mgrs"]["min_res"]
    max_res = DGGS_TYPES["mgrs"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to GEOREF code at a specific resolution [0..5]. \
                                     Usage: latlon2mgrs <lat> <lon> <res> [0..5]. \
                                     Ex: latlon2mgrs 10.775275567242561 106.70679737574993 3"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["mgrs"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution  [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    mgrs_id = latlon2mgrs(lat, lon, res)
    print(mgrs_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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
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

latlon2olc_cli()

Command-line interface for latlon2olc.

Source code in vgrid/conversion/latlon2dggs.py
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
def latlon2olc_cli():
    """
    Command-line interface for latlon2olc.
    """
    min_res = DGGS_TYPES["olc"]["min_res"]
    max_res = DGGS_TYPES["olc"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to OLC/ Google Plus Code at a specific Code length [10..15]. \
                                     Usage: latlon2olc <lat> <lon> <res> [2,4,6,8,10..15]. \
                                     Ex: latlon2olc 10.775275567242561 106.70679737574993 12"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["olc"]["default_res"],
        choices=range(min_res, max_res + 1),
        help="Resolution of the OLC DGGS (choose from 2, 4, 6, 8, 10, 11, 12, 13, 14, 15)",
    )

    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon

    olc_id = latlon2olc(lat, lon, res)
    print(olc_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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
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

latlon2qtm_cli()

Command-line interface for latlon2qtm.

Source code in vgrid/conversion/latlon2dggs.py
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
def latlon2qtm_cli():
    """
    Command-line interface for latlon2qtm.
    """
    min_res = DGGS_TYPES["qtm"]["min_res"]
    max_res = DGGS_TYPES["qtm"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to QTM. \
                                     Usage: latlon2qtm <lat> <lon> <res> [1..24]. \
                                     Ex: latlon2qtm 10.775275567242561 106.70679737574993 12"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["qtm"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon

    qtm_id = latlon2qtm(lat, lon, res)
    print(qtm_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
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
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

latlon2quadkey_cli()

Command-line interface for latlon2tilecode.

Source code in vgrid/conversion/latlon2dggs.py
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
def latlon2quadkey_cli():
    """
    Command-line interface for latlon2tilecode.
    """
    min_res = DGGS_TYPES["quadkey"]["min_res"]
    max_res = DGGS_TYPES["quadkey"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to Quadkey at a specific resolution/ zoom level [0..29]. \
                                     Usage: latlon2quadkey <lat> <lon> <res> [0..29]. \
                                     Ex: latlon2quadkey 10.775275567242561 106.70679737574993 15"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["quadkey"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution/ Zoom level [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    quadkey_id = latlon2quadkey(lat, lon, res)
    print(quadkey_id)

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

latlon2rhealpix_cli()

Command-line interface for latlon2rhealpix.

Source code in vgrid/conversion/latlon2dggs.py
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
def latlon2rhealpix_cli():
    """
    Command-line interface for latlon2rhealpix.
    """
    min_res = DGGS_TYPES["rhealpix"]["min_res"]
    max_res = DGGS_TYPES["rhealpix"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to Rhealpix code at a specific Resolution [0..15]. \
                                     Usage: latlon2rhealpix <lat> <lon> <res> [0..15]. \
                                     Ex: latlon2rhealpix 10.775275567242561 106.70679737574993 {DGGS_TYPES['rhealpix']['default_res']}"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["rhealpix"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon

    rhealpix_id = latlon2rhealpix(lat, lon, res)
    print(rhealpix_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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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_id = s2.CellId.from_lat_lng(lat_lng)  # return S2 cell at max level 30
    s2_id = s2_id.parent(res)  # get S2 cell at resolution
    s2_token = s2.CellId.to_token(s2_id)  # get Cell ID Token, shorter than cell_id.id()
    return s2_token

latlon2s2_cli()

Command-line interface for latlon2s2.

Source code in vgrid/conversion/latlon2dggs.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def latlon2s2_cli():
    """
    Command-line interface for latlon2s2.
    """
    min_res = DGGS_TYPES["s2"]["min_res"]
    max_res = DGGS_TYPES["s2"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to S2 code at a specific Resolution [0..30]. \
                                     Usage: latlon2s2 <lat> <lon> <res> [0..30]. \
                                     Ex: latlon2s2 10.775275567242561 106.70679737574993 21"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["s2"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution [{min_res}..{max_res}]",
    )
    args = parser.parse_args()
    res = args.res
    lat = args.lat
    lon = args.lon
    s2_token = latlon2s2(lat, lon, res)
    print(s2_token)

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
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
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

latlon2tilecode_cli()

Command-line interface for latlon2tilecode.

Source code in vgrid/conversion/latlon2dggs.py
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
def latlon2tilecode_cli():
    """
    Command-line interface for latlon2tilecode.
    """
    min_res = DGGS_TYPES["tilecode"]["min_res"]
    max_res = DGGS_TYPES["tilecode"]["max_res"]
    parser = argparse.ArgumentParser(
        description="Convert Lat, Long to Tile code at a specific resolution/ zoom level [0..29]. \
                                    Usage: latlon2tilecode <lat> <lon> <res> [0..29]. \
                                    Ex: latlon2tilecode 10.775275567242561 106.70679737574993 15"
    )
    parser.add_argument("lat", type=float, help="Input Latitude")
    parser.add_argument("lon", type=float, help="Input Longitude")
    parser.add_argument(
        "res",
        type=int,
        default=DGGS_TYPES["tilecode"]["default_res"],
        choices=range(min_res, max_res + 1),
        help=f"Input Resolution/ Zoom level [{min_res}..{max_res}]",
    )
    args = parser.parse_args()

    res = args.res
    lat = args.lat
    lon = args.lon
    tilecode_id = latlon2tilecode(lat, lon, res)
    print(tilecode_id)