]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - makefile
Added the D.C. blocks download/import.
[dead/census-tools.git] / makefile
1 DB_NAME=census
2 DB_USER=postgres
3 TIGER_SRID=4269
4
5 # Root folder for the shapefiles.
6 TIGER_ROOT=http://www2.census.gov/geo/tiger/TIGER2009
7
8 # State-specific folders.
9 DC_ROOT=$(TIGER_ROOT)/11_DISTRICT_OF_COLUMBIA
10 MD_ROOT=$(TIGER_ROOT)/24_MARYLAND
11 VA_ROOT=$(TIGER_ROOT)/51_VIRGINIA
12 PA_ROOT=$(TIGER_ROOT)/42_PENNSYLVANIA
13 NY_ROOT=$(TIGER_ROOT)/36_NEW_YORK
14
15 # URLs for the TIGER/Line block-level shapefiles.
16 DC_BLOCKS_URL=$(DC_ROOT)/tl_2009_11_tabblock00.zip
17 MD_BLOCKS_URL=$(MD_ROOT)/tl_2009_24_tabblock00.zip
18 VA_BLOCKS_URL=$(VA_ROOT)/tl_2009_51_tabblock00.zip
19 PA_BLOCKS_URL=$(PA_ROOT)/tl_2009_42_tabblock00.zip
20 NY_BLOCKS_URL=$(NY_ROOT)/tl_2009_36_tabblock00.zip
21
22 # URLs for the DC county all-lines shapefiles.
23 # D.C. just has one Census county.
24 DC_LINES_URL=$(DC_ROOT)/11001_District_of_Columbia/tl_2009_11001_edges.zip
25
26 # This is where it gets ugly.
27 #
28 # URLs for the MD county all-lines shapefiles.
29 ALLEGANY_LINES_URL=$(MD_ROOT)/24001_Allegany_County/tl_2009_24001_edges.zip
30 ANNE_ARUNDEL_LINES_URL=$(MD_ROOT)/24003_Anne_Arundel_County/tl_2009_24003_edges.zip
31 BALTIMORE_CO_LINES_URL=$(MD_ROOT)/24005_Baltimore_County/tl_2009_24005_edges.zip
32 BALTIMORE_CI_LINES_URL=$(MD_ROOT)/24510_Baltimore_city/tl_2009_24510_edges.zip
33 CALVERT_LINES_URL=$(MD_ROOT)/24009_Calvert_County/tl_2009_24009_edges.zip
34 CAROLINE_LINES_URL=$(MD_ROOT)/24011_Caroline_County/tl_2009_24011_edges.zip
35 CARROLL_LINES_URL=$(MD_ROOT)/24013_Carroll_County/tl_2009_24013_edges.zip
36 CECIL_LINES_URL=$(MD_ROOT)/24015_Cecil_County/tl_2009_24015_edges.zip
37 CHARLES_LINES_URL=$(MD_ROOT)/24017_Charles_County/tl_2009_24017_edges.zip
38 DORCHESTER_LINES_URL=$(MD_ROOT)/24019_Dorchester_County/tl_2009_24019_edges.zip
39 FREDERICK_LINES_URL=$(MD_ROOT)/24021_Frederick_County/tl_2009_24021_edges.zip
40 GARRETT_LINES_URL=$(MD_ROOT)/24023_Garrett_County/tl_2009_24023_edges.zip
41 HARFORD_LINES_URL=$(MD_ROOT)/24025_Harford_County/tl_2009_24025_edges.zip
42 HOWARD_LINES_URL=$(MD_ROOT)/24027_Howard_County/tl_2009_24027_edges.zip
43 KENT_LINES_URL=$(MD_ROOT)/24029_Kent_County/tl_2009_24029_edges.zip
44 MONTGOMERY_LINES_URL=$(MD_ROOT)/24031_Montgomery_County/tl_2009_24031_edges.zip
45 PRINCE_GEORGES_LINES_URL=$(MD_ROOT)/24033_Prince_Georges_County/tl_2009_24033_edges.zip
46 QUEEN_ANNES_LINES_URL=$(MD_ROOT)/24035_Queen_Annes_County/tl_2009_24035_edges.zip
47 ST_MARYS_LINES_URL=$(MD_ROOT)/24037_St_Marys_County/tl_2009_24037_edges.zip
48 SOMERSET_LINES_URL=$(MD_ROOT)/24039_Somerset_County/tl_2009_24039_edges.zip
49 TALBOT_LINES_URL=$(MD_ROOT)/24041_Talbot_County/tl_2009_24041_edges.zip
50 WASHINGTON_LINES_URL=$(MD_ROOT)/24043_Washington_County/tl_2009_24043_edges.zip
51 WICOMICO_LINES_URL=$(MD_ROOT)/24045_Wicomico_County/tl_2009_24045_edges.zip
52 WORCESTER_LINES_URL=$(MD_ROOT)/24047_Worcester_County/tl_2009_24047_edges.zip
53
54
55 # Starting with PostGIS 1.4.0, these paths are calculated at install
56 # time using the pg_config utility. Rather than try to guess where
57 # PostGIS will wind up installed, we can just check the output of
58 # pg_config ourselves.
59 PG_BINDIR=`pg_config --bindir`
60 PG_SHAREDIR=`pg_config --sharedir`
61
62 # Necessary to run test/data without prerequisites.
63 #
64 .PHONY : test data
65
66
67 # The default task, since it comes first in the list.
68 #
69 all: clean test
70
71
72 test:
73 ./bin/run_tests
74
75
76 # Remove byte-compiled python code.
77 #
78 clean:
79 find ./ -name '*.pyc' -print0 | xargs -0 rm -f
80
81
82 # Download the shapefiles from Tiger if they don't already exist.
83 # For now, we're only dealing with the Census 2000 Maryland Block
84 # data, so the filenames are hard-coded. Easy enough to change.
85 #
86 data: tiger_blocks tiger_lines
87
88 tiger_blocks: dc_blocks md_blocks va_blocks pa_blocks ny_blocks
89
90 dc_blocks:
91 mkdir -p data/census2000/dc/block
92 if [ ! -f data/census2000/dc/block/tl_2009_11_tabblock00.shp ]; \
93 then \
94 wget -O dcblocks.zip $(DC_BLOCKS_URL); \
95 unzip dcblocks.zip -d ./data/census2000/dc/block; \
96 rm dcblocks.zip; \
97 fi;
98
99 md_blocks:
100 mkdir -p data/census2000/maryland/block
101 if [ ! -f data/census2000/maryland/block/tl_2009_24_tabblock00.shp ]; \
102 then \
103 wget -O mdblocks.zip $(MD_BLOCKS_URL); \
104 unzip mdblocks.zip -d ./data/census2000/maryland/block; \
105 rm mdblocks.zip; \
106 fi;
107
108 va_blocks:
109 mkdir -p data/census2000/virginia/block
110 if [ ! -f data/census2000/virginia/block/tl_2009_51_tabblock00.shp ]; \
111 then \
112 wget -O vablocks.zip $(VA_BLOCKS_URL); \
113 unzip vablocks.zip -d ./data/census2000/virginia/block; \
114 rm vablocks.zip; \
115 fi;
116
117 pa_blocks:
118 mkdir -p data/census2000/pennsylvania/block
119 if [ ! -f data/census2000/pennsylvania/block/tl_2009_42_tabblock00.shp ]; \
120 then \
121 wget -O pablocks.zip $(PA_BLOCKS_URL); \
122 unzip pablocks.zip -d ./data/census2000/pennsylvania/block; \
123 rm pablocks.zip; \
124 fi;
125
126 ny_blocks:
127 mkdir -p data/census2000/new_york/block
128 if [ ! -f data/census2000/new_york/block/tl_2009_36_tabblock00.shp ]; \
129 then \
130 wget -O nyblocks.zip $(NY_BLOCKS_URL); \
131 unzip nyblocks.zip -d ./data/census2000/new_york/block; \
132 rm nyblocks.zip; \
133 fi;
134
135
136 tiger_lines: dc_lines
137
138 dc_lines:
139 mkdir -p data/census2000/dc/lines
140 if [ ! -f data/census2000/dc/lines/tl_2009_11001_edges.shp ]; \
141 then \
142 wget -O dclines.zip $(DC_LINES_URL); \
143 unzip dclines.zip -d ./data/census2000/dc/lines; \
144 rm dclines.zip; \
145 fi;
146
147 # This task does a couple of things. First, it drops and re-creates
148 # the DB_NAME database (or schema, whatever). Then, it adds PL/pgSQL
149 # support to the database.
150 #
151 # At that point, we import the two PostGIS files, postgis.sql and
152 # spatial_ref_sys.sql. The postgis.sql file contains the geometry
153 # functions, while spatial_ref_sys.sql contains a table of SRIDs, and
154 # their associated properties. PostGIS requires both.
155 #
156 # Then, we import the Tiger data using shp2pgsql. The shapefiles
157 # should exist, since this task depends on the "data" task, which
158 # downloads said shapefiles.
159 #
160 # Finally, we create the table for the demographic data (obtained from
161 # the geographic header records), and populate that table with the output
162 # of the sf1blocks2sql script.
163 #
164 db: data
165 # Ignore the result of dropdb when it fails.
166 dropdb -U $(DB_USER) $(DB_NAME) || true
167 createdb -U $(DB_USER) $(DB_NAME)
168 createlang -U $(DB_USER) plpgsql $(DB_NAME)
169
170 psql -d $(DB_NAME) \
171 -U $(DB_USER) \
172 -f $(PG_SHAREDIR)/contrib/postgis.sql
173
174 psql -d $(DB_NAME) \
175 -U $(DB_USER) \
176 -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql
177
178 # D.C. Blocks
179
180 $(PG_BINDIR)/shp2pgsql \
181 -I \
182 -s $(TIGER_SRID) \
183 -D \
184 data/census2000/dc/block/tl_2009_11_tabblock00.shp \
185 tiger_blocks \
186 | psql -U $(DB_USER) -d $(DB_NAME)
187
188 # Maryland Blocks
189
190 $(PG_BINDIR)/shp2pgsql \
191 -I \
192 -s $(TIGER_SRID) \
193 -D \
194 data/census2000/maryland/block/tl_2009_24_tabblock00.shp \
195 tiger_blocks \
196 | psql -U $(DB_USER) -d $(DB_NAME)
197
198
199 # Virginia Blocks
200
201 $(PG_BINDIR)/shp2pgsql -a \
202 -I \
203 -s $(TIGER_SRID) \
204 -D \
205 data/census2000/virginia/block/tl_2009_51_tabblock00.shp \
206 tiger_blocks \
207 | psql -U $(DB_USER) -d $(DB_NAME)
208
209
210 # Pennsylvania Blocks
211
212 $(PG_BINDIR)/shp2pgsql -a \
213 -I \
214 -s $(TIGER_SRID) \
215 -D \
216 data/census2000/pennsylvania/block/tl_2009_42_tabblock00.shp \
217 tiger_blocks \
218 | psql -U $(DB_USER) -d $(DB_NAME)
219
220
221 # New York Blocks
222
223 $(PG_BINDIR)/shp2pgsql -a \
224 -I \
225 -s $(TIGER_SRID) \
226 -D \
227 data/census2000/new_york/block/tl_2009_36_tabblock00.shp \
228 tiger_blocks \
229 | psql -U $(DB_USER) -d $(DB_NAME)
230
231
232 psql -d $(DB_NAME) \
233 -U $(DB_USER) \
234 -f sql/create-sf1_blocks-table.sql
235
236 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
237 | psql -U postgres -d $(DB_NAME) > /dev/null
238