-
Notifications
You must be signed in to change notification settings - Fork 0
/
import-alaska-data.sh
executable file
·34 lines (27 loc) · 1.36 KB
/
import-alaska-data.sh
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
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=0 --username postgres --dbname postgres <<-EOSQL
DROP DATABASE alaska_features;
CREATE DATABASE alaska_features;
EOSQL
psql -U postgres -d alaska_features -c 'CREATE EXTENSION IF NOT EXISTS POSTGIS'
for entry in data/*.shp;
do
echo $entry
# ogr2ogr -f "PostgreSQL" "PG:host=localhost user=dart dbname=dart_test password=mypassw0rd" "$entry" -lco GEOMETRY_NAME=geom -lco FID=gid -lco PRECISION=no -nlt PROMOTE_TO_MULTI -nln new_layername -overwrite
tablename="$(basename -- $entry)"
name=$(echo "$tablename" | cut -f 1 -d '.')
# echo "$name"
# shp2pgsql -I -S -s 4326 $entry public."$name" | psql -v ON_ERROR_STOP=1 -q -U postgres -d alaska_features
ogr2ogr -f "PostgreSQL" -overwrite PG:"host=localhost user=postgres dbname=alaska_features password=Mula1000" -t_srs EPSG:4326 -lco GEOMETRY_NAME=geom $entry -nln $name
done
for entry in data/*.geojson;
do
echo $entry
tablename="$(basename -- $entry)"
name=$(echo "$tablename" | cut -f 1 -d '.')
# echo "$name"
# psql -U postgres -c "DROP TABLE IF EXISTS $name"
# shp2pgsql -I -S -s 4326 $entry public."$name" | psql -v ON_ERROR_STOP=1 -q -U postgres -d alaska_features
ogr2ogr -f "PostgreSQL" -overwrite PG:"host=localhost user=postgres dbname=alaska_features password=Mula1000" -t_srs EPSG:4326 -lco GEOMETRY_NAME=geom $entry -nln $name
done