5 # Root folder for the shapefiles.
6 TIGER_ROOT=http://www2.census.gov/geo/tiger/TIGER2009
8 # State-specific folders.
9 DC_ROOT=$(TIGER_ROOT)/11_DISTRICT_OF_COLUMBIA
10 MD_ROOT=$(TIGER_ROOT)/24_MARYLAND
11 VA_ROOT=$(TIGER_ROOT)/51_VIRGINIA
12 PA_ROOT=$(TIGER_ROOT)/42_PENNSYLVANIA
13 NY_ROOT=$(TIGER_ROOT)/36_NEW_YORK
15 # URLs for the TIGER/Line block-level shapefiles.
16 DC_BLOCKS_URL=$(DC_ROOT)/tl_2009_11_tabblock00.zip
17 MD_BLOCKS_URL=$(MD_ROOT)/tl_2009_24_tabblock00.zip
18 VA_BLOCKS_URL=$(VA_ROOT)/tl_2009_51_tabblock00.zip
19 PA_BLOCKS_URL=$(PA_ROOT)/tl_2009_42_tabblock00.zip
20 NY_BLOCKS_URL=$(NY_ROOT)/tl_2009_36_tabblock00.zip
22 # Starting with PostGIS 1.4.0, these paths are calculated at install
23 # time using the pg_config utility. Rather than try to guess where
24 # PostGIS will wind up installed, we can just check the output of
25 # pg_config ourselves.
26 PG_BINDIR=`pg_config --bindir`
27 PG_SHAREDIR=`pg_config --sharedir`
29 # Necessary to run test/data without prerequisites.
34 # The default task, since it comes first in the list.
43 # Remove byte-compiled python code.
46 find ./ -name '*.pyc' -print0 | xargs -0 rm -f
49 # Download the shapefiles from Tiger if they don't already exist.
50 # For now, we're only dealing with the Census 2000 Maryland Block
51 # data, so the filenames are hard-coded. Easy enough to change.
53 data: tiger_blocks tiger_lines
55 tiger_blocks: dc_blocks md_blocks va_blocks pa_blocks ny_blocks
58 mkdir -p data/census2000/dc/block
59 if [ ! -f data/census2000/dc/block/tl_2009_11_tabblock00.shp ]; \
61 wget -O dcblocks.zip $(DC_BLOCKS_URL); \
62 unzip dcblocks.zip -d ./data/census2000/dc/block; \
67 mkdir -p data/census2000/maryland/block
68 if [ ! -f data/census2000/maryland/block/tl_2009_24_tabblock00.shp ]; \
70 wget -O mdblocks.zip $(MD_BLOCKS_URL); \
71 unzip mdblocks.zip -d ./data/census2000/maryland/block; \
76 mkdir -p data/census2000/virginia/block
77 if [ ! -f data/census2000/virginia/block/tl_2009_51_tabblock00.shp ]; \
79 wget -O vablocks.zip $(VA_BLOCKS_URL); \
80 unzip vablocks.zip -d ./data/census2000/virginia/block; \
85 mkdir -p data/census2000/pennsylvania/block
86 if [ ! -f data/census2000/pennsylvania/block/tl_2009_42_tabblock00.shp ]; \
88 wget -O pablocks.zip $(PA_BLOCKS_URL); \
89 unzip pablocks.zip -d ./data/census2000/pennsylvania/block; \
94 mkdir -p data/census2000/new_york/block
95 if [ ! -f data/census2000/new_york/block/tl_2009_36_tabblock00.shp ]; \
97 wget -O nyblocks.zip $(NY_BLOCKS_URL); \
98 unzip nyblocks.zip -d ./data/census2000/new_york/block; \
107 # This imports the Tiger data using shp2pgsql. The shapefiles
108 # should exist, since this task depends on the "data" task, which
109 # downloads said shapefiles.
111 # After the TIGER import is done, we use the sf1blocks2sql script to
112 # parse and import the geographic header record information.
114 db: data newdb tiger_blocks_table tiger_lines_table sf1_blocks_table
117 # The table already exists, so we can append to it, and we don't have
118 # to create the GiST index.
119 for state in data/census2000/*; do \
120 $(PG_BINDIR)/shp2pgsql \
124 $$state/block/*.shp \
126 | psql -U $(DB_USER) -d $(DB_NAME); \
131 # Since the table and index already exist, we can utilize -a,
133 for x in data/census2000/maryland/lines/*.shp; do \
134 $(PG_BINDIR)/shp2pgsql \
140 | psql -U $(DB_USER) -d $(DB_NAME); \
143 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
144 | psql -U postgres -d $(DB_NAME) \
149 # First, we drop and re-create the DB_NAME database (or schema,
150 # whatever). Then, we add PL/pgSQL support to the database.
152 # At that point, we import the two PostGIS files, postgis.sql and
153 # spatial_ref_sys.sql. The postgis.sql file contains the geometry
154 # functions, while spatial_ref_sys.sql contains a table of SRIDs, and
155 # their associated properties. PostGIS requires both.
158 # Ignore the result of dropdb when it fails.
159 dropdb -U $(DB_USER) $(DB_NAME) || true
160 createdb -U $(DB_USER) $(DB_NAME)
161 createlang -U $(DB_USER) plpgsql $(DB_NAME)
165 -f $(PG_SHAREDIR)/contrib/postgis.sql \
170 -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql \
174 # This just runs the SQL script to create the sf1_blocks table.
178 -f sql/create-sf1_blocks-table.sql \
182 # Create the tiger_blocks table, and create its GiST index. Having the
183 # table already exist makes importing via shp2pgsql much easier.
184 # Any blocks file will work as an argument.
186 $(PG_BINDIR)/shp2pgsql \
190 data/census2000/maryland/block/tl_2009_24_tabblock00.shp \
192 | psql -U postgres -d $(DB_NAME) \
196 # Prepare the tiger_lines table, and create the GiST index on its
197 # geometry column. Any lines shapefile will do here.
199 $(PG_BINDIR)/shp2pgsql \
203 data/census2000/maryland/lines/tl_2009_24510_edges.shp \
205 | psql -U postgres -d $(DB_NAME) \