#!/bin/sh
set -e
DBNAME=nhdplus
SRID=4269
ENCODING=LATIN1
FLOWLINE_TABLE=flowline
AREA_TABLE=area
WB_TABLE=waterbody
PT_TABLE=point
LINE_TABLE=line
createdb DBNAMEpsql−dDBNAME -c "CREATE EXTENSION postgis;"
flowlines=$(find . -iname nhdflowline.shp)
set -- flowlinesecho"CreatingFLOWLINE_TABLE schema"
shp2pgsql -p -D -t 2D -s SRID \1 FLOWLINETABLE∣psql−dDBNAME -q
for f in flowlines;doecho"Importingf..."
shp2pgsql -a -D -t 2D -s SRID−WENCODING fFLOWLINE_TABLE | pv | psql -d $DBNAME -q
done
psql -d DBNAME−c"CREATEINDEXCONCURRENTLY{FLOWLINE_TABLE}_geom_gist ON FLOWLINETABLEUSINGGIST(geom);"psql−dDBNAME -c "CREATE INDEX CONCURRENTLY FLOWLINETABLEftypeidxONFLOWLINE_TABLE(ftype);"
psql -d DBNAME−c"CREATEINDEXCONCURRENTLY{FLOWLINE_TABLE}_comid_idx ON FLOWLINETABLE(comid);"psql−dDBNAME -c "CREATE INDEX CONCURRENTLY FLOWLINETABLEfcodeidxONFLOWLINE_TABLE(fcode);"
areas=$(find . -iname nhdarea.shp)
set -- areasecho"CreatingAREA_TABLE schema"
shp2pgsql -p -D -t 2D -s SRID \1 AREATABLE∣psql−dDBNAME -q
for f in areas;doecho"Importingf..."
shp2pgsql -a -D -t 2D -s SRID−WENCODING fAREA_TABLE | pv | psql -d $DBNAME -q
done
psql -d DBNAME−c"CREATEINDEXCONCURRENTLY{AREA_TABLE}_geom_gist ON AREATABLEUSINGGIST(geom);"psql−dDBNAME -c "CREATE INDEX CONCURRENTLY AREATABLEftypeidxONAREA_TABLE(ftype);"
psql -d DBNAME−c"CREATEINDEXCONCURRENTLY{AREA_TABLE}_comid_idx ON AREATABLE(comid);"psql−dDBNAME -c "CREATE INDEX CONCURRENTLY AREATABLEfcodeidxONAREA_TABLE(fcode);"
waterbodies=$(find . -iname nhdwaterbody.shp)
set -- waterbodiesecho"CreatingWB_TABLE schema"
shp2pgsql -p -D -t 2D -s SRID \1 WBTABLE∣psql−dDBNAME -q
for f in waterbodies;doecho"Importingf..."
shp2pgsql -a -D -t 2D -s SRID−WENCODING fWB_TABLE | pv | psql -d $DBNAME -q
done
psql -d DBNAME−c"CREATEINDEXCONCURRENTLY{WB_TABLE}_geom_gist ON WBTABLEUSINGGIST(geom);"psql−dDBNAME -c "CREATE INDEX CONCURRENTLY WBTABLEftypeidxONWB_TABLE(ftype);"
psql -d DBNAME−c"CREATEINDEXCONCURRENTLY{WB_TABLE}_comid_idx ON WBTABLE(comid);"psql−dDBNAME -c "CREATE INDEX CONCURRENTLY WBTABLEfcodeidxONWB_TABLE(fcode);"
vaas=$(find . -iname plusflowlinevaa.dbf)
set -- vaas
echo "Creating plusflowlinevaa schema"
pgdbf -s LATIN1 \1 | psql -d DBNAME−qpsql−dDBNAME -c "TRUNCATE TABLE plusflowlinevaa;"
for f in vaas;doecho"Importingf..."
pgdbf -CDs LATIN1 f∣pv∣psql−dDBNAME -q
done
psql -d DBNAME−c"CREATEINDEXCONCURRENTLYplusflowlinevaacomididxONplusflowlinevaa(comid);"psql−dDBNAME -c "CREATE INDEX CONCURRENTLY plusflowlinevaa_streamorde_idx ON plusflowlinevaa(streamorde);"
psql -d $DBNAME -c "CREATE INDEX CONCURRENTLY plusflowlinevaa_levelpathi_idx ON plusflowlinevaa(levelpathi);"
pgdbf -s LATIN1 (find.−nameNHDFcode.dbf∣head−1)∣pv∣psql−dnhdplus−qpsql−dDBNAME -c "CREATE INDEX CONCURRENTLY nhdfcode_fcode_idx ON nhdfcode(fcode);"
points=$(find . -iname nhdpoint.shp)
set -- pointsecho"CreatingPT_TABLE schema"
shp2pgsql -p -D -s SRID \1 PTTABLE∣psql−dDBNAME -q
for f in points;doecho"Importingf..."
shp2pgsql -a -D -s SRID−WENCODING fPT_TABLE | pv | psql -d $DBNAME -q
done
psql -d DBNAME−c"CREATEINDEXCONCURRENTLY{PT_TABLE}_geom_gist ON PTTABLEUSINGGIST(geom);"psql−dDBNAME -c "CREATE INDEX CONCURRENTLY PTTABLEftypeidxONPT_TABLE(ftype);"
psql -d DBNAME−c"CREATEINDEXCONCURRENTLY{PT_TABLE}_comid_idx ON $PT_TABLE(comid);"
lines=$(find . -iname nhdline.shp)
set -- linesecho"CreatingLINE_TABLE schema"
shp2pgsql -p -D -s SRID \1 LINETABLE∣psql−dDBNAME -q
for f in lines;doecho"Importingf..."
shp2pgsql -a -D -s SRID−WENCODING fLINE_TABLE | pv | psql -d $DBNAME -q
done
psql -d DBNAME−c"CREATEINDEXCONCURRENTLY{LINE_TABLE}_geom_gist ON LINETABLEUSINGGIST(geom);"psql−dDBNAME -c "CREATE INDEX CONCURRENTLY LINETABLEftypeidxONLINE_TABLE(ftype);"
psql -d DBNAME−c"CREATEINDEXCONCURRENTLY{LINE_TABLE}_comid_idx ON $LINE_TABLE(comid);"