我有一个带有 ansible 配置脚本的 Vagrant 环境,它使用 Mapnik + Postgis + TileStache + uWSGI + Nginx 提供了一个全新的 Ubuntu 16.04 服务器,用于提供地图切片。
半年前,一切正常。现在,在启动 Vagrant 容器之后,配置步骤工作正常,所有 osm2pgsql 导入工作正常,我的 TileStache 发出 hello,这表明 nginx -> uwsgi -> tilestache 正在工作。
我已经尝试测试 PIL/pillow 是否有效。像下面这样的简单脚本完全可以工作:
from PIL import Image
import io
with open('test.png') as f:
io = io.BytesIO(f.read())
im = Image.open(io)
我的tilestache配置:
{
"cache": {
"name": "Disk",
"path": "./cache/",
"umask": "0000"
},
"layers": {
"osm_layer": {
"provider": {
"name": "proxy",
"url": "http://tile.openstreetmap.org/{Z}/{X}/{Y}.png"
}
}
}
}
但是当我尝试访问这样的平铺图像时:http://localhost/osm_layer/0/0/0.png它不起作用。通常这应该给我与http://tile.openstreetmap.org/0/0/0.png相同的图块
我的日志文件中出现以下错误:
Jun 26 09:07:16 gis uwsgi[31478]: Traceback (most recent call last):
Jun 26 09:07:16 gis uwsgi[31478]: File "/usr/lib/python2.7/dist-packages/TileStache/__init__.py", line 379, in __call__
Jun 26 09:07:16 gis uwsgi[31478]: status_code, headers, content = requestHandler2(self.config, path_info, query_string, script_name)
Jun 26 09:07:16 gis uwsgi[31478]: File "/usr/lib/python2.7/dist-packages/TileStache/__init__.py", line 255, in requestHandler2
Jun 26 09:07:16 gis uwsgi[31478]: status_code, headers, content = layer.getTileResponse(coord, extension)
Jun 26 09:07:16 gis uwsgi[31478]: File "/usr/lib/python2.7/dist-packages/TileStache/Core.py", line 414, in getTileResponse
Jun 26 09:07:16 gis uwsgi[31478]: tile = self.render(coord, format)
Jun 26 09:07:16 gis uwsgi[31478]: File "/usr/lib/python2.7/dist-packages/TileStache/Core.py", line 500, in render
Jun 26 09:07:16 gis uwsgi[31478]: tile = provider.renderTile(width, height, srs, coord)
Jun 26 09:07:16 gis uwsgi[31478]: File "/usr/lib/python2.7/dist-packages/TileStache/Providers.py", line 250, in renderTile
Jun 26 09:07:16 gis uwsgi[31478]: tile = Verbatim(body)
Jun 26 09:07:16 gis uwsgi[31478]: File "/usr/lib/python2.7/dist-packages/TileStache/Providers.py", line 164, in __init__
Jun 26 09:07:16 gis uwsgi[31478]: self.format = self.image().format
Jun 26 09:07:16 gis uwsgi[31478]: File "/usr/lib/python2.7/dist-packages/TileStache/Providers.py", line 170, in image
Jun 26 09:07:16 gis uwsgi[31478]: self._image = Image.open(self.buffer)
Jun 26 09:07:16 gis uwsgi[31478]: File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 2295, in open
Jun 26 09:07:16 gis uwsgi[31478]: % (filename if filename else fp))
Jun 26 09:07:16 gis uwsgi[31478]: IOError: cannot identify image file <StringIO.StringIO instance at 0x7f513b7f5a28>
Jun 26 09:07:16 gis uwsgi[31478]: [pid: 31484|app: 0|req: 3/6] 192.168.20.1 () {42 vars in 681 bytes} [Wed Jun 26 09:07:16 2019] GET /osm_layer/0/0/0.png => generated 0 bytes in 138 msecs (HTTP/2.0 500) 0 headers in 0 bytes (0 switches on core 0)
似乎相应的包、图像文件或 PIL/pillow 包存在问题,因为要重现错误,仅代理 OSM 瓦片就足够了。目前不涉及矢量导入或 postgres。这些 OSM 瓦片被代理到http://tile.openstreetmap.org/ {Z}/{X}/{Y}.png
我还可以看到tilestache 创建了缓存目录结构,但是由于存在IOError,因此没有缓存实际的图块/图像。