5 # Root folder for the shapefiles.
6 TIGER_ROOT=http://www2.census.gov/geo/tiger/TIGER2009
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
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
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
26 # This is where it gets ugly.
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
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`
62 # Necessary to run test/data without prerequisites.
67 # The default task, since it comes first in the list.
76 # Remove byte-compiled python code.
79 find ./ -name '*.pyc' -print0 | xargs -0 rm -f
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.
86 data: tiger_blocks tiger_lines
88 tiger_blocks: dc_blocks md_blocks va_blocks pa_blocks ny_blocks
91 mkdir -p data/census2000/dc/block
92 if [ ! -f data/census2000/dc/block/tl_2009_11_tabblock00.shp ]; \
94 wget -O dcblocks.zip $(DC_BLOCKS_URL); \
95 unzip dcblocks.zip -d ./data/census2000/dc/block; \
100 mkdir -p data/census2000/maryland/block
101 if [ ! -f data/census2000/maryland/block/tl_2009_24_tabblock00.shp ]; \
103 wget -O mdblocks.zip $(MD_BLOCKS_URL); \
104 unzip mdblocks.zip -d ./data/census2000/maryland/block; \
109 mkdir -p data/census2000/virginia/block
110 if [ ! -f data/census2000/virginia/block/tl_2009_51_tabblock00.shp ]; \
112 wget -O vablocks.zip $(VA_BLOCKS_URL); \
113 unzip vablocks.zip -d ./data/census2000/virginia/block; \
118 mkdir -p data/census2000/pennsylvania/block
119 if [ ! -f data/census2000/pennsylvania/block/tl_2009_42_tabblock00.shp ]; \
121 wget -O pablocks.zip $(PA_BLOCKS_URL); \
122 unzip pablocks.zip -d ./data/census2000/pennsylvania/block; \
127 mkdir -p data/census2000/new_york/block
128 if [ ! -f data/census2000/new_york/block/tl_2009_36_tabblock00.shp ]; \
130 wget -O nyblocks.zip $(NY_BLOCKS_URL); \
131 unzip nyblocks.zip -d ./data/census2000/new_york/block; \
136 tiger_lines: dc_lines md_lines
139 mkdir -p data/census2000/dc/lines
140 if [ ! -f data/census2000/dc/lines/tl_2009_11001_edges.shp ]; \
142 wget -O dclines.zip $(DC_LINES_URL); \
143 unzip dclines.zip -d ./data/census2000/dc/lines; \
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
150 mkdir -p data/census2000/maryland/lines
151 if [ ! -f data/census2000/maryland/lines/tl_2009_24001_edges.shp ]; \
153 wget -O alleganylines.zip $(ALLEGANY_LINES_URL); \
154 unzip alleganylines.zip -d ./data/census2000/maryland/lines; \
155 rm alleganylines.zip; \
159 mkdir -p data/census2000/maryland/lines
160 if [ ! -f data/census2000/maryland/lines/tl_2009_24003_edges.shp ]; \
162 wget -O aalines.zip $(ANNE_ARUNDEL_LINES_URL); \
163 unzip aalines.zip -d ./data/census2000/maryland/lines; \
168 mkdir -p data/census2000/maryland/lines
169 if [ ! -f data/census2000/maryland/lines/tl_2009_24005_edges.shp ]; \
171 wget -O bcolines.zip $(BALTIMORE_CO_LINES_URL); \
172 unzip bcolines.zip -d ./data/census2000/maryland/lines; \
177 mkdir -p data/census2000/maryland/lines
178 if [ ! -f data/census2000/maryland/lines/tl_2009_24510_edges.shp ]; \
180 wget -O bcilines.zip $(BALTIMORE_CI_LINES_URL); \
181 unzip bcilines.zip -d ./data/census2000/maryland/lines; \
186 mkdir -p data/census2000/maryland/lines
187 if [ ! -f data/census2000/maryland/lines/tl_2009_24009_edges.shp ]; \
189 wget -O calvertlines.zip $(CALVERT_LINES_URL); \
190 unzip calvertlines.zip -d ./data/census2000/maryland/lines; \
191 rm calvertlines.zip; \
195 mkdir -p data/census2000/maryland/lines
196 if [ ! -f data/census2000/maryland/lines/tl_2009_24011_edges.shp ]; \
198 wget -O carolinelines.zip $(CAROLINE_LINES_URL); \
199 unzip carolinelines.zip -d ./data/census2000/maryland/lines; \
200 rm carolinelines.zip; \
204 mkdir -p data/census2000/maryland/lines
205 if [ ! -f data/census2000/maryland/lines/tl_2009_24013_edges.shp ]; \
207 wget -O carrolllines.zip $(CARROLL_LINES_URL); \
208 unzip carrolllines.zip -d ./data/census2000/maryland/lines; \
209 rm carrolllines.zip; \
213 mkdir -p data/census2000/maryland/lines
214 if [ ! -f data/census2000/maryland/lines/tl_2009_24015_edges.shp ]; \
216 wget -O cecillines.zip $(CECIL_LINES_URL); \
217 unzip cecillines.zip -d ./data/census2000/maryland/lines; \
222 mkdir -p data/census2000/maryland/lines
223 if [ ! -f data/census2000/maryland/lines/tl_2009_24017_edges.shp ]; \
225 wget -O charleslines.zip $(CHARLES_LINES_URL); \
226 unzip charleslines.zip -d ./data/census2000/maryland/lines; \
227 rm charleslines.zip; \
231 mkdir -p data/census2000/maryland/lines
232 if [ ! -f data/census2000/maryland/lines/tl_2009_24019_edges.shp ]; \
234 wget -O dorchesterlines.zip $(DORCHESTER_LINES_URL); \
235 unzip dorchesterlines.zip -d ./data/census2000/maryland/lines; \
236 rm dorchesterlines.zip; \
240 mkdir -p data/census2000/maryland/lines
241 if [ ! -f data/census2000/maryland/lines/tl_2009_24021_edges.shp ]; \
243 wget -O fredericklines.zip $(FREDERICK_LINES_URL); \
244 unzip fredericklines.zip -d ./data/census2000/maryland/lines; \
245 rm fredericklines.zip; \
249 mkdir -p data/census2000/maryland/lines
250 if [ ! -f data/census2000/maryland/lines/tl_2009_24023_edges.shp ]; \
252 wget -O garrettlines.zip $(GARRETT_LINES_URL); \
253 unzip garrettlines.zip -d ./data/census2000/maryland/lines; \
254 rm garrettlines.zip; \
258 mkdir -p data/census2000/maryland/lines
259 if [ ! -f data/census2000/maryland/lines/tl_2009_24025_edges.shp ]; \
261 wget -O harfordlines.zip $(HARFORD_LINES_URL); \
262 unzip harfordlines.zip -d ./data/census2000/maryland/lines; \
263 rm harfordlines.zip; \
267 mkdir -p data/census2000/maryland/lines
268 if [ ! -f data/census2000/maryland/lines/tl_2009_24027_edges.shp ]; \
270 wget -O howardlines.zip $(HOWARD_LINES_URL); \
271 unzip howardlines.zip -d ./data/census2000/maryland/lines; \
272 rm howardlines.zip; \
276 mkdir -p data/census2000/maryland/lines
277 if [ ! -f data/census2000/maryland/lines/tl_2009_24029_edges.shp ]; \
279 wget -O kentlines.zip $(KENT_LINES_URL); \
280 unzip kentlines.zip -d ./data/census2000/maryland/lines; \
285 mkdir -p data/census2000/maryland/lines
286 if [ ! -f data/census2000/maryland/lines/tl_2009_24031_edges.shp ]; \
288 wget -O montgomerylines.zip $(MONTGOMERY_LINES_URL); \
289 unzip montgomerylines.zip -d ./data/census2000/maryland/lines; \
290 rm montgomerylines.zip; \
293 prince_georges_lines:
294 mkdir -p data/census2000/maryland/lines
295 if [ ! -f data/census2000/maryland/lines/tl_2009_24033_edges.shp ]; \
297 wget -O pglines.zip $(PRINCE_GEORGES_LINES_URL); \
298 unzip pglines.zip -d ./data/census2000/maryland/lines; \
303 mkdir -p data/census2000/maryland/lines
304 if [ ! -f data/census2000/maryland/lines/tl_2009_24035_edges.shp ]; \
306 wget -O qalines.zip $(QUEEN_ANNES_LINES_URL); \
307 unzip qalines.zip -d ./data/census2000/maryland/lines; \
312 mkdir -p data/census2000/maryland/lines
313 if [ ! -f data/census2000/maryland/lines/tl_2009_24037_edges.shp ]; \
315 wget -O smlines.zip $(ST_MARYS_LINES_URL); \
316 unzip smlines.zip -d ./data/census2000/maryland/lines; \
321 mkdir -p data/census2000/maryland/lines
322 if [ ! -f data/census2000/maryland/lines/tl_2009_24039_edges.shp ]; \
324 wget -O somersetlines.zip $(SOMERSET_LINES_URL); \
325 unzip somersetlines.zip -d ./data/census2000/maryland/lines; \
326 rm somersetlines.zip; \
330 mkdir -p data/census2000/maryland/lines
331 if [ ! -f data/census2000/maryland/lines/tl_2009_24041_edges.shp ]; \
333 wget -O talbotlines.zip $(TALBOT_LINES_URL); \
334 unzip talbotlines.zip -d ./data/census2000/maryland/lines; \
335 rm talbotlines.zip; \
339 mkdir -p data/census2000/maryland/lines
340 if [ ! -f data/census2000/maryland/lines/tl_2009_24043_edges.shp ]; \
342 wget -O washingtonlines.zip $(WASHINGTON_LINES_URL); \
343 unzip washingtonlines.zip -d ./data/census2000/maryland/lines; \
344 rm washingtonlines.zip; \
348 mkdir -p data/census2000/maryland/lines
349 if [ ! -f data/census2000/maryland/lines/tl_2009_24045_edges.shp ]; \
351 wget -O wicomicolines.zip $(WICOMICO_LINES_URL); \
352 unzip wicomicolines.zip -d ./data/census2000/maryland/lines; \
353 rm wicomicolines.zip; \
357 mkdir -p data/census2000/maryland/lines
358 if [ ! -f data/census2000/maryland/lines/tl_2009_24047_edges.shp ]; \
360 wget -O worcesterlines.zip $(WORCESTER_LINES_URL); \
361 unzip worcesterlines.zip -d ./data/census2000/maryland/lines; \
362 rm worcesterlines.zip; \
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.
370 # After the TIGER import is done, we use the sf1blocks2sql script to
371 # parse and import the geographic header record information.
373 db: data newdb tiger_blocks_table tiger_lines_table sf1_blocks_table
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 \
383 $$state/block/*.shp \
385 | psql -U $(DB_USER) -d $(DB_NAME); \
390 # Since the table and index already exist, we can utilize -a,
392 for x in data/census2000/maryland/lines/*.shp; do \
393 $(PG_BINDIR)/shp2pgsql \
399 | psql -U $(DB_USER) -d $(DB_NAME); \
402 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
403 | psql -U postgres -d $(DB_NAME) \
408 # First, we drop and re-create the DB_NAME database (or schema,
409 # whatever). Then, we add PL/pgSQL support to the database.
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.
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)
424 -f $(PG_SHAREDIR)/contrib/postgis.sql \
429 -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql \
433 # This just runs the SQL script to create the sf1_blocks table.
437 -f sql/create-sf1_blocks-table.sql \
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.
445 $(PG_BINDIR)/shp2pgsql \
449 data/census2000/maryland/block/tl_2009_24_tabblock00.shp \
451 | psql -U postgres -d $(DB_NAME) \
455 # Prepare the tiger_lines table, and create the GiST index on its
456 # geometry column. Any lines shapefile will do here.
458 $(PG_BINDIR)/shp2pgsql \
462 data/census2000/maryland/lines/tl_2009_24510_edges.shp \
464 | psql -U postgres -d $(DB_NAME) \