dynamic tilestache.cfg file based on url parameters

25 views
Skip to first unread message

isbhod

unread,
Aug 31, 2018, 11:48:06 AM8/31/18
to Tilestache
Is it possible, via apache and mod_wsgi to read a url parameter and use that to write a tilestach.cfg file before calling "application = TileStache.WSGITileServer('/tmp/tilestach.cfg')?

My goal is to server personalized maps to several users.  The user settings are saved to a postgresql DB, which are read by dynamically generated mapnik XML.  My issue is an every growing tilestache.cfg file that needs to be read each time a user updates a map setting.   Currently I am reading a rather large and growing  tilestache.cfg file from s3.  This file is written each time there is a new user.  But this file must be read each time a tile is served and as the .cfg file gets longer and longer it is slowing down tile serving.  So my hope is to just dynamically generate the tilestache.cfg file each time and only for that particular user.  Currently each user is list as a layer in the tilestach.cfg, but each layer has the same settings.  I am looking to use a url like this: "https://myTileStacheServer.com/tiles/username/18/63397/94350.png?layer=username


I tired sending the tilestache.cfg as json in the .wsgi file "application=TileStache.WSGITileServer(json)", but that gives me "IOError: [Errno 2] No such file or directory:..." error.

I tried:
from urlparse import parse_qs
import os, TileStache

def application(environ,start_response):
   
params=parse_qs(environ['QUERY_STRING'])
    layer
=params.get('layer',[None])[0]
    cfg
="{\"cache\": {\"name\": \"Test\",\"path\": \"file:///tmp/stache\",\"umask\": \"0000\"},\"layers\": {\""+layer+"_mini\": {\"provider\": {\"name\": \"mapnik\",\"mapfile\": \"http://URLOfMyTilestacheServer/dynamicMapnikMiniXML.php?layer="+layer+"\"},\"projection\": \"spherical mercator\",\"bounds\": {\"north\": 89,\"west\": -180,\"south\": -89,\"east\": 180,\"low\": 0,\"high\": 40},\"png options\": {\"optimize\": true}},\""+layer+"\": {\"provider\": {\"name\": \"mapnik\",\"mapfile\": \"http://URLOfMyTilestacheServer/dynamicMapnikXML.php?layer="+layer+"\"},\"projection\": \"spherical mercator\",\"bounds\": {\"north\": 89,\"west\": -180,\"south\": -89,\"east\": 180,\"low\": 0,\"high\": 40},\"png options\": {\"optimize\": true}}}}"
    f
=open('/tmp/tilestache.cfg','w')
    f
.write(cfg)
    f
.close()
   
TileStache.WSGITileServer('/tmp/tilestache.cfg')


But the above gives me "Exception occurred processing WSGI script '/var/www/wsgi/tilestache.wsgi'." ... "TypeError: 'NoneType' object is not iterable"

The "./tmp/tielstache.cfg' file is written  and is readable, but I am complete novice with python, and barely knowledgeable with wsgi and tilestache, so any help with this would be greatly appreciated.


Thank you,
-N8
Reply all
Reply to author
Forward
0 new messages