]> gitweb.michael.orlitzky.com - dead/census-tools.git/blobdiff - makefile
Added the framework for the PostGIS database integration.
[dead/census-tools.git] / makefile
index f3136a6cda47c33afcb4d13b3d9a8cde272ae5ff..2c20ffc4f90989ffa09bfa4b0172e54e900ff17e 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,9 +1,80 @@
-.PHONY : test
+DB_NAME='census2000'
+DB_USER='postgres'
+TIGER_DATA_URL='http://www2.census.gov/cgi-bin/shapefiles/multi-file-download?files=24_MARYLAND%2Ftl_2008_24_tabblock00.zip'
 
+
+# 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/census-2000-block/maryland/
+       if [ ! -f data/census-2000-block/maryland/tl_2008_24_tabblock00.shp ]; then \
+               wget -O tiger.zip $(TIGER_DATA_URL); \
+               unzip tiger.zip; \
+               rm tiger.zip; \
+               unzip srv/ftp/geo/tiger/TIGER2008/24_MARYLAND/tl_2008_24_tabblock00.zip \
+                      -d ./data/census-2000-block/maryland/; \
+               rm -rf srv; \
+       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, lwpostgis.sql and
+# spatial_ref_sys.sql. These are magic as far as I'm concerned, but
+# PostGIS requires them.
+#
+# 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
+       dropdb -U $(DB_USER) $(DB_NAME)
+       createdb -U $(DB_USER) $(DB_NAME)
+       createlang -U $(DB_USER) plpgsql $(DB_NAME)
+
+       psql -d $(DB_NAME) \
+             -U $(DB_USER) \
+             -f /usr/share/postgresql/contrib/lwpostgis.sql
+
+       psql -d $(DB_NAME) \
+             -U $(DB_USER) \
+             -f /usr/share/postgresql/contrib/spatial_ref_sys.sql
+
+       shp2pgsql -I data/census-2000-block/maryland/tl_2008_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)
+