Last active
December 22, 2015 16:29
-
-
Save mittenchops/6499844 to your computer and use it in GitHub Desktop.
Load GeoJSON, posted here to for SO and mongoDB mailing list references
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, pymongo, shapefile, sys, ijson | |
from ijson import common | |
from ijson.backends import yajl | |
def floaten(event): | |
if event[1] == 'number': | |
return (event[0], event[1], float(event[2])) | |
else: | |
return event | |
# This does not actually work for some reason. | |
def loader(geojsonfile, collection): | |
with open(geojsonfile) as jf: | |
events = imap(floaten, yajl.parse(jf)) | |
i = 0 | |
for d in common.items(events, 'features'): | |
print('Loading record {}'.format(str(i))) | |
db[collection].insert(d) | |
time.sleep(1) | |
i = i + 1 | |
print("Upload of shapefile: {} into collection: {} successful".format(geojsonfile, collection)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment