Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QGis raster layer as background layer #71

Open
TNick opened this issue Oct 9, 2023 · 5 comments
Open

QGis raster layer as background layer #71

TNick opened this issue Oct 9, 2023 · 5 comments

Comments

@TNick
Copy link

TNick commented Oct 9, 2023

I have a QGis project saved in the PostgreSql with three layers saved in the same database (two vector layers and a raster layer). As it is the webapp shows the three layers inside the theme and renders the map without issue.

I would like the raster layer to be a background layer (not show up in the list of theme layers, show up as a background layer).

From other answers elsewhere I take the hint that I should use a relative path but can't seem to find a good example for that. The same issue seems to suggest that I should create a separate theme (project) for the raster layer, maybe.

@manisandro
Copy link
Member

You can define a backgroundLayer with just the one layername from your QGIS project and then define the same layer as a printLayer. This way, it will not appear in the QWC2 layer tree, will appear in the background layer selection, and will be used as a background when printing.

Something along the lines of this very minimal example should work:

{
  "themes": {
    "items": [
      {
        "url": "/ows/my_project",
        "backgroundLayers": [
          {"name":"my_bg_layer","printLayer":"qgis_layer_name"}
        ],
        "mapCrs": "EPSG:XXXX"
      }
    ],
    "backgroundLayers": [
      ,
      {
        "type":"wms",
        "url":"/ows/my_project",
        "name":"my_bg_layer",
        "srs":"EPSG:XXXX",
        "params":{"LAYERS":"qgis_layer_name"}
      }
    ]
  }
}

@TNick
Copy link
Author

TNick commented Oct 11, 2023

That works beautifully, thank you.

What if I want to use wmts? When adding it like a regular raster layer all I had to do was to add "tiled": true, inside theme definition, so I assume some behind-the-scene magic happens. However, simply changing the type in the background layer definition was not enough. I assume I have to manually provide tileMatrixPrefix, tileMatrixSet, originX, originY, resolutions and tileSize?

@TNick
Copy link
Author

TNick commented Oct 11, 2023

I did some more digging:

  • in the host machine I copied the wmts_config_generator.py utility from QWC2 project into volumes/qgs-resources/scripts/wmts_config_generator.py
  • for some reason I cannot enable port mapping so that port 80 from qgis server si available on host machine
  • docker exec -it qwc-qgis-server-1 sh to get into qgis server prompt
  • python3 data/scripts/wmts_config_generator.py "http://127.0.0.1/ows/pg/public/MAPNAME?SERVICE=WMTS&REQUEST=GetCapabilities" LAYER_NAME "EPSG:XXXX"
  • the layer is not found
  • I modified wmts_config_generator.py so that it prints the layer it found; if finds no layer
  • in the QGis project that hosts the layer you need to make sure that WMTS is enabled for that layer (project properties -> QGis Server -> WMTS tab)
  • now the wmts_config_generator.py utility generates a configuration which I merged with the previous hint, resulting:
            {
                "url": "/ows/pg/public/2020-10-07-background",
                "srs": "EPSG:3844",
                "type": "wmts",
                "params":{
                    "LAYERS": "ortofotoplan_2021"
                },
                "title": "Ortofotoplan 2021",
                "name": "ortofotoplan_2021",
                "format": "image/png",
                "requestEncoding": "KVP",
                "tileMatrixPrefix": "",
                "tileMatrixSet": "EPSG:3844",
                "originX": 1396130.211,
                "originY": -334742.867,
                "projection": "EPSG:3844",
                "tileSize": [
                  256,
                  256
                ],
                "style": "default",
                "bbox": {
                  "crs": "EPSG:4326",
                  "bounds": [
                    25.523214,
                    46.557917,
                    25.825315,
                    46.884994
                  ]
                },
                "resolutions": [
                  6963.833519999999,
                  3481.9167599999996,
                  1740.9583799999998,
                  870.4791899999999,
                  435.23959499999995,
                  217.61979749999998,
                  108.80989874999999,
                  54.404949374999994,
                  27.20247468764,
                  13.601237343679998,
                  6.800618671839999,
                  3.4003093359199994,
                  1.7001546679599997,
                  0.85007733412,
                  0.42503866692,
                  0.21251933359999997,
                  0.10625966679999999,
                  0.05312983339999999,
                  0.02656491656
                ],
                "thumbnail": "ortofotoplan_2021.jpg"
            },

However, something is off, as the background tiles are empty. I see requests like these, return code is 200 but there's no content.

https://voslabeni.advaita.ro/ows/pg/public/2020-10-07-background
  ?layer=ortofotoplan_2021
  &style=default
  &tilematrixset=EPSG%3A3844
  &Service=WMTS
  &Request=GetTile
  &Version=1.0.0
  &Format=image%2Fpng
  &TileMatrix=16
  &TileCol=-31242
  &TileRow=-33306

@manisandro
Copy link
Member

Note that tiled: true just enables tiling mode in WMS, it is not a WMTS. If you want to enable tiling mode in your background layer, you can add TILED=1 to the params. If you want to use WMTS proper, you'll need to set up a tile cache.

@TNick
Copy link
Author

TNick commented Oct 12, 2023

Thank you for your reply.

Setting TILED inside params to 1 or true seems to have no effect. The request is for the full width and TILED parameter is false.

            {
                "url": "/ows/pg/public/project-name",
                "srs": "EPSG:3844",
                "type": "wms",
                "params":{
                    "LAYERS": "ortofotoplan_2021",
                    "TILED": true
                },
                "title": "Ortofotoplan 2021",
                "name": "ortofotoplan_2021"
            }

Setting it outside to true (not 1) causes the request to have the TIELD parameter true but there is a single request for the whole background (not tiled). Setting tileSize (borrowed from other background layer def) in params and outside did not help.

            {
                "url": "/ows/pg/public/project-name",
                "srs": "EPSG:3844",
                "type": "wms",
                "params":{
                    "LAYERS": "ortofotoplan_2021",
                    "tileSize": [
                        256,
                        256
                    ]
                },
                "title": "Ortofotoplan 2021",
                "name": "ortofotoplan_2021",
                "tiled": true,
                "tileSize": [
                    256,
                    256
                ]
            },

Regarding your second point, I would expect the tile cache to be transparent (in the sense that the request would look the same, the web app would be oblivious about the existence of a cache between it and the server), right? While inefficient, the QGis server should reply with png tiles. What I get is an empty response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants