source: subversion/applications/rendering/toposm/import_nhd @ 34399

Last change on this file since 34399 was 23632, checked in by ahlzen, 9 years ago

Fixed issues in import_nhd script.

  • Property svn:executable set to *
File size: 3.0 KB
Line 
1#!/bin/bash
2
3if [[ -z $TOPOSM_ENV_SET ]]; then
4    echo "Error: TopOSM environment not set."
5    exit 1
6fi
7
8SETUPCMD="shp2pgsql -p -I -g way -W latin1"
9IMPORTCMD="shp2pgsql -a -g way -W latin1"
10DBCMD="psql -q -p $DB_PORT $DB_NAME $DB_USER"
11
12# NOTE: The data type for fcode and ftype is changed because, for some
13# reason, mapnik (silently) fails to filter on bigint columns.
14
15# areas
16PREP_TABLE=1
17for SRCFILE in $NHD_DIR/nhdarhi*.shp; do
18    if [ "$PREP_TABLE" ]; then 
19            echo "Creating ${NHD_TABLE_PREFIX}_area tables..."
20            $SETUPCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_area | $DBCMD
21            $SETUPCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_area_major | $DBCMD
22    fi
23    echo "Importing $SRCFILE..."
24    $IMPORTCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_area |  $DBCMD
25    unset PREP_TABLE
26done
27echo "ALTER TABLE ${NHD_TABLE_PREFIX}_area ALTER COLUMN fcode TYPE INT, ALTER COLUMN ftype TYPE INT" | $DBCMD
28echo "ALTER TABLE ${NHD_TABLE_PREFIX}_area_major ALTER COLUMN fcode TYPE INT, ALTER COLUMN ftype TYPE INT" | $DBCMD
29echo "Extracting major areas..."
30echo "INSERT INTO ${NHD_TABLE_PREFIX}_area_major SELECT * FROM ${NHD_TABLE_PREFIX}_area WHERE areasqkm > 1" | $DBCMD
31
32# flowlines
33PREP_TABLE=1
34for SRCFILE in $NHD_DIR/nhdflh??.shp; do
35    if [ "$PREP_TABLE" ]; then 
36            echo "Creating ${NHD_TABLE_PREFIX}_flowline table..."
37            $SETUPCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_flowline | $DBCMD
38            $SETUPCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_flowline_major | $DBCMD
39    fi
40    echo "Importing $SRCFILE..."
41    $IMPORTCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_flowline | $DBCMD
42    unset PREP_TABLE
43done
44echo "ALTER TABLE ${NHD_TABLE_PREFIX}_flowline ALTER COLUMN fcode TYPE INT, ALTER COLUMN ftype TYPE INT" | $DBCMD
45echo "Extracting major flowlines..."
46echo "INSERT INTO ${NHD_TABLE_PREFIX}_flowline_major SELECT * FROM ${NHD_TABLE_PREFIX}_flowline WHERE lengthkm > 2" | $DBCMD
47
48# points
49PREP_TABLE=1
50for SRCFILE in $NHD_DIR/nhdpthi*.shp; do
51    if [ "$PREP_TABLE" ]; then 
52            echo "Creating ${NHD_TABLE_PREFIX}_point table..."
53            $SETUPCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_point | $DBCMD
54    fi
55    echo "Importing $SRCFILE..."
56    $IMPORTCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_point | $DBCMD
57    unset PREP_TABLE
58done
59echo "ALTER TABLE ${NHD_TABLE_PREFIX}_point ALTER COLUMN fcode TYPE INT, ALTER COLUMN ftype TYPE INT" | $DBCMD
60
61# waterbodies
62PREP_TABLE=1
63for SRCFILE in $NHD_DIR/nhdwbhi*.shp; do
64    if [ "$PREP_TABLE" ]; then 
65            echo "Creating ${NHD_TABLE_PREFIX}_waterbody table..."
66            $SETUPCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_waterbody | $DBCMD
67            $SETUPCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_waterbody_major | $DBCMD
68    fi
69    echo "Importing $SRCFILE..."
70    $IMPORTCMD "$SRCFILE" ${NHD_TABLE_PREFIX}_waterbody | $DBCMD
71    unset PREP_TABLE
72done
73echo "ALTER TABLE ${NHD_TABLE_PREFIX}_waterbody ALTER COLUMN fcode TYPE INT, ALTER COLUMN ftype TYPE INT" | $DBCMD
74echo "Extracting major waterbodies..."
75echo "INSERT INTO ${NHD_TABLE_PREFIX}_waterbody_major SELECT * FROM ${NHD_TABLE_PREFIX}_waterbody WHERE areasqkm > 1" | $DBCMD
76
77echo "Done."
Note: See TracBrowser for help on using the repository browser.