Skip to content

Instantly share code, notes, and snippets.

@MuddyBootsCode
Created October 14, 2020 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MuddyBootsCode/bf359d6e3053b6d66272259be2f6860b to your computer and use it in GitHub Desktop.
Save MuddyBootsCode/bf359d6e3053b6d66272259be2f6860b to your computer and use it in GitHub Desktop.
import requests
import json
import geojson
from neo4j import GraphDatabase
def insert_geo(county_name, geo_data):
with driver.session() as session:
session.run(
'''
MATCH (c:County {name: $county_name})
set c.geometry = $geo_data
''', county_name=county_name, geo_data=geo_data)
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "docker-graph"))
r = requests.get('https://opendata.arcgis.com/datasets/9b2eb7d232584572ad53bad41c76b04d_0.geojson', stream=True)
print(r.status_code, ' Request Status')
if r.status_code == 200:
info = []
f = open('texas_counties.geojson', 'wb')
r.raw.decode_content = True
for chunk in r.iter_content(chunk_size=512 * 1024):
if chunk:
f.write(chunk)
f.close()
print('File Written')
with open('texas_counties.geojson') as f:
newGeo = geojson.load(f)
features = newGeo['features']
for r in features:
print(f'Inserting Geo Data for {r["properties"]["CNTY_NM"]}')
insert_geo(r['properties']['CNTY_NM'], json.dumps(r['geometry']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment