-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloadshapedata
More file actions
executable file
·68 lines (50 loc) · 1.46 KB
/
loadshapedata
File metadata and controls
executable file
·68 lines (50 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Takes in the table name, directory containing a bunch of ZIP’ed shape files and a temp working directory
# Flattens all of the zip files in the shape directory into a table named “public.DATASET”
#/bin/bash
-set e
DATASET=$1
SHAPEDIR=$2
TEMP=$3
if [ “$#” -eq 0 ];
then
echo “Please enter the dataset, shape directory and staging directory”
exit 1
fi
if [ -z “$TEMP” ]
then
echo attempting to set $TEMP directory to system temp directory
$TEMP=$TMPDIR
fi
if [ -z “$TEMP” ]
then
echo Could not set temp directory. Bailing
exit 1
fi
#assumes just default install of PostGIS
DB=postgres
USER_NAME=postgres
TABLE=public.$DATASET
#Clean up the staging directory, otherwise we will potentially end up with the wrong schema for each shape file
cd $TEMP
rm $TEMP/*.shp
rm $TEMP/*.zip
rm $TEMP/*.dbf
rm $TEMP/*.prj
rm $TEMP/*.shx
cd $SHAPEDIR
#unzip files into temp working directory
for z in *.zip; do unzip -o -d $TEMP $z; done
cd $TMPDIR
#Get the first file. Used to set the schema in PostGIS
FIRSTFILE=$(ls *.shp | head -1)
echo $FIRST FILE
#prepare the tables don't load data
shp2pgsql -p -s 4326 -W LATIN1 $FIRSTFILE $TABLE | psql -U $USER_NAME -d $DB
#loop thru shapes and put them into SQL as 4326
for z in *${t}.shp;
do
shp2pgsql -s 4326 -W LATIN1 -a $z $TABLE | psql -d $DB -U $USER_NAME;
done
psql -d $DB -U $USER_NAME “CREATE INDEX geom_gix ON $TABLE USING gist\(geom\)”
cd $TMPDIR
rm $TMPDIR/*