+
+
+# 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: tiger_blocks tiger_lines
+
+tiger_blocks: dc_blocks md_blocks va_blocks pa_blocks ny_blocks
+
+dc_blocks:
+ mkdir -p data/census2000/dc/block
+ if [ ! -f data/census2000/dc/block/tl_2009_11_tabblock00.shp ]; \
+ then \
+ wget -O dcblocks.zip $(DC_BLOCKS_URL); \
+ unzip dcblocks.zip -d ./data/census2000/dc/block; \
+ rm dcblocks.zip; \
+ fi;
+
+md_blocks:
+ mkdir -p data/census2000/maryland/block
+ if [ ! -f data/census2000/maryland/block/tl_2009_24_tabblock00.shp ]; \
+ then \
+ wget -O mdblocks.zip $(MD_BLOCKS_URL); \
+ unzip mdblocks.zip -d ./data/census2000/maryland/block; \
+ rm mdblocks.zip; \
+ fi;
+
+va_blocks:
+ mkdir -p data/census2000/virginia/block
+ if [ ! -f data/census2000/virginia/block/tl_2009_51_tabblock00.shp ]; \
+ then \
+ wget -O vablocks.zip $(VA_BLOCKS_URL); \
+ unzip vablocks.zip -d ./data/census2000/virginia/block; \
+ rm vablocks.zip; \
+ fi;
+
+pa_blocks:
+ mkdir -p data/census2000/pennsylvania/block
+ if [ ! -f data/census2000/pennsylvania/block/tl_2009_42_tabblock00.shp ]; \
+ then \
+ wget -O pablocks.zip $(PA_BLOCKS_URL); \
+ unzip pablocks.zip -d ./data/census2000/pennsylvania/block; \
+ rm pablocks.zip; \
+ fi;
+
+ny_blocks:
+ mkdir -p data/census2000/new_york/block
+ if [ ! -f data/census2000/new_york/block/tl_2009_36_tabblock00.shp ]; \
+ then \
+ wget -O nyblocks.zip $(NY_BLOCKS_URL); \
+ unzip nyblocks.zip -d ./data/census2000/new_york/block; \
+ rm nyblocks.zip; \
+ fi;
+
+
+tiger_lines: dc_lines
+
+dc_lines:
+ mkdir -p data/census2000/dc/lines
+ if [ ! -f data/census2000/dc/lines/tl_2009_11001_edges.shp ]; \
+ then \
+ wget -O dclines.zip $(DC_LINES_URL); \
+ unzip dclines.zip -d ./data/census2000/dc/lines; \
+ rm dclines.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
+
+# D.C. Blocks
+
+ $(PG_BINDIR)/shp2pgsql \
+ -I \
+ -s $(TIGER_SRID) \
+ -D \
+ data/census2000/dc/block/tl_2009_11_tabblock00.shp \
+ tiger_blocks \
+ | psql -U $(DB_USER) -d $(DB_NAME)
+
+# Maryland Blocks
+
+ $(PG_BINDIR)/shp2pgsql \
+ -I \
+ -s $(TIGER_SRID) \
+ -D \
+ data/census2000/maryland/block/tl_2009_24_tabblock00.shp \
+ tiger_blocks \
+ | psql -U $(DB_USER) -d $(DB_NAME)
+
+
+# Virginia Blocks
+
+ $(PG_BINDIR)/shp2pgsql -a \
+ -I \
+ -s $(TIGER_SRID) \
+ -D \
+ data/census2000/virginia/block/tl_2009_51_tabblock00.shp \
+ tiger_blocks \
+ | psql -U $(DB_USER) -d $(DB_NAME)
+
+
+# Pennsylvania Blocks
+
+ $(PG_BINDIR)/shp2pgsql -a \
+ -I \
+ -s $(TIGER_SRID) \
+ -D \
+ data/census2000/pennsylvania/block/tl_2009_42_tabblock00.shp \
+ tiger_blocks \
+ | psql -U $(DB_USER) -d $(DB_NAME)
+
+
+# New York Blocks
+
+ $(PG_BINDIR)/shp2pgsql -a \
+ -I \
+ -s $(TIGER_SRID) \
+ -D \
+ data/census2000/new_york/block/tl_2009_36_tabblock00.shp \
+ tiger_blocks \
+ | 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) > /dev/null
+