-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·92 lines (77 loc) · 2.54 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·92 lines (77 loc) · 2.54 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# Under the Sea - Setup Script
# This script sets up the database and imports census data
set -e # Exit on any error
echo "Setting up Under the Sea - Sea Level Rise Explorer"
echo "=================================================="
# Check if PostgreSQL is installed
if ! command -v psql &> /dev/null; then
echo "ERROR: PostgreSQL not found. Please install it first:"
echo " brew install postgresql@14 postgis"
exit 1
fi
# Check if ogr2ogr is installed
if ! command -v ogr2ogr &> /dev/null; then
echo "ERROR: ogr2ogr not found. Please install GDAL:"
echo " brew install gdal"
exit 1
fi
# Database configuration
DB_NAME="slr"
DB_USER="slr_user"
DB_PASSWORD="secure_password_123"
DB_HOST="localhost"
DB_PORT="5432"
echo "Setting up database..."
# Check if database exists
if psql -lqt | cut -d \| -f 1 | grep -qw $DB_NAME; then
echo "WARNING: Database '$DB_NAME' already exists."
read -p "Do you want to recreate it? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Dropping existing database..."
dropdb $DB_NAME 2>/dev/null || true
psql -c "DROP ROLE IF EXISTS $DB_USER;" 2>/dev/null || true
else
echo "SUCCESS: Using existing database"
exit 0
fi
fi
# Create database user and database
echo "Creating database user and database..."
psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASSWORD';" || {
echo "WARNING: User might already exist, continuing..."
}
createdb $DB_NAME -O $DB_USER || {
echo "ERROR: Failed to create database"
exit 1
}
# Enable PostGIS extension
echo "Enabling PostGIS extension..."
psql -d $DB_NAME -c "CREATE EXTENSION IF NOT EXISTS postgis;"
# Check if shapefile exists
SHAPEFILE="USA_Census_2020_Redistricting_Tracts/Tracts.shp"
if [ ! -f "$SHAPEFILE" ]; then
echo "ERROR: Census shapefile not found at $SHAPEFILE"
echo " Please ensure the shapefile is in the correct location."
exit 1
fi
# Import census data
echo "Importing census data..."
ogr2ogr -f "PostgreSQL" \
"PG:host=$DB_HOST dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD" \
"$SHAPEFILE" \
-nln census_tracts \
-lco GEOMETRY_NAME=geom \
-lco PRECISION=NO \
-nlt PROMOTE_TO_MULTI \
-overwrite
# Verify import
TRACT_COUNT=$(psql -d $DB_NAME -U $DB_USER -h $DB_HOST -t -c "SELECT COUNT(*) FROM census_tracts;" | xargs)
echo "SUCCESS: Setup complete!"
echo "INFO: Imported $TRACT_COUNT census tracts"
echo ""
echo "To start the application:"
echo " streamlit run app.py"
echo ""
echo "The app will be available at: http://localhost:8501"