Skip to content

Instantly share code, notes, and snippets.

@mapmeld
Created January 2, 2020 15:52
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 mapmeld/ec5b8805ec929f031273947aa66c30ea to your computer and use it in GitHub Desktop.
Save mapmeld/ec5b8805ec929f031273947aa66c30ea to your computer and use it in GitHub Desktop.
State-specific maps of Native American Communities
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