]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - makefile
Added the framework for the PostGIS database integration.
[dead/census-tools.git] / makefile
1 DB_NAME='census2000'
2 DB_USER='postgres'
3 TIGER_DATA_URL='http://www2.census.gov/cgi-bin/shapefiles/multi-file-download?files=24_MARYLAND%2Ftl_2008_24_tabblock00.zip'
4
5
6 # Necessary to run test/data without prerequisites.
7 #
8 .PHONY : test data
9
10
11 # The default task, since it comes first in the list.
12 #
13 all: clean test
14
15
16 test:
17 ./bin/run_tests
18
19
20 # Remove byte-compiled python code.
21 #
22 clean:
23 find ./ -name '*.pyc' -print0 | xargs -0 rm -f
24
25
26 # Download the shapefiles from Tiger if they don't already exist.
27 # For now, we're only dealing with the Census 2000 Maryland Block
28 # data, so the filenames are hard-coded. Easy enough to change.
29 #
30 data:
31 mkdir -p data/census-2000-block/maryland/
32 if [ ! -f data/census-2000-block/maryland/tl_2008_24_tabblock00.shp ]; then \
33 wget -O tiger.zip $(TIGER_DATA_URL); \
34 unzip tiger.zip; \
35 rm tiger.zip; \
36 unzip srv/ftp/geo/tiger/TIGER2008/24_MARYLAND/tl_2008_24_tabblock00.zip \
37 -d ./data/census-2000-block/maryland/; \
38 rm -rf srv; \
39 fi;
40
41
42 # This task does a couple of things. First, it drops and re-creates
43 # the DB_NAME database (or schema, whatever). Then, it adds PL/pgSQL
44 # support to the database.
45 #
46 # At that point, we import the two PostGIS files, lwpostgis.sql and
47 # spatial_ref_sys.sql. These are magic as far as I'm concerned, but
48 # PostGIS requires them.
49 #
50 # Then, we import the Tiger data using shp2pgsql. The shapefiles
51 # should exist, since this task depends on the "data" task, which
52 # downloads said shapefiles.
53 #
54 # Finally, we create the table for the demographic data (obtained from
55 # the geographic header records), and populate that table with the output
56 # of the sf1blocks2sql script.
57 #
58 db: data
59 dropdb -U $(DB_USER) $(DB_NAME)
60 createdb -U $(DB_USER) $(DB_NAME)
61 createlang -U $(DB_USER) plpgsql $(DB_NAME)
62
63 psql -d $(DB_NAME) \
64 -U $(DB_USER) \
65 -f /usr/share/postgresql/contrib/lwpostgis.sql
66
67 psql -d $(DB_NAME) \
68 -U $(DB_USER) \
69 -f /usr/share/postgresql/contrib/spatial_ref_sys.sql
70
71 shp2pgsql -I data/census-2000-block/maryland/tl_2008_24_tabblock00.shp tiger \
72 | psql -U $(DB_USER) -d $(DB_NAME)
73
74 psql -d $(DB_NAME) \
75 -U $(DB_USER) \
76 -f sql/create-sf1_blocks-table.sql
77
78 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
79 | psql -U postgres -d $(DB_NAME)
80