我正在使用mapnik以PDF格式呈现地图,而且我遇到了一个混乱的问题。
def writeFile(m, mapId):
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename=test.pdf'
map_surface = cairo.PDFSurface(response, 1200, 700)
map_ctx = cairo.Context(map_surface)
mapnik.render(m, map_ctx)
legend = createLegend(map_ctx, mapId)
map_surface.finish()
return response
我们正在使用Django。以上功能在我的联合开发人员的计算机上正常工作,但在我的计算机上崩溃了。问题在于mapnik.render()
功能。我最终得到以下错误:
python: /build/buildd/cairo-1.12.2/src/cairo.c:301: cairo_destroy: Assertion `((*&(&cr->ref_count)->ref_count) > 0)' failed.
Aborted
当我用mapnik.render(m, map_surface)
切换它时,它可以正常工作。我尝试卸载然后重新安装正确的库(libcairo2-dev,python-cairo,libmapnik,mapnik-utils),但没有任何工作。
任何帮助将不胜感激。
编辑:
无意中解决了这个问题。已安装的tilemill,与mapnik捆绑在一起
sudo add-apt-repository ppa:developmentseed/mapbox
sudo apt-get update
sudo apt-get install tilemill libmapnik nodejs
Mapnik版现在是2.2.0-pre