I'm trying to run two wsgi applications, one django and the other tilestache using the same server.
The tilestache server accesses the db via django to query the db.
In the process of serving tiles it performs a transform on the incoming bbox, and in this process hit's the following error. The transform works without error for the specific bbox polygon when run manually from the python shell:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/TileStache/__init__.py", line 325, in __call__
mimetype, content = requestHandler(self.config, environ['PATH_INFO'], environ['QUERY_STRING'])
File "/usr/lib/python2.7/dist-packages/TileStache/__init__.py", line 231, in requestHandler
mimetype, content = getTile(layer, coord, extension)
File "/usr/lib/python2.7/dist-packages/TileStache/__init__.py", line 84, in getTile
tile = layer.render(coord, format)
File "/usr/lib/python2.7/dist-packages/TileStache/Core.py", line 295, in render
tile = provider.renderArea(width, height, srs, xmin, ymin, xmax, ymax, coord.zoom)
File "/var/www/tileserver/providers.py", line 59, in renderArea
bbox.transform(METERS_SRID)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/gis/geos/geometry.py", line 520, in transform
g = gdal.OGRGeometry(self.wkb, srid)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/gis/gdal/geometries.py", line 131, in __init__
self.__class__ = GEO_CLASSES[self.geom_type.num]
File "/usr/local/lib/python2.7/dist-packages/django/contrib/gis/gdal/geometries.py", line 245, in geom_type
return OGRGeomType(capi.get_geom_type(self.ptr))
File "/usr/local/lib/python2.7/dist-packages/django/contrib/gis/gdal/geomtype.py", line 43, in __init__
raise OGRException('Invalid OGR Integer Type: %d' % type_input)
OGRException: Invalid OGR Integer Type: 1987180391
I think I've hit the non thread safe issue with GDAL, metioned on the django site.
Is there a way I could configure this so that it would work?
Apache Version:
Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured
Apache apache2/sites-available/default:
<VirtualHost *:80>
ServerAdmin ironman@localhost
DocumentRoot /var/www/bin
LogLevel warn
WSGIDaemonProcess lbs processes=2 maximum-requests=500 threads=1
WSGIProcessGroup lbs
WSGIScriptAlias / /var/www/bin/apache/django.wsgi
Alias /static /var/www/lbs/static/
</VirtualHost>
<VirtualHost *:8080>
ServerAdmin ironman@localhost
DocumentRoot /var/www/bin
LogLevel warn
WSGIDaemonProcess tilestache processes=1 maximum-requests=500 threads=1
WSGIProcessGroup tilestache
WSGIScriptAlias / /var/www/bin/tileserver/tilestache.wsgi
</VirtualHost>
Django Version: 1.4
httpd.conf:
Listen 8080
NameVirtualHost *:8080
UPDATE
I've added the a test.wsgi script to determine if the GLOBAL interpreter setting is correct, as mentioned by graham and described here:
http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Sub_Interpreter_Being_Used
It seems to show the expected result:
[Tue Aug 14 10:32:01 2012] [notice] Apache/2.2.22 (Ubuntu)
mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Tue Aug 14 10:32:01 2012] [info] mod_wsgi (pid=29891): Attach
interpreter ''.
I've worked around the issue for now by changing the srs used in the db so that the transform is unnecessary in tilestache app.
I don't understand why the transform() method, when called in the django app works, but then in the tilestache app fails.
tilestache.wsgi
#!/usr/bin/python
import os
import time
import sys
import TileStache
current_dir = os.path.abspath(os.path.dirname(__file__))
project_dir = os.path.realpath(os.path.join(current_dir, "..", ".."))
sys.path.append(project_dir)
sys.path.append(current_dir)
os.environ['DJANGO_SETTINGS_MODULE'] = 'bin.settings'
sys.stdout = sys.stderr
# wait for the apache django lbs server to start up,
# --> in order to retrieve the tilestache cfg
time.sleep(2)
tilestache_config_url = "http://127.0.0.1/tilestache/config/"
application = TileStache.WSGITileServer(tilestache_config_url)
UPDATE 2
So it turned out I did need to use a projection other than the google (900913) one in the db. So my previous workaround failed.
While I'd like to fix this issue, I decided to work around the issue this type by making a django view that performs the transform needed. So now tilestache requests the data through the django app and not internally.