]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - makefile
Updated the makefile to import TIGER block data for MD, VA, PA, and NY.
[dead/census-tools.git] / makefile
1 DB_NAME=census
2 DB_USER=postgres
3 TIGER_SRID=4269
4
5 # URLs for the TIGER/Line block-level shapefiles.
6 TIGER_ROOT=http://www2.census.gov/geo/tiger/TIGER2009
7 MD_BLOCKS_URL=$(TIGER_ROOT)/24_MARYLAND/tl_2009_24_tabblock00.zip
8 VA_BLOCKS_URL=$(TIGER_ROOT)/51_VIRGINIA/tl_2009_51_tabblock00.zip
9 PA_BLOCKS_URL=$(TIGER_ROOT)/42_PENNSYLVANIA/tl_2009_42_tabblock00.zip
10 NY_BLOCKS_URL=$(TIGER_ROOT)/36_NEW_YORK/tl_2009_36_tabblock00.zip
11
12 # Starting with PostGIS 1.4.0, these paths are calculated at install
13 # time using the pg_config utility. Rather than try to guess where
14 # PostGIS will wind up installed, we can just check the output of
15 # pg_config ourselves.
16 PG_BINDIR=`pg_config --bindir`
17 PG_SHAREDIR=`pg_config --sharedir`
18
19 # Necessary to run test/data without prerequisites.
20 #
21 .PHONY : test data
22
23
24 # The default task, since it comes first in the list.
25 #
26 all: clean test
27
28
29 test:
30 ./bin/run_tests
31
32
33 # Remove byte-compiled python code.
34 #
35 clean:
36 find ./ -name '*.pyc' -print0 | xargs -0 rm -f
37
38
39 # Download the shapefiles from Tiger if they don't already exist.
40 # For now, we're only dealing with the Census 2000 Maryland Block
41 # data, so the filenames are hard-coded. Easy enough to change.
42 #
43 data: tiger_blocks
44
45 tiger_blocks: md_blocks va_blocks pa_blocks ny_blocks
46
47 md_blocks:
48 mkdir -p data/census2000/maryland/block
49 if [ ! -f data/census2000/maryland/block/tl_2009_24_tabblock00.shp ]; \
50 then \
51 wget -O mdblocks.zip $(MD_BLOCKS_URL); \
52 unzip mdblocks.zip -d ./data/census2000/maryland/block; \
53 rm mdblocks.zip; \
54 fi;
55
56 va_blocks:
57 mkdir -p data/census2000/virginia/block
58 if [ ! -f data/census2000/virginia/block/tl_2009_51_tabblock00.shp ]; \
59 then \
60 wget -O vablocks.zip $(VA_BLOCKS_URL); \
61 unzip vablocks.zip -d ./data/census2000/virginia/block; \
62 rm vablocks.zip; \
63 fi;
64
65 pa_blocks:
66 mkdir -p data/census2000/pennsylvania/block
67 if [ ! -f data/census2000/pennsylvania/block/tl_2009_42_tabblock00.shp ]; \
68 then \
69 wget -O pablocks.zip $(PA_BLOCKS_URL); \
70 unzip pablocks.zip -d ./data/census2000/pennsylvania/block; \
71 rm pablocks.zip; \
72 fi;
73
74 ny_blocks:
75 mkdir -p data/census2000/new_york/block
76 if [ ! -f data/census2000/new_york/block/tl_2009_36_tabblock00.shp ]; \
77 then \
78 wget -O nyblocks.zip $(NY_BLOCKS_URL); \
79 unzip nyblocks.zip -d ./data/census2000/new_york/block; \
80 rm nyblocks.zip; \
81 fi;
82
83
84 # This task does a couple of things. First, it drops and re-creates
85 # the DB_NAME database (or schema, whatever). Then, it adds PL/pgSQL
86 # support to the database.
87 #
88 # At that point, we import the two PostGIS files, postgis.sql and
89 # spatial_ref_sys.sql. The postgis.sql file contains the geometry
90 # functions, while spatial_ref_sys.sql contains a table of SRIDs, and
91 # their associated properties. PostGIS requires both.
92 #
93 # Then, we import the Tiger data using shp2pgsql. The shapefiles
94 # should exist, since this task depends on the "data" task, which
95 # downloads said shapefiles.
96 #
97 # Finally, we create the table for the demographic data (obtained from
98 # the geographic header records), and populate that table with the output
99 # of the sf1blocks2sql script.
100 #
101 db: data
102 # Ignore the result of dropdb when it fails.
103 dropdb -U $(DB_USER) $(DB_NAME) || true
104 createdb -U $(DB_USER) $(DB_NAME)
105 createlang -U $(DB_USER) plpgsql $(DB_NAME)
106
107 psql -d $(DB_NAME) \
108 -U $(DB_USER) \
109 -f $(PG_SHAREDIR)/contrib/postgis.sql
110
111 psql -d $(DB_NAME) \
112 -U $(DB_USER) \
113 -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql
114
115
116 # Maryland Blocks
117
118 $(PG_BINDIR)/shp2pgsql \
119 -I \
120 -s $(TIGER_SRID) \
121 -D \
122 data/census2000/maryland/block/tl_2009_24_tabblock00.shp \
123 tiger_blocks \
124 | psql -U $(DB_USER) -d $(DB_NAME)
125
126
127 # Virginia Blocks
128
129 $(PG_BINDIR)/shp2pgsql -a \
130 -I \
131 -s $(TIGER_SRID) \
132 -D \
133 data/census2000/virginia/block/tl_2009_51_tabblock00.shp \
134 tiger_blocks \
135 | psql -U $(DB_USER) -d $(DB_NAME)
136
137
138 # Pennsylvania Blocks
139
140 $(PG_BINDIR)/shp2pgsql -a \
141 -I \
142 -s $(TIGER_SRID) \
143 -D \
144 data/census2000/pennsylvania/block/tl_2009_42_tabblock00.shp \
145 tiger_blocks \
146 | psql -U $(DB_USER) -d $(DB_NAME)
147
148
149 # New York Blocks
150
151 $(PG_BINDIR)/shp2pgsql -a \
152 -I \
153 -s $(TIGER_SRID) \
154 -D \
155 data/census2000/new_york/block/tl_2009_36_tabblock00.shp \
156 tiger_blocks \
157 | psql -U $(DB_USER) -d $(DB_NAME)
158
159
160 psql -d $(DB_NAME) \
161 -U $(DB_USER) \
162 -f sql/create-sf1_blocks-table.sql
163
164 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
165 | psql -U postgres -d $(DB_NAME) > /dev/null
166