sources
- https://github.com/migurski/TileStache
- for PIL workaround http://obroll.com/install-python-pil-python-image-library-on-ubuntu-11-10-oneiric/
- https://github.com/mapnik/mapnik/wiki/UbuntuInstallation
- http://www.axismaps.com/blog/2012/01/dont-panic-an-absolute-beginners-guide-to-building-a-map-server/
sudo apt-get install python-software-properties
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:cartodb/gis
sudo add-apt-repository ppa:mapnik/nightly-2.2
sudo aptitude update
sudo aptitude upgrade
sudo apt-get install git
sudo apt-get install apache2
sudo apt-get install build-essential
sudo apt-get install python-setuptools python-dev python2.7-dev libpq-dev
sudo apt-get install libapache2-mod-python
sudo apt-get install gdal-bin libgdal1-dev
sudo apt-get install libgeos-c1 libgeos-dev
sudo apt-get install postgresql-9.1 postgresql-client-9.1 postgresql-contrib-9.1 postgresql-server-dev-9.1
sudo nano /etc/postgresql/9.1/main/pg_hba.conf
# Scroll down to the bottom of the file and change the
# words ident and md5 to “trust” (there should be 3).
cd /usr/local/src
wget http://download.osgeo.org/postgis/source/postgis-2.0.2.tar.gz
tar xzf postgis-2.0.2.tar.gz
cd postgis-2.0.2
./configure --with-raster --with-topology
make
make install
# add bin to path
export PATH=/usr/lib/postgresql/9.1/bin/:$PATH
# create and run setup script
touch /var/lib/postgresql/config_db.sh
nano /var/lib/postgresql/config_db.sh
#!/usr/bin/env bash
POSTGIS_SQL_PATH=/usr/share/postgresql/9.1/contrib/postgis-2.0
createdb -E UTF8 template_postgis
createlang -d template_postgis plpgsql
psql -d postgres -c \ "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis'"
psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/legacy.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/rtpostgis.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/topology.sql
psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
sudo su - postgres
bash config_db.sh
# confirm template exists with
psql --command="\l"
exit
# install boost (q: with suggests? --install-suggests, a: so far seems ok without)
sudo apt-get install libboost1.49-dev
# then install mapnik
sudo apt-get install libmapnik-dev python-mapnik mapnik-utils
# can test with
python
import mapnik
easy_install pip
sudo pip install -U werkzeug
sudo pip install -U simplejson
sudo pip install -U modestmaps --allow-external modestmaps --allow-unverified modestmaps
sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib
now install PIL itself
sudo pip install -U pil
but since this still fails, do this instead (this package should include PIL per this post)
sudo apt-get install python-imaging
git clone https://github.com/migurski/TileStache
cd TileStache
Step 12. Install TileStache globally and add a couple of additional dependencies (see this)
sudo python setup.py install
sudo pip install -U shapely
sudo pip install -U psycopg2
sudo nano /etc/apache2/conf.d/httpd.conf
add this (headers is an addition to allow cross-domain requests, NOTE: * may not be secure):
<Directory /var/www/tiles>
AddHandler mod_python .py
PythonHandler TileStache::modpythonHandler
PythonOption config /etc/TileStache/tilestache.cfg
Header set Access-Control-Allow-Origin "*"
</Directory>
For more on CORS see this page
now
# Altering headers requires the use of mod_headers. Mod_headers is enabled by default in Apache, however, you may want to ensure it's enabled by running:
a2enmod headers
# then check config for errors, and if ok, restart/reload apache with
apachectl -t
sudo service apache2 reload
then
mkdir /var/www/tiles
shutdown -r now # reboot changes
http://192.241.206.80/tiles/tiles.py/osm/preview.html
http://192.241.206.80/tiles/tiles.py/example/preview.html
sudo /etc/init.d/apache2 restart
- First make sure data are projected in Spherical Mercator
- Spherical Mercator EPSG:900913 (EPSG:3857) # went with latter 900913 wouldn't display
- Reproject in QGIS
- or use ogr2ogr
ogr2ogr -t_srs epsg:900913 shapes/parcels_with_history_merc.shp shapes/parcels_with_history.shp
createdb parcel_data -U postgres
psql -d parcel_data -U postgres
parcel_data# CREATE EXTENSION postgis;
CREATE EXTENSION
parcel_data# CREATE SCHEMA sf;
CREATE SCHEMA
shp2pgsql -I -s 900913 parcels_with_history_merc.shp sf.parcels | psql -d parcel_data -U postgres
{
"cache":
{
"name": "Test",
"path": "/tmp/stache",
"umask": "0000"
},
"layers":
{
"osm":
{
"provider": {"name": "proxy", "provider": "OPENSTREETMAP"},
"png options": {"palette": "http://tilestache.org/example-palette-openstreetmap-mapnik.act"}
},
"example":
{
"provider": {"name": "mapnik", "mapfile": "examples/style.xml"},
"projection": "spherical mercator"
},
"parcels_vec": {
"allowed origin": "*",
"provider": {
"class": "TileStache.Goodies.VecTiles:Provider",
"kwargs": {
"dbinfo": {
"host": "localhost",
"user": "postgres",
"database": "parcel_data"
},
"queries": [
"SELECT gid, geom AS __geometry__ FROM sf.parcels"
]
}
}
},
"parcels_utf":
{
"provider":
{
"name": "mapnik grid",
"mapfile": "mapnik_styles/parcels_utf.xml",
"fields": ["MAPBLKLOT"]
},
}
}
}
<?xml version="1.0"?>
<!-- An ultra simple Mapnik stylesheet -->
<!DOCTYPE Map [
<!ENTITY google_mercator "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
]>
<Map srs="&google_mercator;">
<Style name="style">
<Rule>
<PolygonSymbolizer />
</Rule>
</Style>
<Layer name="layer" srs="&google_mercator;">
<StyleName>style</StyleName>
<Datasource>
<Parameter name="table">
select gid from sf.parcels
</Parameter>
<Parameter name="type">postgis</Parameter>
<Parameter name="port">5432</Parameter>
<Parameter name="user">postgres</Parameter>
<Parameter name="dbname">parcel_data</Parameter>
</Datasource>
</Layer>
</Map>