]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - makefile
Modified the Data module and download script to download the Summary File 1 data.
[dead/census-tools.git] / makefile
1 DB_NAME=census
2 DB_USER=postgres
3 TIGER_SRID=4269
4 SHAPELY_URL=http://pypi.python.org/packages/source/S/Shapely/Shapely-1.0.14.tar.gz
5
6
7 # Starting with PostGIS 1.4.0, these paths are calculated at install
8 # time using the pg_config utility. Rather than try to guess where
9 # PostGIS will wind up installed, we can just check the output of
10 # pg_config ourselves.
11 PG_BINDIR=`pg_config --bindir`
12 PG_SHAREDIR=`pg_config --sharedir`
13
14 # Necessary to run test/data without prerequisites.
15 #
16 .PHONY : test data lib
17
18
19 # The default task, since it comes first in the list.
20 #
21 all: clean lib test
22
23
24 test:
25 ./bin/run_tests
26
27
28 # Download or check out any third-party libraries.
29 lib:
30 if [ ! -d lib/Shapely ]; then \
31 wget -O shapely.tar.gz $(SHAPELY_URL); \
32 tar -xvzf shapely.tar.gz -C lib/ ; \
33 rm shapely.tar.gz; \
34 mv lib/Shapely* lib/Shapely; \
35 fi;
36
37
38 # Remove byte-compiled python code.
39 #
40 clean:
41 find ./ -name '*.pyc' -print0 | xargs -0 rm -f
42
43
44 data:
45 bin/download_data
46
47
48 # This imports the Tiger data using shp2pgsql. The shapefiles
49 # should exist, since this task depends on the "data" task, which
50 # downloads said shapefiles.
51 #
52 # After the TIGER import is done, we use the sf1blocks2sql script to
53 # parse and import the geographic header record information.
54 #
55 db: data newdb tiger_blocks_table tiger_lines_table sf1_blocks_table
56 # All Blocks
57 #
58 # The table already exists, so we can append to it, and we don't have
59 # to create the GiST index.
60 for state in data/census2000/*; do \
61 $(PG_BINDIR)/shp2pgsql \
62 -a \
63 -s $(TIGER_SRID) \
64 -D \
65 $$state/blocks/*.shp \
66 tiger_blocks \
67 | psql -U $(DB_USER) -d $(DB_NAME); \
68 done;
69
70 # All Lines
71 #
72 # Since the table and index already exist, we can utilize -a,
73 # and leave -I out.
74 for state in data/census2000/*; do \
75 for shapefile in $$state/lines/*.shp; do \
76 echo "Importing $$shapefile."; \
77 $(PG_BINDIR)/shp2pgsql \
78 -a \
79 -s $(TIGER_SRID) \
80 $$shapefile \
81 tiger_lines \
82 | bin/filter-transactions \
83 | psql -U $(DB_USER) -d $(DB_NAME) \
84 > /dev/null; \
85 done; \
86 done;
87
88 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
89 | psql -U postgres -d $(DB_NAME) \
90 > /dev/null
91
92
93
94 # First, we drop and re-create the DB_NAME database (or schema,
95 # whatever). Then, we add PL/pgSQL support to the database.
96 #
97 # At that point, we import the two PostGIS files, postgis.sql and
98 # spatial_ref_sys.sql. The postgis.sql file contains the geometry
99 # functions, while spatial_ref_sys.sql contains a table of SRIDs, and
100 # their associated properties. PostGIS requires both.
101 #
102 newdb:
103 # Ignore the result of dropdb when it fails.
104 dropdb -U $(DB_USER) $(DB_NAME) || true
105 createdb -U $(DB_USER) $(DB_NAME)
106 createlang -U $(DB_USER) plpgsql $(DB_NAME)
107
108 psql -d $(DB_NAME) \
109 -U $(DB_USER) \
110 -f $(PG_SHAREDIR)/contrib/postgis.sql \
111 > /dev/null
112
113 psql -d $(DB_NAME) \
114 -U $(DB_USER) \
115 -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql \
116 > /dev/null
117
118
119 # This just runs the SQL script to create the sf1_blocks table.
120 sf1_blocks_table:
121 psql -d $(DB_NAME) \
122 -U $(DB_USER) \
123 -f sql/create-sf1_blocks-table.sql \
124 > /dev/null
125
126
127 # Create the tiger_blocks table, and create its GiST index. Having the
128 # table already exist makes importing via shp2pgsql much easier.
129 # Any blocks file will work as an argument.
130 tiger_blocks_table:
131 $(PG_BINDIR)/shp2pgsql \
132 -p \
133 -I \
134 -s $(TIGER_SRID) \
135 data/census2000/maryland/blocks/tl_2009_24_tabblock00.shp \
136 tiger_blocks \
137 | psql -U postgres -d $(DB_NAME) \
138 > /dev/null
139
140
141 # Prepare the tiger_lines table, and create the GiST index on its
142 # geometry column. Any lines shapefile will do here.
143 tiger_lines_table:
144 $(PG_BINDIR)/shp2pgsql \
145 -p \
146 -I \
147 -s $(TIGER_SRID) \
148 data/census2000/maryland/lines/tl_2009_24510_edges.shp \
149 tiger_lines \
150 | psql -U postgres -d $(DB_NAME) \
151 > /dev/null
152
153 # Add a unique index on the "tlid" column.
154 psql -U postgres \
155 -d census \
156 -f sql/create_tlid_unique_index.sql