]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - makefile
Merged the documentation additions and most recent makefile modification (branch...
[dead/census-tools.git] / makefile
1 DB_NAME='census'
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 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/census-2000-block/maryland/
39 if [ ! -f data/census-2000-block/maryland/tl_2008_24_tabblock00.shp ]; then \
40 wget -O tiger.zip $(TIGER_DATA_URL); \
41 unzip tiger.zip; \
42 rm tiger.zip; \
43 unzip srv/ftp/geo/tiger/TIGER2008/24_MARYLAND/tl_2008_24_tabblock00.zip \
44 -d ./data/census-2000-block/maryland/; \
45 rm -rf srv; \
46 fi;
47
48
49 # This task does a couple of things. First, it drops and re-creates
50 # the DB_NAME database (or schema, whatever). Then, it adds PL/pgSQL
51 # support to the database.
52 #
53 # At that point, we import the two PostGIS files, postgis.sql and
54 # spatial_ref_sys.sql. The postgis.sql file contains the geometry
55 # functions, while spatial_ref_sys.sql contains a table of SRIDs, and
56 # their associated properties. PostGIS requires both.
57 #
58 # Then, we import the Tiger data using shp2pgsql. The shapefiles
59 # should exist, since this task depends on the "data" task, which
60 # downloads said shapefiles.
61 #
62 # Finally, we create the table for the demographic data (obtained from
63 # the geographic header records), and populate that table with the output
64 # of the sf1blocks2sql script.
65 #
66 db: data
67 # Ignore the result of dropdb when it fails.
68 dropdb -U $(DB_USER) $(DB_NAME) || true
69 createdb -U $(DB_USER) $(DB_NAME)
70 createlang -U $(DB_USER) plpgsql $(DB_NAME)
71
72 psql -d $(DB_NAME) \
73 -U $(DB_USER) \
74 -f $(PG_SHAREDIR)/contrib/postgis.sql
75
76 psql -d $(DB_NAME) \
77 -U $(DB_USER) \
78 -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql
79
80 $(PG_BINDIR)/shp2pgsql -I \
81 -s $(TIGER_SRID) \
82 data/census-2000-block/maryland/tl_2008_24_tabblock00.shp \
83 tiger \
84 | psql -U $(DB_USER) -d $(DB_NAME)
85
86 psql -d $(DB_NAME) \
87 -U $(DB_USER) \
88 -f sql/create-sf1_blocks-table.sql
89
90 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
91 | psql -U postgres -d $(DB_NAME)
92