如何缓存QGIS Server WMS?

Ben*_*imo 5 qgis tilestache openlayers-3

看起来栅格图块已经开始过时了,但是,我仍然需要一个解决方案,以某种方式为我的QGIS Server的WMS做.

到目前为止,我已经尝试过TileCache,但是我无法让它在OL3中工作,而且它似乎也有点"古老".

那么什么是我的最佳出价,如果以后我想在我的OL3应用程序中使用缓存层?TileStache,Mapproxy,MapCache?

我的QGIS Server在CentOS 7下运行.

jgr*_*cha 4

QGIS Server 与MapProxy配合良好。使用 QGIS Server+MapProxy,您将获得最好的 QGIS 样式以及切片缓存的速度。

MapProxy 是用 Python 编写的,您可能已经在服务器上安装了 Python。您可以(并且应该)在虚拟环境中运行 MapProxy。MapProxy 的说明非常清晰,启动并运行它并从 QGIS Server 获取数据实际上只需要几分钟的时间。

  1. 它比 GeoWebCache 轻得多
  2. 它缓存并提供图块(仅tiled: true在您的 WMS 请求中使用)
  3. 它与 OpenLayers 配合得很好。安装后,您将获得一个演示页面,其中包含 OpenLayers 示例。
  4. 您可以针对缓存的源调用 GetFeatureInfo 请求
  5. 您可以针对缓存的源调用 GetLegendGraphic 请求
  6. 它可以处理自定义网格(只要您在 OpenLayers 中使用相同的网格)
  7. 您可以并行请求多个图块并利用 QGIS Server 并行渲染支持(如果启用)。
  8. 由于QGIS Server可以将项目存储在Postgis上,因此您可以轻松更新项目而无需任何上传。MapProxy 将使用 QGIS Server 更新的样式。

例子

MapProxy 文档中有非常好的小示例。

这是最复杂的示例之一,因为它使用自定义网格和 CRS,而不是 EPSG:3857。如果使用常用的GLOBAL_MERCATOR网格,那就简单多了(在MapProxy端和OpenLayers端)。

这是mapproxy.yaml配置文件的一个小示例,带有自定义网格。来源是QGIS Server。我添加了一个GetFeatureInfo鼠标单击请求,以显示如何将这些请求转发到 QGIS Server。我还添加了图层的图例(使用service=WMS&REQUEST=GetLegendGraphic&VERSION=1.3.0)。

layers:
  - name: caop
    title: CAOP by QGIS Server
    sources: [caop_cache_continente]
caches:
  caop_cache_continente:
    meta_size: [4, 4]
    meta_buffer: 20
    # 20+4x256+20
    # width=1064&height=1064
    use_direct_from_level: 14
    concurrent_tile_creators: 2
    link_single_color_images: true
    grids: [continente]
    sources: [continente_wms]
sources:
  continente_wms:
    type: wms
    wms_opts:
      featureinfo: true
      legendgraphic: true
    req:
      url: http://continente.qgis.demo/cgi-bin/qgis_mapserv.fcgi
      layers: freguesia
      transparent: true
grids:
  continente:
    srs: 'EPSG:3763'
    bbox_srs: 'EPSG:3763'
    bbox: [-127104, -301712, 173088, 278544]
    origin: nw
    res: [ 1172.625, 586.3125, 293.15625, 146.578125, 73.2890625, 36.64453125, 18.322265625, 9.1611328125, 4.58056640625, 2.290283203125, 1.1451416015625, 0.57257080078125, 0.286285400390625, 0.1431427001953125, 0.07157135009765625 ]
Run Code Online (Sandbox Code Playgroud)

以下 OpenLayers 文件能够从 MapProxy 获取图块。

layers:
  - name: caop
    title: CAOP by QGIS Server
    sources: [caop_cache_continente]
caches:
  caop_cache_continente:
    meta_size: [4, 4]
    meta_buffer: 20
    # 20+4x256+20
    # width=1064&height=1064
    use_direct_from_level: 14
    concurrent_tile_creators: 2
    link_single_color_images: true
    grids: [continente]
    sources: [continente_wms]
sources:
  continente_wms:
    type: wms
    wms_opts:
      featureinfo: true
      legendgraphic: true
    req:
      url: http://continente.qgis.demo/cgi-bin/qgis_mapserv.fcgi
      layers: freguesia
      transparent: true
grids:
  continente:
    srs: 'EPSG:3763'
    bbox_srs: 'EPSG:3763'
    bbox: [-127104, -301712, 173088, 278544]
    origin: nw
    res: [ 1172.625, 586.3125, 293.15625, 146.578125, 73.2890625, 36.64453125, 18.322265625, 9.1611328125, 4.58056640625, 2.290283203125, 1.1451416015625, 0.57257080078125, 0.286285400390625, 0.1431427001953125, 0.07157135009765625 ]
Run Code Online (Sandbox Code Playgroud)