]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - makefile
Added the MD lines import to the makefile.
[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 md_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 md_lines: allegany_lines anne_arundel_lines baltimore_co_lines baltimore_ci_lines calvert_lines caroline_lines carroll_lines cecil_lines charles_lines dorchester_lines frederick_lines garrett_lines harford_lines howard_lines kent_lines montgomery_lines prince_georges_lines queen_annes_lines st_marys_lines somerset_lines talbot_lines washington_lines wicomico_lines worcester_lines
148
149 allegany_lines:
150 mkdir -p data/census2000/maryland/lines
151 if [ ! -f data/census2000/maryland/lines/tl_2009_24001_edges.shp ]; \
152 then \
153 wget -O alleganylines.zip $(ALLEGANY_LINES_URL); \
154 unzip alleganylines.zip -d ./data/census2000/maryland/lines; \
155 rm alleganylines.zip; \
156 fi;
157
158 anne_arundel_lines:
159 mkdir -p data/census2000/maryland/lines
160 if [ ! -f data/census2000/maryland/lines/tl_2009_24003_edges.shp ]; \
161 then \
162 wget -O aalines.zip $(ANNE_ARUNDEL_LINES_URL); \
163 unzip aalines.zip -d ./data/census2000/maryland/lines; \
164 rm aalines.zip; \
165 fi;
166
167 baltimore_co_lines:
168 mkdir -p data/census2000/maryland/lines
169 if [ ! -f data/census2000/maryland/lines/tl_2009_24005_edges.shp ]; \
170 then \
171 wget -O bcolines.zip $(BALTIMORE_CO_LINES_URL); \
172 unzip bcolines.zip -d ./data/census2000/maryland/lines; \
173 rm bcolines.zip; \
174 fi;
175
176 baltimore_ci_lines:
177 mkdir -p data/census2000/maryland/lines
178 if [ ! -f data/census2000/maryland/lines/tl_2009_24510_edges.shp ]; \
179 then \
180 wget -O bcilines.zip $(BALTIMORE_CI_LINES_URL); \
181 unzip bcilines.zip -d ./data/census2000/maryland/lines; \
182 rm bcilines.zip; \
183 fi;
184
185 calvert_lines:
186 mkdir -p data/census2000/maryland/lines
187 if [ ! -f data/census2000/maryland/lines/tl_2009_24009_edges.shp ]; \
188 then \
189 wget -O calvertlines.zip $(CALVERT_LINES_URL); \
190 unzip calvertlines.zip -d ./data/census2000/maryland/lines; \
191 rm calvertlines.zip; \
192 fi;
193
194 caroline_lines:
195 mkdir -p data/census2000/maryland/lines
196 if [ ! -f data/census2000/maryland/lines/tl_2009_24011_edges.shp ]; \
197 then \
198 wget -O carolinelines.zip $(CAROLINE_LINES_URL); \
199 unzip carolinelines.zip -d ./data/census2000/maryland/lines; \
200 rm carolinelines.zip; \
201 fi;
202
203 carroll_lines:
204 mkdir -p data/census2000/maryland/lines
205 if [ ! -f data/census2000/maryland/lines/tl_2009_24013_edges.shp ]; \
206 then \
207 wget -O carrolllines.zip $(CARROLL_LINES_URL); \
208 unzip carrolllines.zip -d ./data/census2000/maryland/lines; \
209 rm carrolllines.zip; \
210 fi;
211
212 cecil_lines:
213 mkdir -p data/census2000/maryland/lines
214 if [ ! -f data/census2000/maryland/lines/tl_2009_24015_edges.shp ]; \
215 then \
216 wget -O cecillines.zip $(CECIL_LINES_URL); \
217 unzip cecillines.zip -d ./data/census2000/maryland/lines; \
218 rm cecillines.zip; \
219 fi;
220
221 charles_lines:
222 mkdir -p data/census2000/maryland/lines
223 if [ ! -f data/census2000/maryland/lines/tl_2009_24017_edges.shp ]; \
224 then \
225 wget -O charleslines.zip $(CHARLES_LINES_URL); \
226 unzip charleslines.zip -d ./data/census2000/maryland/lines; \
227 rm charleslines.zip; \
228 fi;
229
230 dorchester_lines:
231 mkdir -p data/census2000/maryland/lines
232 if [ ! -f data/census2000/maryland/lines/tl_2009_24019_edges.shp ]; \
233 then \
234 wget -O dorchesterlines.zip $(DORCHESTER_LINES_URL); \
235 unzip dorchesterlines.zip -d ./data/census2000/maryland/lines; \
236 rm dorchesterlines.zip; \
237 fi;
238
239 frederick_lines:
240 mkdir -p data/census2000/maryland/lines
241 if [ ! -f data/census2000/maryland/lines/tl_2009_24021_edges.shp ]; \
242 then \
243 wget -O fredericklines.zip $(FREDERICK_LINES_URL); \
244 unzip fredericklines.zip -d ./data/census2000/maryland/lines; \
245 rm fredericklines.zip; \
246 fi;
247
248 garrett_lines:
249 mkdir -p data/census2000/maryland/lines
250 if [ ! -f data/census2000/maryland/lines/tl_2009_24023_edges.shp ]; \
251 then \
252 wget -O garrettlines.zip $(GARRETT_LINES_URL); \
253 unzip garrettlines.zip -d ./data/census2000/maryland/lines; \
254 rm garrettlines.zip; \
255 fi;
256
257 harford_lines:
258 mkdir -p data/census2000/maryland/lines
259 if [ ! -f data/census2000/maryland/lines/tl_2009_24025_edges.shp ]; \
260 then \
261 wget -O harfordlines.zip $(HARFORD_LINES_URL); \
262 unzip harfordlines.zip -d ./data/census2000/maryland/lines; \
263 rm harfordlines.zip; \
264 fi;
265
266 howard_lines:
267 mkdir -p data/census2000/maryland/lines
268 if [ ! -f data/census2000/maryland/lines/tl_2009_24027_edges.shp ]; \
269 then \
270 wget -O howardlines.zip $(HOWARD_LINES_URL); \
271 unzip howardlines.zip -d ./data/census2000/maryland/lines; \
272 rm howardlines.zip; \
273 fi;
274
275 kent_lines:
276 mkdir -p data/census2000/maryland/lines
277 if [ ! -f data/census2000/maryland/lines/tl_2009_24029_edges.shp ]; \
278 then \
279 wget -O kentlines.zip $(KENT_LINES_URL); \
280 unzip kentlines.zip -d ./data/census2000/maryland/lines; \
281 rm kentlines.zip; \
282 fi;
283
284 montgomery_lines:
285 mkdir -p data/census2000/maryland/lines
286 if [ ! -f data/census2000/maryland/lines/tl_2009_24031_edges.shp ]; \
287 then \
288 wget -O montgomerylines.zip $(MONTGOMERY_LINES_URL); \
289 unzip montgomerylines.zip -d ./data/census2000/maryland/lines; \
290 rm montgomerylines.zip; \
291 fi;
292
293 prince_georges_lines:
294 mkdir -p data/census2000/maryland/lines
295 if [ ! -f data/census2000/maryland/lines/tl_2009_24033_edges.shp ]; \
296 then \
297 wget -O pglines.zip $(PRINCE_GEORGES_LINES_URL); \
298 unzip pglines.zip -d ./data/census2000/maryland/lines; \
299 rm pglines.zip; \
300 fi;
301
302 queen_annes_lines:
303 mkdir -p data/census2000/maryland/lines
304 if [ ! -f data/census2000/maryland/lines/tl_2009_24035_edges.shp ]; \
305 then \
306 wget -O qalines.zip $(QUEEN_ANNES_LINES_URL); \
307 unzip qalines.zip -d ./data/census2000/maryland/lines; \
308 rm qalines.zip; \
309 fi;
310
311 st_marys_lines:
312 mkdir -p data/census2000/maryland/lines
313 if [ ! -f data/census2000/maryland/lines/tl_2009_24037_edges.shp ]; \
314 then \
315 wget -O smlines.zip $(ST_MARYS_LINES_URL); \
316 unzip smlines.zip -d ./data/census2000/maryland/lines; \
317 rm smlines.zip; \
318 fi;
319
320 somerset_lines:
321 mkdir -p data/census2000/maryland/lines
322 if [ ! -f data/census2000/maryland/lines/tl_2009_24039_edges.shp ]; \
323 then \
324 wget -O somersetlines.zip $(SOMERSET_LINES_URL); \
325 unzip somersetlines.zip -d ./data/census2000/maryland/lines; \
326 rm somersetlines.zip; \
327 fi;
328
329 talbot_lines:
330 mkdir -p data/census2000/maryland/lines
331 if [ ! -f data/census2000/maryland/lines/tl_2009_24041_edges.shp ]; \
332 then \
333 wget -O talbotlines.zip $(TALBOT_LINES_URL); \
334 unzip talbotlines.zip -d ./data/census2000/maryland/lines; \
335 rm talbotlines.zip; \
336 fi;
337
338 washington_lines:
339 mkdir -p data/census2000/maryland/lines
340 if [ ! -f data/census2000/maryland/lines/tl_2009_24043_edges.shp ]; \
341 then \
342 wget -O washingtonlines.zip $(WASHINGTON_LINES_URL); \
343 unzip washingtonlines.zip -d ./data/census2000/maryland/lines; \
344 rm washingtonlines.zip; \
345 fi;
346
347 wicomico_lines:
348 mkdir -p data/census2000/maryland/lines
349 if [ ! -f data/census2000/maryland/lines/tl_2009_24045_edges.shp ]; \
350 then \
351 wget -O wicomicolines.zip $(WICOMICO_LINES_URL); \
352 unzip wicomicolines.zip -d ./data/census2000/maryland/lines; \
353 rm wicomicolines.zip; \
354 fi;
355
356 worcester_lines:
357 mkdir -p data/census2000/maryland/lines
358 if [ ! -f data/census2000/maryland/lines/tl_2009_24047_edges.shp ]; \
359 then \
360 wget -O worcesterlines.zip $(WORCESTER_LINES_URL); \
361 unzip worcesterlines.zip -d ./data/census2000/maryland/lines; \
362 rm worcesterlines.zip; \
363 fi;
364
365
366 # This imports the Tiger data using shp2pgsql. The shapefiles
367 # should exist, since this task depends on the "data" task, which
368 # downloads said shapefiles.
369 #
370 # After the TIGER import is done, we use the sf1blocks2sql script to
371 # parse and import the geographic header record information.
372 #
373 db: data newdb tiger_blocks_table tiger_lines_table sf1_blocks_table
374 # All Blocks
375 #
376 # The table already exists, so we can append to it, and we don't have
377 # to create the GiST index.
378 for state in data/census2000/*; do \
379 $(PG_BINDIR)/shp2pgsql \
380 -a \
381 -s $(TIGER_SRID) \
382 -D \
383 $$state/block/*.shp \
384 tiger_blocks \
385 | psql -U $(DB_USER) -d $(DB_NAME); \
386 done;
387
388 # MD Lines
389 #
390 # Since the table and index already exist, we can utilize -a,
391 # and leave -I out.
392 for x in data/census2000/maryland/lines/*.shp; do \
393 $(PG_BINDIR)/shp2pgsql \
394 -a \
395 -s $(TIGER_SRID) \
396 -D \
397 $$x \
398 tiger_lines \
399 | psql -U $(DB_USER) -d $(DB_NAME); \
400 done;
401
402 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
403 | psql -U postgres -d $(DB_NAME) \
404 > /dev/null
405
406
407
408 # First, we drop and re-create the DB_NAME database (or schema,
409 # whatever). Then, we add PL/pgSQL support to the database.
410 #
411 # At that point, we import the two PostGIS files, postgis.sql and
412 # spatial_ref_sys.sql. The postgis.sql file contains the geometry
413 # functions, while spatial_ref_sys.sql contains a table of SRIDs, and
414 # their associated properties. PostGIS requires both.
415 #
416 newdb:
417 # Ignore the result of dropdb when it fails.
418 dropdb -U $(DB_USER) $(DB_NAME) || true
419 createdb -U $(DB_USER) $(DB_NAME)
420 createlang -U $(DB_USER) plpgsql $(DB_NAME)
421
422 psql -d $(DB_NAME) \
423 -U $(DB_USER) \
424 -f $(PG_SHAREDIR)/contrib/postgis.sql \
425 > /dev/null
426
427 psql -d $(DB_NAME) \
428 -U $(DB_USER) \
429 -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql \
430 > /dev/null
431
432
433 # This just runs the SQL script to create the sf1_blocks table.
434 sf1_blocks_table:
435 psql -d $(DB_NAME) \
436 -U $(DB_USER) \
437 -f sql/create-sf1_blocks-table.sql \
438 > /dev/null
439
440
441 # Create the tiger_blocks table, and create its GiST index. Having the
442 # table already exist makes importing via shp2pgsql much easier.
443 # Any blocks file will work as an argument.
444 tiger_blocks_table:
445 $(PG_BINDIR)/shp2pgsql \
446 -p \
447 -I \
448 -s $(TIGER_SRID) \
449 data/census2000/maryland/block/tl_2009_24_tabblock00.shp \
450 tiger_blocks \
451 | psql -U postgres -d $(DB_NAME) \
452 > /dev/null
453
454
455 # Prepare the tiger_lines table, and create the GiST index on its
456 # geometry column. Any lines shapefile will do here.
457 tiger_lines_table:
458 $(PG_BINDIR)/shp2pgsql \
459 -p \
460 -I \
461 -s $(TIGER_SRID) \
462 data/census2000/maryland/lines/tl_2009_24510_edges.shp \
463 tiger_lines \
464 | psql -U postgres -d $(DB_NAME) \
465 > /dev/null