]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - makefile
Added the Configuration package with the Defaults module containing some default...
[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 # 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. The lwpostgis.sql file contains the geometry
48 # functions, while spatial_ref_sys.sql contains a table of SRIDs, and
49 # their associated properties. PostGIS requires both.
50 #
51 # Then, we import the Tiger data using shp2pgsql. The shapefiles
52 # should exist, since this task depends on the "data" task, which
53 # downloads said shapefiles.
54 #
55 # Finally, we create the table for the demographic data (obtained from
56 # the geographic header records), and populate that table with the output
57 # of the sf1blocks2sql script.
58 #
59 db: data
60 dropdb -U $(DB_USER) $(DB_NAME)
61 createdb -U $(DB_USER) $(DB_NAME)
62 createlang -U $(DB_USER) plpgsql $(DB_NAME)
63
64 psql -d $(DB_NAME) \
65 -U $(DB_USER) \
66 -f /usr/share/postgresql/contrib/lwpostgis.sql
67
68 psql -d $(DB_NAME) \
69 -U $(DB_USER) \
70 -f /usr/share/postgresql/contrib/spatial_ref_sys.sql
71
72 shp2pgsql -I \
73 -s $(TIGER_SRID) \
74 data/census-2000-block/maryland/tl_2008_24_tabblock00.shp \
75 tiger \
76 | psql -U $(DB_USER) -d $(DB_NAME)
77
78 psql -d $(DB_NAME) \
79 -U $(DB_USER) \
80 -f sql/create-sf1_blocks-table.sql
81
82 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
83 | psql -U postgres -d $(DB_NAME)
84