Skip to content

Commit

Permalink
Merge pull request #256 from datamade/feature/jfc/import-geographies
Browse files Browse the repository at this point in the history
Import shapes with new management command
  • Loading branch information
jeancochrane authored Jun 27, 2019
2 parents 74ccc1f + bb33a1e commit 522342d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ There are tens of thousands of bills and hundreds of events in Chicago legislati
pupa update chicago bills window=0 && pupa update chicago events window=0
```

Finally, make sure to load shapes into the database so that Posts can be associated with their corresponding boundaries:

```bash
python manage.py import_shapes data/final/shapes/chicago_shapes.json
```

## Setup CSS, Images, and other static resources
```bash
python manage.py collectstatic
Expand Down
1 change: 1 addition & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
raw/shapes/*.json
12 changes: 12 additions & 0 deletions data/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BOUNDARIES_SOURCE := "https://data.cityofchicago.org/api/geospatial/sp34-6z76?method=export&format=GeoJSON"

.PHONY: all clean
all: final/shapes/chicago_shapes.json
clean:
rm -Rf final/shapes/chicago_shapes.json

raw/shapes/chicago_shapes.json:
curl $(BOUNDARIES_SOURCE) > $@

final/shapes/chicago_shapes.json: raw/shapes/chicago_shapes.json
cat $< | python3 scripts/transform_shapes.py > $@
1 change: 1 addition & 0 deletions data/final/shapes/chicago_shapes.json

Large diffs are not rendered by default.

Empty file added data/raw/shapes/.gitkeep
Empty file.
12 changes: 12 additions & 0 deletions data/scripts/transform_shapes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json
import sys

boundaries = json.load(sys.stdin)

for feature in boundaries['features']:
division_id = 'ocd-division/country:us/state:il/place:chicago/ward:{}'.format(
feature['properties']['ward']
)
feature['properties']['division_id'] = division_id

json.dump(boundaries, sys.stdout)

0 comments on commit 522342d

Please sign in to comment.