A Python library for hashing common geospatial objects.
Install via PyPI with:
pip install geocryptOr install directly from GitHub with:
pip install git+git://github.com/spatialcurrent/geocrypt.git@mainBelow are some simple use cases. See test.py for more use cases.
from geocrypt import geocrypt
digest_a = geocrypt.hash({"type": "lonlat", "value": [-77.042999267578125, 38.922558058625356]})
# digest_a == "cc0a149fd1387a34412ee47cb08ab12b"
digest_b = geocrypt.hash({"geometry": {"coordinates": [-77.042999267578125, 38.922558058625356], "type": "Point"}, "id": 1, "properties": {"addr:street": "18th Street Northwest"}, "type": "Feature"})
# digest_b == "cc0a149fd1387a34412ee47cb08ab12b"
# digest_a == digest_bBy default, the md5 hash algorithm is used, but other algorithms can be selected, too.
geocrypt.hash({"type": "lonlat", "value": [-77.042999267578125, 38.922558058625356]}, algorithm="sha512")You can also round all coordinates to a given number of decimal places. 5 is a standard number to round to for online maps. By rounding to 5 decimal places, you mitigate floating point errors that might lead 2 different hashes for locations that are the same for all intents and purposes, such as [-77.042999267578125, 38.922558058625356] and [-77.042999299999, 38.922558099999].
geocrypt.hash({"type": "lonlat", "value": [-77.042999267578125, 38.922558058625356]}, decimals=5)For unit tests, run the following command from the project root folder:
python -m unittest -v geocrypt.testSpatial Current, Inc. is currently accepting pull requests for this repository. We'd love to have your contributions! Please see Contributing.rst for how to get started.
This work is distributed under the MIT License. See LICENSE file.