-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
57 lines (43 loc) · 1.36 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
objects=zcta5 county place state
tiger_url=ftp://ftp2.census.gov/geo/tiger/TIGER2019
db_name=geo
zcta5: zcta5.geo.json
$(call importAndIndex,postalcodes,properties.GEOID10)
county: county.geo.json
$(call importAndIndex,counties,properties.NAME)
place: place.geo.json
$(call importAndIndex,places,properties.NAME)
state: state.geo.json
$(call importAndIndex,states,properties.NAME)
%.geo.json: %.zip
ogr2ogr -t_srs crs:84 -f "GeoJSON" /vsistdout/ /vsizip/$< | \
./data/pluck_features.js > [email protected]
mv [email protected] $@ && rm $<
%.zip: %.manifest
curl $(shell head -n 1 $<) -o [email protected]
mv [email protected] $@ && rm $<
%.manifest:
$(eval url := $(tiger_url)/$(shell echo $* | tr -s '[:lower:]' '[:upper:]')/)
curl -l $(url) | \
sort -nr | \
sed 's,^,$(url),' > $*.tmp
test -s ./$*.tmp && mv $*.tmp $@
image:
docker build -t gcr.io/boundariesio/api:$$(git rev-parse --short HEAD) .
push: image
gcloud docker push gcr.io/boundariesio/api:$$(git rev-parse --short HEAD)
clean:
# pass
define importAndIndex
mongo localhost/$(db_name) --eval "JSON.stringify(db.$1.ensureIndex({geometry: '2dsphere'}))"
mongo localhost/$(db_name) --eval "JSON.stringify(db.$1.ensureIndex({'$2': 'text'}))"
mongoimport \
--upsert \
--upsertFields $2 \
--collection $1 \
--db $(db_name) \
< ./$<
endef
.PRECIOUS: %.zip %.geo.json
.INTERMEDIATE: %.tmp
.PHONY: clean $(objects) image