]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - makefile
Renamed the "tiger" table to "tiger_blocks" in preparation for the addition of the...
[dead/census-tools.git] / makefile
1 DB_NAME='census'
2 DB_USER='postgres'
3 TIGER_DATA_URL='http://www2.census.gov/geo/tiger/TIGER2009/24_MARYLAND/tl_2009_24_tabblock00.zip'
4 TIGER_SRID='4269'
5
6 # Starting with PostGIS 1.4.0, these paths are calculated at install
7 # time using the pg_config utility. Rather than try to guess where
8 # PostGIS will wind up installed, we can just check the output of
9 # pg_config ourselves.
10 PG_BINDIR=`pg_config --bindir`
11 PG_SHAREDIR=`pg_config --sharedir`
12
13 # Necessary to run test/data without prerequisites.
14 #
15 .PHONY : test data
16
17
18 # The default task, since it comes first in the list.
19 #
20 all: clean test
21
22
23 test:
24 ./bin/run_tests
25
26
27 # Remove byte-compiled python code.
28 #
29 clean:
30 find ./ -name '*.pyc' -print0 | xargs -0 rm -f
31
32
33 # Download the shapefiles from Tiger if they don't already exist.
34 # For now, we're only dealing with the Census 2000 Maryland Block
35 # data, so the filenames are hard-coded. Easy enough to change.
36 #
37 data:
38 mkdir -p data/census2000/maryland/block
39 if [ ! -f data/census2000/maryland/block/tl_2009_24_tabblock00.shp ]; then \
40 wget -O tmp.zip $(TIGER_DATA_URL); \
41 unzip tmp.zip -d ./data/census2000/maryland/block; \
42 rm tmp.zip; \
43 fi;
44
45
46 # This task does a couple of things. First, it drops and re-creates
47 # the DB_NAME database (or schema, whatever). Then, it adds PL/pgSQL
48 # support to the database.
49 #
50 # At that point, we import the two PostGIS files, postgis.sql and
51 # spatial_ref_sys.sql. The postgis.sql file contains the geometry
52 # functions, while spatial_ref_sys.sql contains a table of SRIDs, and
53 # their associated properties. PostGIS requires both.
54 #
55 # Then, we import the Tiger data using shp2pgsql. The shapefiles
56 # should exist, since this task depends on the "data" task, which
57 # downloads said shapefiles.
58 #
59 # Finally, we create the table for the demographic data (obtained from
60 # the geographic header records), and populate that table with the output
61 # of the sf1blocks2sql script.
62 #
63 db: data
64 # Ignore the result of dropdb when it fails.
65 dropdb -U $(DB_USER) $(DB_NAME) || true
66 createdb -U $(DB_USER) $(DB_NAME)
67 createlang -U $(DB_USER) plpgsql $(DB_NAME)
68
69 psql -d $(DB_NAME) \
70 -U $(DB_USER) \
71 -f $(PG_SHAREDIR)/contrib/postgis.sql
72
73 psql -d $(DB_NAME) \
74 -U $(DB_USER) \
75 -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql
76
77 $(PG_BINDIR)/shp2pgsql -I \
78 -s $(TIGER_SRID) \
79 data/census2000/maryland/block/tl_2009_24_tabblock00.shp \
80 tiger_blocks \
81 | psql -U $(DB_USER) -d $(DB_NAME)
82
83 psql -d $(DB_NAME) \
84 -U $(DB_USER) \
85 -f sql/create-sf1_blocks-table.sql
86
87 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
88 | psql -U postgres -d $(DB_NAME)
89