Exemplo n.º 1
0
def main(
    loc: str | tuple[float, float],
    precision: int = 3,
    url: bool = False,
    center: bool = False,
) -> str | tuple[float, float]:
    if isinstance(loc, str):  # maidenhead
        maiden = copy(loc)
        loc = maidenhead.to_location(loc, center)
        print(f"{loc[0]:.4f} {loc[1]:.4f}")
    elif len(loc) == 2:  # lat lon
        if isinstance(loc[0], str):
            loc = (float(loc), float(loc))
        maiden = maidenhead.to_maiden(*loc, precision=precision)
        print(maiden)
        loc = maiden
    else:
        raise ValueError("specify Maidenhead grid (single string) or lat lon (with space between)")

    if url:
        uri = maidenhead.google_maps(maiden, center)
        print(uri)
        return uri

    return loc
Exemplo n.º 2
0
def convert_maidenhead_to_latlon(
    maidenhead_coordinates: str, output_precision: int = 6
):
    """
    Convert latitude / longitude coordinates to Maidenhead coordinates

    Parameters
    ==========
    maidenhead_coordinates: 'str'
        Maidenhead coordinates for the given lat/lon with
        the specified precision
    output_precision: 'int'
        Output precision for the lat/lon values (rounding)

    Returns
    =======
    latitude : 'float'
        Latitude value
    longitude : 'float'
        Longitude value
    """
    assert len(maidenhead_coordinates) % 2 == 0

    latitude, longitude = maidenhead.to_location(maidenhead_coordinates)
    latitude: float = round(latitude, output_precision)
    longitude: float = round(longitude, output_precision)
    return latitude, longitude
Exemplo n.º 3
0
def main():
    my_location = maidenhead.to_location(QTHR)
    repeaters = get_uk_repeaters_dataframe()

    def distance_function(row):
        d = geopy.distance.distance(my_location, (row.lat, row.lon))
        return d.kilometers

    repeaters["distance"] = repeaters.apply(distance_function, axis=1)
    repeaters = repeaters.sort_values(by=["distance"])

    with get_repeaters_csv_output_path().open("w") as repeaters_file:
        repeaters.to_csv(repeaters_file, index=False, line_terminator="\n")
Exemplo n.º 4
0
def maidenhead_to_latlon(grid):
    grid = grid.strip()

    m = re.search(r'^([+-]?[0-9.]+?),([+-]?[0-9.]+)$', grid)
    if m:
        lat = float(m.group(1))
        lon = float(m.group(2))
        return lat, lon

    if len(grid) < 4:
        grid += "55"
    if len(grid) < 6:
        grid += "mm"
    if len(grid) < 8:
        grid += "55"

    lat, lon = maidenhead.to_location(grid)

    return lat, lon
Exemplo n.º 5
0
def main():
    p = argparse.ArgumentParser(description="convert to / from Maidenhead locator")
    p.add_argument(
        "loc", help="Maidenhead grid (single string) or lat lon (with space between)", nargs="+"
    )
    p.add_argument("-p", "--precision", help="maidenhead precision", type=int, default=3)
    p.add_argument("-u", "--url", help="also output Google Maps URL", action="store_true")
    args = p.parse_args()

    if len(args.loc) == 1:  # maidenhead
        maiden = args.loc[0]
        print('{:.4f} {:.4f}'.format(*maidenhead.to_location(maiden)))
    elif len(args.loc) == 2:  # lat lon
        maiden = maidenhead.to_maiden(*map(float, args.loc), precision=args.precision)
        print(maiden)
    else:
        raise SystemExit("specify Maidenhead grid (single string) or lat lon (with space between)")

    if args.url:
        print(maidenhead.google_maps(maiden))
Exemplo n.º 6
0
def main(loc: T.Union[str, T.Sequence[float]],
         precision: int = 3,
         url: bool = False):
    if isinstance(loc, str):  # maidenhead
        maiden = copy(loc)
        loc = maidenhead.to_location(loc)
        print(f"{loc[0]:.4f} {loc[1]:.4f}")
    elif len(loc) == 2:  # lat lon
        if isinstance(loc[0], str):
            loc = list(map(float, loc))
        maiden = maidenhead.to_maiden(*loc, precision=precision)
        print(maiden)
        loc = maiden
    else:
        raise ValueError(
            "specify Maidenhead grid (single string) or lat lon (with space between)"
        )

    if url:
        uri = maidenhead.google_maps(maiden)
        print(uri)
        return uri

    return loc
Exemplo n.º 7
0
def test_invalid_maiden_len():
    with pytest.raises(ValueError):
        maidenhead.to_location(maiden="GG52qjjjjj")
Exemplo n.º 8
0
def test_invalid_maiden(invalid):
    with pytest.raises(AttributeError):
        maidenhead.to_location(maiden=invalid)
Exemplo n.º 9
0
def test_maiden2latlon(location):
    lat, lon = maidenhead.to_location(location.maiden)
    assert lat == approx(location.latlon[0], rel=0.0001)
    assert lon == approx(location.latlon[1], rel=0.0001)
Exemplo n.º 10
0
print("4. Leave location unchanged\n")

choice = input("Enter your choice (1 - 4): ")

if (choice == '2'):

    regex = '[A-Za-z]+[A-Za-z]+[0-9]+[0-9]+[A-Za-z]+[A-Za-z]'

    for i in list(range(3)):

        grid = input(
            "\nEnter your 6 character character grid square (i.e. FM29ha): ")

        if re.search(regex, grid):
            print("grid is valid!")
            print(mh.to_location(grid)[0])
            print(mh.to_location(grid)[1])
            latitude = mh.to_location(grid)[0]
            longitude = mh.to_location(grid)[1]
            location = input(
                "\nEnter the name of your location (or hit Return to leave blank): "
            )
            break
        else:
            print("grid is not valid!")
            grid = ""

elif (choice == '3'):

    for i in list(range(3)):
        lat = input("\nType your latitude (South is negative): ")
Exemplo n.º 11
0
import sys
import maidenhead as mh
import re
import sys
def decdeg2dms(dd):
   is_positive = dd >= 0
   dd = abs(dd)
   minutes,seconds = divmod(dd*3600,60)
   degrees,minutes = divmod(minutes,60)
   degrees = degrees if is_positive else -degrees
   return (degrees,minutes,seconds)

#grid_square = 'cn97uk'
grid_square = str(sys.argv[1])
lat_lon = mh.to_location(grid_square)
#print(lat_lon)
#print(mh.to_location(str(grid_square)))


lat = decdeg2dms(mh.to_location(grid_square)[0])
lon = decdeg2dms(mh.to_location(grid_square)[1])

if lon[0] < 0:
    lon_dir = 'W'
if lon[0] > 0:
    lon_dir = 'E'
if lat[0] < 0:
    lat_dir = 'S'
if lat[0] > 0:
    lat_dir = 'N'