Created
October 14, 2020 12:43
-
-
Save MuddyBootsCode/bf359d6e3053b6d66272259be2f6860b to your computer and use it in GitHub Desktop.
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 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