https://github.com/space-physics/maidenhead
Python Maidenhead <--> WGS84 coordinate conversions
https://github.com/space-physics/maidenhead
amateur-radio geolocation maidenhead
Last synced: 3 months ago
JSON representation
Python Maidenhead <--> WGS84 coordinate conversions
- Host: GitHub
- URL: https://github.com/space-physics/maidenhead
- Owner: space-physics
- License: mit
- Created: 2018-05-08T19:06:16.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2025-05-25T06:27:22.000Z (about 1 year ago)
- Last Synced: 2025-09-28T12:22:16.413Z (8 months ago)
- Topics: amateur-radio, geolocation, maidenhead
- Language: Python
- Homepage:
- Size: 108 KB
- Stars: 24
- Watchers: 3
- Forks: 13
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Maidenhead <-> Lat/Lon
[](https://zenodo.org/badge/latestdoi/132653071)
[](https://github.com/space-physics/maidenhead/actions/workflows/ci.yml)
[](https://pypi.python.org/pypi/maidenhead)
[](http://pepy.tech/project/maidenhead)
`maidenhead` provides a simple, yet effective location hashing algorithm.
Maidenhead allows global location precision down to 750m
Maidenhead provides 4 levels of increasing accuracy
Level | Precision
--------|------------
1 | World
2 | Regional
3 | Metropolis
4 | City
5 | Street
6 | 1m precision
```sh
pip install maidenhead
```
or for development version
```sh
git clone https://github.com/space-physics/maidenhead
pip install -e maidenhead
```
Examples assume first doing
```python
import maidenhead as mh
```
Lat, lon to Maidenhead locator:
```python
mh.to_maiden(lat, lon, level)
```
returns a char (len = lvl*2)
Maidenhead locator to lat lon:
```python
mh.to_location('AB01cd')
```
takes Maidenhead location string and returns top-left lat, lon of Maidenhead grid square.
The `center=True` option outputs lat lon of the center of provided maidenhead grid square, instead of the default southwest corner.
Maidenhead locator to [geoJSON](https://geojson.org/) ([RFC 7946](https://tools.ietf.org/html/rfc7946))
```python
geo_obj = mh.to_geoJSONObject('AB01cd', center=True, nosquare=False)
geoJSON = json.dumps(geo_obj, indent=2)
```
## Command Line
The command line interface takes either decimal degrees for "latitude longitude" or the Maidenhead locator string:
```sh
python -m maidenhead 65.0 -148.0
```
> BP65aa
```sh
python -m maidenhead BP65aa12
```
> 65.0083 -147.9917
The "python -m" CLI is also available:
```sh
python -m maidenhead 65.0 -148.0
```
The `--center` option outputs lat lon of the center of provided maidenhead grid square, instead of the default southwest corner.
```sh
python -m maidenhead --center --geojson EN35ld
```
> {"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"QTHLocator_Centerpoint": "EN35ld"}, "geometry": {"type": "Point", "coordinates": [-93.04166666666667, 45.145833333333336]}}, {"type": "Feature", "properties": {"QTHLocator": "EN35ld"}, "geometry": {"type": "Polygon", "coordinates": [[[-93.08333333333333, 45.125], [-93.08333333333333, 45.166666666666664], [-93.0, 45.166666666666664], [-93.0, 45.125], [-93.08333333333333, 45.125]]]}}]}
The `--center` option enables adding center point of the grid square as Point feature.
The `--nosquare` option disables adding Polygon feature for the requested grid square
## Alternatives
Open Location Codes a.k.a Plus Codes are in
[Python code by Google](https://github.com/google/open-location-code/tree/master/python).
Web convertor [Earth Point - Tools for Google Earth](https://www.earthpoint.us/Convert.aspx).