Useful resource: Setting up PostGIS (postgres-9.3), qGIS.
From http://www.mapbox.com/tilemill/docs/guides/ubuntu-service/.
# Tilemill
sudo add-apt-repository ppa:developmentseed/mapbox
sudo add-apt-repository ppa:mapnik/v2.2.0
sudo apt-get update
sudo apt-get install tilemill libmapnik nodejs
# Preferences can be changed by editing /etc/tilemill/tilemill.config
# Run with /usr/share/tilemill/index.js --server=true
# You should also be able to run with service tilemill start, but
# I couldn't get that to read the config file properly.
PostGIS install instructions from Setting up PostGIS (postgres-9.3), qGIS.
# Dependencies: postGIS
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list'
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.3-postgis-2.1 pgadmin3 postgresql-contrib
sudo apt-get install phppgadmin
Edit file
sudo nano /etc/postgresql/9.3/main/pg_hba.conf
Add (change last column to trust
):
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
To make Postgres accessible from outside localhost (from http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html):
su - postgres
echo 'host all all 50.174.116.72/24 trust' >> /etc/postgresql/9.3/main/pg_hba.conf
#echo 'host all all 0.0.0.0/0 trust' >> /etc/postgresql/9.3/main/pg_hba.conf
The first will give access to a specifc ip. The latter gives access to everyone. See this blog post for details.
Edit /etc/postgresql/9.3/main/postgresql.conf
, change listen_addresses='localhost'
to listen_addresses='*'
.
sudo /etc/init.d/postgresql restart
Now create the osm table and import PostGIS:
export GTFS_DB=osm
psql -U postgres -c "drop database if exists \"$GTFS_DB\";"
psql -U postgres -c "create database \"$GTFS_DB\";"
psql -U postgres -d "$GTFS_DB" -c "CREATE EXTENSION fuzzystrmatch;"
psql -U postgres -d "$GTFS_DB" -c "CREATE EXTENSION postgis;"
psql -U postgres -d "$GTFS_DB" -c "CREATE EXTENSION postgis_topology;"
psql -U postgres -d "$GTFS_DB" -c "CREATE EXTENSION postgis_tiger_geocoder;"
From http://stackoverflow.com/questions/761327/hidden-features-of-postgresql
Show list of all dbs and their size:
select datname, pg_size_pretty(pg_database_size(datname)) as size
from pg_database;
Connect to db:
\c dbname
Show all tables in a db:
\d
Show size of all tables in db:
select schemaname, relname,
pg_size_pretty(pg_relation_size(schemaname || '.' || relname)) as size
from (select schemaname, relname, 'table' as type
from pg_stat_user_tables
union all
select schemaname, relname, 'index' as type
from pg_stat_user_indexes) x;
Show table schema
\d+ tablename
From http://www.mapbox.com/tilemill/docs/guides/osm-bright-ubuntu-quickstart/.
# Dependencies: imposm
sudo aptitude install build-essential python-dev protobuf-compiler \
libprotobuf-dev libtokyocabinet-dev python-psycopg2 libgeos-c1
sudo apt-get install python-pip
sudo pip install imposm
# Download Mapbox OSM Bright
cd ~/
wget https://github.com/mapbox/osm-bright/zipball/master
unzip master
mv mapbox-osm-bright-14bd07d osm-bright
rm master
Download .pbf osm file from http://metro.teczno.com or http://download.geofabrik.de/osm/. Then import the file into PostGIS with imposm:
imposm -U postgres -d osm -m /root/osm-bright/imposm-mapping.py \
--read --write --optimize --deploy-production-tables <data.osm.pbf>
Set up OSM Bright in ~/osm-bright
cd ~/osm-bright
cp configure.py.sample configure.py
- Change config["importer"] = "osm2pgsql" to config["importer"] = "imposm", unless you prefer to use osm2pgsql and have that set up.
- Optionally change the name of your project from the default, ‘OSM Bright’.
- Adjust the path to point to your MapBox project folder,
/root/Documents/MapBox/project/
. - change the line that says
config["postgis"]["user"] = ""
toconfig["postgis"]["user"] = "postgres"
- Save & close the file.
# Build a project file
./make.py
/usr/share/tilemill/index.js --server=true
Connect to the remove server via ssh (we set up a subdomain maps.albatrossdemos.com
pointing to 54.214.3.211
):
ssh -CA [email protected] -L 20009:localhost:20009 -L 20008:localhost:20008
# now you can access http://localhost:20009 in your local browser
Or, make the instance publically accessible (assign an IP address, create and A record, then make Tilemill listen to the url:
sudo sh -c 'echo export TILEMILL_HOST="maps.albatrossdemos.com" >> /etc/profile'
mkdir /var/log/tilemill/
source /etc/profile
/usr/share/tilemill/index.js --server=true --listenHost=0.0.0.0 --coreUrl=${TILEMILL_HOST}:20009 --tileUrl=${TILEMILL_HOST}:20008
Or run it from a call to forever in crontab. Install forever (npm install forever -g
). Run crontab -e
and add:
@reboot forever "/usr/share/tilemill/index.js --server=true --listenHost=0.0.0.0 --coreUrl=${TILEMILL_HOST}:20009 --tileUrl=${TILEMILL_HOST}:20008' -l=/var/log/tilemill/forever.log -o=/var/log/tilemill/stdout.log -e=/var/log/tilemill/stderr.log"
- Elevation data: http://www.mapbox.com/tilemill/docs/guides/terrain-data/
- Convert from pbf to osm:
./osmconvert norway.pbf >norway.osm