-
-
Save ateucher/92554a9db882c231750bd1c7d14615b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install gdal, python, postgresql/postgis on Ubuntu 16.04 | |
# install dependencies | |
sudo apt install unzip | |
sudo apt-get update | |
sudo apt-get install python-pip | |
sudo add-apt-repository ppa:ubuntugis/ppa | |
sudo apt-get update | |
sudo apt-get install gdal-bin libgdal-dev | |
pip install --upgrade pip | |
pip install --upgrade --user virtualenv | |
# install python gis | |
sudo pip install numpy | |
sudo pip install rasterio | |
sudo pip install fiona | |
# install latest postgres/postgis | |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' | |
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add - | |
sudo apt-get update | |
sudo apt-get install postgresql postgresql-contrib | |
sudo apt-get install postgresql-9.6-postgis-2.3 | |
# create user (gis) and db (postgis) | |
sudo -i -u postgres | |
createuser --interactive | |
createdb postgis | |
# enable postgis and create the users pwd | |
psql postgis | |
CREATE EXTENSION postgis; | |
ALTER USER gis WITH PASSWORD 'mypwd'; | |
\q | |
exit | |
# more libs | |
sudo pip install sqlalchemy | |
sudo pip install html5lib | |
sudo pip install https://github.com/smnorris/bcdata/zipball/master | |
sudo pip install https://github.com/smnorris/pgdb/zipball/master | |
# tune postgresql.conf based on 16gb vm | |
sudo nano /etc/postgresql/9.6/main/postgresql.conf | |
# max_connections = 1 | |
# shared_buffers = 4GB | |
# effective_cache_size = 12GB | |
# work_mem = 2GB | |
# maintenance_work_mem = 1GB | |
# min_wal_size = 1GB | |
# max_wal_size = 2GB | |
# checkpoint_completion_target = 0.9 | |
# wal_buffers = 16MB | |
# default_statistics_target = 100 | |
# restart after editing pgconf | |
sudo /etc/init.d/postgresql restart | |
# install lostgis | |
sudo apt-get install postgresql-server-dev-all | |
sudo pip install pgxnclient | |
sudo pgxn install lostgis | |
pgxn load -d postgis lostgis | |
# create pg shortcuts | |
# create .path and add lines below | |
cd | |
nano .path | |
# ------------ | |
# save pg typing | |
#export PGDATA=/etc/postgresql/9.6/main | |
#export PGHOST=localhost | |
#export PGPORT=5432 | |
#export PGDATABASE=postgis | |
#export PGUSER=gis | |
# reference .path in .profile | |
nano .profile | |
# add these lines | |
# -------- | |
# save pg typing | |
# export PGDATA=/etc/postgresql/9.6/main | |
# export PGHOST=localhost | |
# export PGPORT=5432 | |
# export PGDATABASE=postgis | |
# export PGUSER=gis | |
# put these together into a sqlalchemy URL | |
# http://docs.sqlalchemy.org/en/latest/core/engines.html | |
# note that the password is stored here in plain text viewable by anyone... | |
#export DATABASE_URL='postgresql://'$PGUSER'@'$PGHOST':'$PGPORT'/'$PGDATABASE | |
# ------------ | |
# create .pgpass & add pwd | |
nano .pgpass | |
# *:*:*:gis:gis | |
chmod 600 .pgpass | |
# install psql2csv | |
curl https://raw.githubusercontent.com/fphilipe/psql2csv/master/psql2csv > psql2csv | |
sudo cp psql2csv /usr/local/bin/psql2csv | |
sudo chmod +x /usr/local/bin/psql2csv | |
# create whse_basemapping and add tiles needed for most projects | |
psql -c "CREATE SCHEMA whse_basemapping" | |
bcdata --email [email protected] bcgs-1-20-000-grid | |
ogr2ogr \ | |
--config PG_USE_COPY YES \ | |
-f PostgreSQL \ | |
PG:"host=localhost user=gis dbname=postgis password=gis" \ | |
-nln bcgs_20k_grid \ | |
-t_srs EPSG:3005 \ | |
-lco OVERWRITE=YES \ | |
-lco SCHEMA=whse_basemapping \ | |
-lco GEOMETRY_NAME=geom \ | |
BCGS_20K_GRID.gdb \ | |
WHSE_BASEMAPPING_BCGS_20K_GRID_polygon | |
# exit and create snapshot | |
exit | |
doctl compute droplet-action snapshot 48695614 --snapshot-name gis_pg96_gdal21 | |
# recreate droplet from this image | |
doctl compute droplet create gis2 \ | |
--size 16gb \ | |
--image image_slug \ | |
--region nyc1 \ | |
--ssh-keys ssh_key_fingerprint |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment