Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Installing Tilestache to serve custom ArcGIS layers using Postgres 10 on Ubuntu 16 (Xenial Xerus)

Installing Tilestache to serve custom ArcGIS layers using Postgres 10 on Ubuntu 16 (Xenial Xerus)

Here I share my work notes to get custom layers that were once in ArcGIS to serve on a Ubuntu web host.

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt install curl
  • curl -O -L
  • sudo python
  • sudo pip install -U pillow modestmaps simplejson uuid tilestache
  • Sudo pip install -U werkzeug

Install postgres-10

  • sudo touch /etc/apt/sources.list.d/pgdg.list
  • sudo sh -c 'echo "deb $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
  • sudo apt-get install wget ca-certificates
  • sudo apt-get update
  • sudo apt-get install -y postgresql-10 --allow-unauthenticated
  • sudo apt-get install postgis postgresql-10-postgis-scripts --allow-unauthenticated
    • Make sure you have a database extension control file: find /usr -name postgis.control
  • Install pgRouting 2.3 package -sudo apt-get install -y postgresql-10-pgrouting --allow-unauthenticated

Create a database

  • In order to first interact with postgresql you need to be a user that is in the postgres superusers list. User “postgres”
    • To become the postgres user you need to run: sudo -u postgres psql or sudo -u postgres -i
  • Create a database
    • From the bash shell as the postgres user
      • createdb -E UTF-8 -T template0 <collection_name>
    • From the postgresql cli:
      • CREATE DATABASE <collection_name>;

Creating user

When the postgres database is created it automatically creates the user postgres but you might need to create a second user

  • From Bash:
    • sudo -u postgres createuser
  • From postgres cli:
    • create user superuser password '';

Setting to halt on any errors

  • \set ON_ERROR_STOP on

Giving the user a password

This is needed since the default password for default postgres user is ‘postgres’ From Bash:

  • sudo -u postgres psql


  • ALTER USER with encrypted password ''; or
  • \PASSWORD <postgresql_user>

By this point in time you will have two users, check with

  • \du

Notice how one user ‘postgres’ has many more roles than the new user you just created. We will be fixing that in the next step

Grant database privileges on user

  • psql=#
    • ALTER USER <username> createdb superuser createrole replication bypassrls;

Granting privileges on database

  • psql=#
    • grant all privileges on database to ;

Install extensions on table

  • \connect <database_name>
  • CREATE EXTENSION adminpack;
  • CREATE EXTENSION plpgsql; (Usually already added. As it is a part of the postgres install by default)
  • \quit

As one step in bash:$

  • psql -d <database_name> -c 'CREATE EXTENSION postgis; CREATE EXTENSION hstore; CREATE EXTENSION adminpack;'

Import ArcGIS database

  • sudo apt-get -y install gdal-bin
  • ogr2ogr -f "PostgreSQL" PG:"host=localhost port=5432 dbname=<database_name> user=postgres password=<user_password>" Charlotte.gdb -overwrite -progress --config PG_USE_COPY YES
  • If you want to import select attributes from the database you can filter adding an sql query to the ogr2ogr command
    • sql "SELECT * FROM infile WHERE ID='1'"

Check if it loaded correctly sudo -u postgres psql to open postgres cli

  • \list to see all databases
  • \connect epri
  • \dt to see tables

Download mapnik

Using a combination of steps located here:

Install mapnik

  • sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
  • sudo apt-get update -y
  • sudo apt-get install -y gcc-6 g++-6 clang-3.8
  • export CXX="clang++-3.8" && export CC="clang-3.8"

Harfbuzz needs to be installed before you install boost

Check if its already installed

  • pkg-config --libs --cflags harfbuzz
  • wget
  • tar xvfj harfbuzz-1.4.8.tar.bz2
  • cd harfbuzz
  • ./configure --prefix=/usr --with-gobject && make
  • sudo make install
  • sudo apt-get install python zlib1g-dev clang make pkg-config curl
  • source

Return back to your mapnik folder

  • Make JOBS=6
  • make test
  • Might get an test issue with postgis
  • sudo make install
  • Enable mapnik extensions
  • python scons/ INPUT_PLUGINS='all'

Install TileStache (Tileserver is a WSGI application)

  • wget
    • (V1.51.5 (Jan 25, 2017))
  • tar -xzf v1.51.5.tar.gz
  • cd TileStache-1.51.5
  • sudo apt-get install gdal-bin
  • sudo pip install -U TileStache
  • sudo python install

Run the tileserver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.