X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=makefile;h=13fd41be6c2c0a3b806b1ea65e5a8f40a72ccb97;hb=5bdd6e837232451fe5ae6dd9f726763587eb631e;hp=13032e9a18ef6b031dc251820dfd49186f8dd26e;hpb=ee8fd80377354b587a9dbe19ff25fea0cf8979e5;p=dead%2Fcensus-tools.git diff --git a/makefile b/makefile index 13032e9..13fd41b 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,20 @@ -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' -TIGER_SRID='4269' +DB_NAME=census +DB_USER=postgres +TIGER_SRID=4269 + +# URLs for the TIGER/Line block-level shapefiles. +TIGER_ROOT=http://www2.census.gov/geo/tiger/TIGER2009 +MD_BLOCKS_URL=$(TIGER_ROOT)/24_MARYLAND/tl_2009_24_tabblock00.zip +VA_BLOCKS_URL=$(TIGER_ROOT)/51_VIRGINIA/tl_2009_51_tabblock00.zip +PA_BLOCKS_URL=$(TIGER_ROOT)/42_PENNSYLVANIA/tl_2009_42_tabblock00.zip +NY_BLOCKS_URL=$(TIGER_ROOT)/36_NEW_YORK/tl_2009_36_tabblock00.zip + +# 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. # @@ -27,15 +40,44 @@ clean: # 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; \ +data: tiger_blocks + +tiger_blocks: md_blocks va_blocks pa_blocks ny_blocks + +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; @@ -43,9 +85,10 @@ data: # 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. +# 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 @@ -56,28 +99,68 @@ data: # of the sf1blocks2sql script. # db: data - dropdb -U $(DB_USER) $(DB_NAME) + # 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 /usr/share/postgresql/contrib/lwpostgis.sql + -f $(PG_SHAREDIR)/contrib/postgis.sql psql -d $(DB_NAME) \ -U $(DB_USER) \ - -f /usr/share/postgresql/contrib/spatial_ref_sys.sql + -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql + + +# 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) - shp2pgsql -I \ + +# 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) \ - data/census-2000-block/maryland/tl_2008_24_tabblock00.shp \ - tiger \ + -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) + | psql -U postgres -d $(DB_NAME) > /dev/null