DB_NAME='census' DB_USER='postgres' TIGER_DATA_URL='http://www2.census.gov/geo/tiger/TIGER2009/24_MARYLAND/tl_2009_24_tabblock00.zip' TIGER_SRID='4269' # Starting with PostGIS 1.4.0, these paths are calculated at install # time using the pg_config utility. Rather than try to guess where # PostGIS will wind up installed, we can just check the output of # pg_config ourselves. PG_BINDIR=`pg_config --bindir` PG_SHAREDIR=`pg_config --sharedir` # Necessary to run test/data without prerequisites. # .PHONY : test data # The default task, since it comes first in the list. # all: clean test test: ./bin/run_tests # Remove byte-compiled python code. # clean: find ./ -name '*.pyc' -print0 | xargs -0 rm -f # Download the shapefiles from Tiger if they don't already exist. # For now, we're only dealing with the Census 2000 Maryland Block # data, so the filenames are hard-coded. Easy enough to change. # data: mkdir -p data/census2000/maryland/block if [ ! -f data/census2000/maryland/block/tl_2009_24_tabblock00.shp ]; then \ wget -O tmp.zip $(TIGER_DATA_URL); \ unzip tmp.zip -d ./data/census2000/maryland/block; \ rm tmp.zip; \ fi; # This task does a couple of things. First, it drops and re-creates # the DB_NAME database (or schema, whatever). Then, it adds PL/pgSQL # support to the database. # # At that point, we import the two PostGIS files, postgis.sql and # spatial_ref_sys.sql. The postgis.sql file contains the geometry # functions, while spatial_ref_sys.sql contains a table of SRIDs, and # their associated properties. PostGIS requires both. # # Then, we import the Tiger data using shp2pgsql. The shapefiles # should exist, since this task depends on the "data" task, which # downloads said shapefiles. # # Finally, we create the table for the demographic data (obtained from # the geographic header records), and populate that table with the output # of the sf1blocks2sql script. # db: data # Ignore the result of dropdb when it fails. dropdb -U $(DB_USER) $(DB_NAME) || true createdb -U $(DB_USER) $(DB_NAME) createlang -U $(DB_USER) plpgsql $(DB_NAME) psql -d $(DB_NAME) \ -U $(DB_USER) \ -f $(PG_SHAREDIR)/contrib/postgis.sql psql -d $(DB_NAME) \ -U $(DB_USER) \ -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql $(PG_BINDIR)/shp2pgsql -I \ -s $(TIGER_SRID) \ data/census2000/maryland/block/tl_2009_24_tabblock00.shp \ tiger \ | psql -U $(DB_USER) -d $(DB_NAME) psql -d $(DB_NAME) \ -U $(DB_USER) \ -f sql/create-sf1_blocks-table.sql bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \ | psql -U postgres -d $(DB_NAME)