Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 60 lines (54 sloc) 1.765 kB
1ede450 Update tiger_import for TIGER/Line 2010.
Schuyler Erle authored
1 #!/bin/bash
2
3 TMP="/tmp/tiger-import.$$"
4 SHPS="edges"
5 DBFS="featnames addr"
6 BASE=$(dirname $0)
7 PATH=$PATH:$BASE
6313ff6 @timwaters correct path to sql file
timwaters authored
8 SQL="$BASE/sql"
1ede450 Update tiger_import for TIGER/Line 2010.
Schuyler Erle authored
9 HELPER_LIB="$BASE/../lib/geocoder/us/sqlite3.so"
10 DATABASE=$1
11 shift
12
13 mkdir -p $TMP || exit 1
14
15 # Initialize the database if it doesn't exist.
16 [ ! -r $DATABASE ] && cat ${SQL}/{create,place}.sql | sqlite3 $DATABASE
17
18 # Marshal the county directories to import.
19 #
20 # If no directory was given on the command-line, read a list from STDIN.
21 if [ x"$1" = x"" ]; then
22 cat
23 else
24 # Otherwise, find all of the contents of each state directory.
25 ls -d $1/[0-9]* | while read state; do
26 ls -d ${state}/[0-9]*
27 done
28 fi | while read county; do
29 echo "--- $county"
30 # Unpack the county files into the temp directory.
31 for file in $SHPS $DBFS; do
32 ZIP=$(ls ${county}/*_${file}.zip 2>/dev/null)
33 SHP=$(ls ${county}/*_${file}.* 2>/dev/null)
34 if [ x"$ZIP" != x"" ]; then
35 unzip -q $ZIP -d $TMP
36 elif [ x"$SHP" != x"" ]; then
37 ln -s $SHP $TMP
38 fi
39 done
40 # Generate an SQL stream to feed into the sqlite3 binary.
41 # Start by loading the helper libs and initializing the temporary tables
42 # that will hold the TIGER data before ETL.
43 (echo ".load $HELPER_LIB" && \
44 cat ${SQL}/setup.sql && \
45 for file in $SHPS; do
46 # Convert each Shapefile into SQL statements.
47 shp2sqlite -aS ${TMP}/*_${file}.shp tiger_${file}
48 done && \
49 for file in $DBFS; do
50 # Convert each DBF into SQL statements likewise.
51 shp2sqlite -an ${TMP}/*_${file}.dbf tiger_${file}
52 done && \
53 cat ${SQL}/convert.sql) | sqlite3 $DATABASE
54 # Finally, do the transform/load phase (convert.sql)
55 # and clean up the temporary files.
56 rm -f $TMP/*
57 done 2>&1 | tee import-$$.log
58 rm -rf $TMP
59
Something went wrong with that request. Please try again.