Skip to content

Instantly share code, notes, and snippets.

@edmundophie
Last active September 1, 2015 15:49
Show Gist options
  • Save edmundophie/df4ab34998dfcb6cf19a to your computer and use it in GitHub Desktop.
Save edmundophie/df4ab34998dfcb6cf19a to your computer and use it in GitHub Desktop.

TileStache Installation Reference (Ubuntu 12.04)

https://gist.github.com/tomay/8657441

TileStache Documentation

http://tilestache.org/doc/

About Mapshaper.org

Mapshaper.org is a powerful tool to convert .shp to geojson/topojson and viceversa. Some of other mapshaper.org features are:

  • Simplify geometry in order to reduce the file size
  • Filter and rename geometry properties

Inserting a Map Data to the Database

What you will need:
  • Map Data in .shp and its companion file (.shx and .dbf)

N.B:

  • .shx and .dbf file are important. It contains the properties of each area like the area name, etc.
  • If the map data is in geojson or topojson file then you must convert it first to a shapefile using mapshaper.org.
How to insert:
  1. Put your .shp and its companion file (.shx and .dbf) within the same folder
  2. Move/copy them to a temporary folder in /etc/myfolder (You can delete this folder later after finished)
  3. Login as postgres user using sudo su - postgres command
  4. Type command shp2pgsql -s 900913:4326 /etc/myfolder/SHAPEFILE_NAME.shp SCHEMA.TABLE | psql -h HOSTNAME -d DATABASE_NAME -U USER
  5. Done

N.B:

  • In order to be displayed properly map data need to be projected in mercator projection (SRID 4326). So make sure your shapefile is projected in mercator.
  • If not then you can project it to mercator by using the specified shp2pgsql command above (highlight the parameter 900913:4326) where 900913 is the origin SRID and 4326 is the targeted SRID.
  • Take a look at this cheatsheet to understand more about the paramater in shp2pgsql.
How to check if the data has been inserted to DB:
  1. Login as postgres user using sudo su - postgres command
  2. Type psql command to enter the postgresql sql mode
  3. Type \c db_name_where_data_inserted to connect to the DB
  4. Type select * FROM SCHEMA.TABLE LIMIT 1 to view the DB content
  5. If you able to see a record then it has been inserted successfully (Sometime you can only see the header due to console mode limitation)

Brief Explanation About TileStache

  • To start tilestache type tilestache-server.py -c /Path/to/configfile.cfg in the console
  • Last time I put the config file in /etc/TileStache/tilestache.cfg
  • You can read the explanation about the config file in the tilestache documentation

Map Data Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment