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

Revision 22580, 3.0 KB checked in by ahlzen, 4 years ago (diff)

Added TopOSM code and resources.

  • Property svn:executable set to *
Line 
1#!/bin/sh
2
3# unpacked NHD shapefiles in the following directory:
4SRCDIR="temp/nhd"
5
6DATABASE="gis"
7
8# HACK: Removes transaction support for shp2pgsql
9# because a few lines in each file contain illegal characters, aborting
10# entire transactions. Better yet would be to filter out these characters
11# but that's for later...
12FILTER='s/BEGIN;//g'
13
14# NOTE: The data type for fcode and ftype is changed because, for some
15# reason, mapnik (silently) fails to filter on bigint columns.
16
17# areas
18PREP_TABLE=1
19for SRCFILE in $SRCDIR/nhdarhi*.shp; do
20#for SRCFILE in $SRCDIR/processed/area*.shp; do
21    if [ "$PREP_TABLE" ]; then
22        echo "Creating nhdarea table..."
23        shp2pgsql -p -I -g way "$SRCFILE" nhdarea | psql -q $DATABASE
24        shp2pgsql -p -I -g way "$SRCFILE" nhdarea_major | psql -q $DATABASE
25    fi
26    echo "Importing $SRCFILE..."
27    shp2pgsql -a -g way "$SRCFILE" nhdarea | psql -q $DATABASE
28    unset PREP_TABLE
29done
30echo "ALTER TABLE nhdarea ALTER COLUMN fcode TYPE INT, ALTER COLUMN ftype TYPE INT" | psql -q $DATABASE
31echo "ALTER TABLE nhdarea_major ALTER COLUMN fcode TYPE INT, ALTER COLUMN ftype TYPE INT" | psql -q $DATABASE
32
33echo "Extracting major areas..."
34echo "INSERT INTO nhdarea_major SELECT * FROM nhdarea WHERE areasqkm > 1" | psql -q $DATABASE
35
36# flowlines
37PREP_TABLE=1
38for SRCFILE in $SRCDIR/nhdflh??.shp; do
39    if [ "$PREP_TABLE" ]; then
40        echo "Creating nhdflowline table..."
41        shp2pgsql -p -I -g way "$SRCFILE" nhdflowline | psql -q $DATABASE
42        shp2pgsql -p -I -g way "$SRCFILE" nhdflowline_major | psql -q $DATABASE
43    fi
44    echo "Importing $SRCFILE..."
45    shp2pgsql -a -g way "$SRCFILE" nhdflowline | \
46        sed "$FILTER" | \
47        psql -q $DATABASE
48    unset PREP_TABLE
49done
50echo "ALTER TABLE nhflowline ALTER COLUMN fcode TYPE INT, ALTER COLUMN ftype TYPE INT" | psql -q $DATABASE
51
52echo "Extracting major flowlines..."
53echo "INSERT INTO nhdflowline_major SELECT * FROM nhdflowline WHERE lengthkm > 2" | psql -q $DATABASE
54
55# points
56PREP_TABLE=1
57for SRCFILE in $SRCDIR/nhdpthi*.shp; do
58    if [ "$PREP_TABLE" ]; then
59        echo "Creating nhdpoint table..."
60        shp2pgsql -p -I -g way "$SRCFILE" nhdpoint | psql -q $DATABASE
61    fi
62    echo "Importing $SRCFILE..."
63    shp2pgsql -a -g way "$SRCFILE" nhdpoint | \
64        sed "$FILTER" | \
65        psql -q $DATABASE
66    unset PREP_TABLE
67done
68echo "ALTER TABLE nhdpoint ALTER COLUMN fcode TYPE INT, ALTER COLUMN ftype TYPE INT" | psql -q $DATABASE
69
70# waterbodies
71PREP_TABLE=1
72for SRCFILE in $SRCDIR/nhdwbhi*.shp; do
73    if [ "$PREP_TABLE" ]; then
74        echo "Creating nhdwaterbody table..."
75        shp2pgsql -p -I -g way "$SRCFILE" nhdwaterbody | psql -q $DATABASE
76        shp2pgsql -p -I -g way "$SRCFILE" nhdwaterbody_major | psql -q $DATABASE
77    fi
78    echo "Importing $SRCFILE..."
79    shp2pgsql -a -g way "$SRCFILE" nhdwaterbody | \
80        sed "$FILTER" | \
81        psql -q $DATABASE
82    unset PREP_TABLE
83done
84echo "ALTER TABLE nhdwaterbody ALTER COLUMN fcode TYPE INT, ALTER COLUMN ftype TYPE INT" | psql -q $DATABASE
85
86echo "Extracting major waterbodies..."
87echo "INSERT INTO nhdwaterbody_major SELECT * FROM nhdwaterbody WHERE areasqkm > 1" | psql -q $DATABASE
88
89echo "Done."
Note: See TracBrowser for help on using the repository browser.