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
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 # 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.
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.
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.
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.
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)
172 -f $(PG_SHAREDIR)/contrib/postgis.sql
176 -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql
180 $(PG_BINDIR)/shp2pgsql \
184 data/census2000/dc/block/tl_2009_11_tabblock00.shp \
186 | psql -U $(DB_USER) -d $(DB_NAME)
190 $(PG_BINDIR)/shp2pgsql \
194 data/census2000/maryland/block/tl_2009_24_tabblock00.shp \
196 | psql -U $(DB_USER) -d $(DB_NAME)
201 $(PG_BINDIR)/shp2pgsql -a \
205 data/census2000/virginia/block/tl_2009_51_tabblock00.shp \
207 | psql -U $(DB_USER) -d $(DB_NAME)
210 # Pennsylvania Blocks
212 $(PG_BINDIR)/shp2pgsql -a \
216 data/census2000/pennsylvania/block/tl_2009_42_tabblock00.shp \
218 | psql -U $(DB_USER) -d $(DB_NAME)
223 $(PG_BINDIR)/shp2pgsql -a \
227 data/census2000/new_york/block/tl_2009_36_tabblock00.shp \
229 | psql -U $(DB_USER) -d $(DB_NAME)
234 -f sql/create-sf1_blocks-table.sql
236 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
237 | psql -U postgres -d $(DB_NAME) > /dev/null