4 SHAPELY_URL=http://pypi.python.org/packages/source/S/Shapely/Shapely-1.0.14.tar.gz
7 # Starting with PostGIS 1.4.0, these paths are calculated at install
8 # time using the pg_config utility. Rather than try to guess where
9 # PostGIS will wind up installed, we can just check the output of
10 # pg_config ourselves.
11 PG_BINDIR=`pg_config --bindir`
12 PG_SHAREDIR=`pg_config --sharedir`
14 # Necessary to run test/data without prerequisites.
16 .PHONY : test data lib
19 # The default task, since it comes first in the list.
28 # Download or check out any third-party libraries.
30 if [ ! -d lib/Shapely ]; then \
31 wget -O shapely.tar.gz $(SHAPELY_URL); \
32 tar -xvzf shapely.tar.gz -C lib/ ; \
34 mv lib/Shapely* lib/Shapely; \
38 # Remove byte-compiled python code.
41 find ./ -name '*.pyc' -print0 | xargs -0 rm -f
48 # This imports the Tiger data using shp2pgsql. The shapefiles
49 # should exist, since this task depends on the "data" task, which
50 # downloads said shapefiles.
52 # After the TIGER import is done, we use the sf1blocks2sql script to
53 # parse and import the geographic header record information.
55 db: data newdb tiger_blocks_table tiger_lines_table sf1_blocks_table
58 # The table already exists, so we can append to it, and we don't have
59 # to create the GiST index.
60 for state in data/census2000/*; do \
61 $(PG_BINDIR)/shp2pgsql \
65 $$state/blocks/*.shp \
67 | psql -U $(DB_USER) -d $(DB_NAME); \
72 # Since the table and index already exist, we can utilize -a,
74 for state in data/census2000/*; do \
75 for shapefile in $$state/lines/*.shp; do \
76 echo "Importing $$shapefile."; \
77 $(PG_BINDIR)/shp2pgsql \
82 | bin/filter-transactions \
83 | psql -U $(DB_USER) -d $(DB_NAME) \
88 bin/sf1blocks2sql src/Tests/Fixtures/SummaryFile1/mdgeo.uf1 sf1_blocks \
89 | psql -U postgres -d $(DB_NAME) \
94 # First, we drop and re-create the DB_NAME database (or schema,
95 # whatever). Then, we add PL/pgSQL support to the database.
97 # At that point, we import the two PostGIS files, postgis.sql and
98 # spatial_ref_sys.sql. The postgis.sql file contains the geometry
99 # functions, while spatial_ref_sys.sql contains a table of SRIDs, and
100 # their associated properties. PostGIS requires both.
103 # Ignore the result of dropdb when it fails.
104 dropdb -U $(DB_USER) $(DB_NAME) || true
105 createdb -U $(DB_USER) $(DB_NAME)
106 createlang -U $(DB_USER) plpgsql $(DB_NAME)
110 -f $(PG_SHAREDIR)/contrib/postgis.sql \
115 -f $(PG_SHAREDIR)/contrib/spatial_ref_sys.sql \
119 # This just runs the SQL script to create the sf1_blocks table.
123 -f sql/create-sf1_blocks-table.sql \
127 # Create the tiger_blocks table, and create its GiST index. Having the
128 # table already exist makes importing via shp2pgsql much easier.
129 # Any blocks file will work as an argument.
131 $(PG_BINDIR)/shp2pgsql \
135 data/census2000/maryland/blocks/tl_2009_24_tabblock00.shp \
137 | psql -U postgres -d $(DB_NAME) \
141 # Prepare the tiger_lines table, and create the GiST index on its
142 # geometry column. Any lines shapefile will do here.
144 $(PG_BINDIR)/shp2pgsql \
148 data/census2000/maryland/lines/tl_2009_24510_edges.shp \
150 | psql -U postgres -d $(DB_NAME) \
153 # Add a unique index on the "tlid" column.
156 -f sql/create_tlid_unique_index.sql