Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python3
# See:
# Processes output from:
import json
from geolib import geohash
# check the accuracy
# PostGIS check from
assert (geohash.encode(48, -126, 20) == 'c0w3hf1s70w3hf1s70w3')
# Google BigQuery check from
assert (geohash.encode(47.62, -122.35, 10) == 'c22yzugqw7')
with open('worldpopfull100k.geojson', 'r') as ifp:
with open('to_load.json', 'w') as ofp:
features = json.load(ifp)['features']
# new-line-separated JSON
schema = None
for obj in features:
props = obj['properties']
props['geometry'] = json.dumps({
'type': 'Polygon',
'coordinates': obj['geometry']['coordinates'][0]
(lon, lat) = props['point']
props['geohash'] = geohash.encode(lat, lon, 10)
del props['point']
print('Schema: ', schema)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment