Created
January 2, 2020 15:52
-
-
Save mapmeld/ec5b8805ec929f031273947aa66c30ea to your computer and use it in GitHub Desktop.
State-specific maps of Native American Communities
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
from sys import argv | |
import json | |
# pip install fiona shapely shapely-geojson | |
import fiona | |
from shapely.geometry import shape | |
from shapely_geojson import dumps | |
if len(argv) < 2: | |
print('usage: gen_map.py "New Mexico" > output.geojson') | |
quit() | |
target_state = argv[1] | |
states = [] | |
for pol in fiona.open('tl_2019_us_state/tl_2019_us_state.shp'): | |
name = pol['properties']['NAME'] | |
if name == target_state: | |
states.append(shape(pol['geometry'])) | |
features = { | |
"type": "FeatureCollection", | |
"features": [] | |
} | |
for pol in fiona.open('tl_2019_us_aiannh/tl_2019_us_aiannh.shp'): | |
geo = shape(pol['geometry']) | |
for state in states: | |
if geo.intersects(state): | |
features["features"].append({ | |
"geometry": json.loads(dumps(geo)), | |
"properties": pol['properties'] | |
}) | |
break | |
print(json.dumps(features, separators=(',', ':'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment