4

The CDRC have a range of useful maps online here: https://mapmaker.cdrc.ac.uk - previously they used XYZ Tiles which could be re-used in QGIS easily but the new system uses Vector Tiles hosted on Carto.

I can pull the vectors into QGIS using the standard "Vector Tiles" source, but I can't see how to style them by attribute to generate something like the maps on the site.

I'm creating a new Generic Vector Tile layer with URL:

https://d.gusc.cartocdn.com/oliverobrien/api/v1/map/4c582a80bbcebc635d20d3efc85693fd:1638399714930/{z}/{x}/{y}.mvt

and loading into the layers. That works. I can see the polygons. But I want to style them. I don't have a "Style URL" to put in the "Optional" box so I need to do this manually.

If I use the "Identify Features" tool I can click on features and see the attributes I want to style by...

enter image description here

...but I can't work out how to get those attributes into any styling process.

If I try styling the fill colour by an expression as I might do with a standard vector layer, the expression doesn't show any of these attributes:

enter image description here

In the symbology dialog, I thought I could use a filter rule, but here's a bunch of efforts none of which work, and none of which produce errors either. They either style all the features or none. I've tried various other combinations of things here too (a pointer to a documentation page for the filter syntax would be useful...)

enter image description here

I've also tried looking at labelling these features but I can't get these attributes into the label "Value" field either, so I'm thinking that somehow this can't be done, but its weird that I can see these values in the "Identify Features" tool but nowhere else in QGIS...

[Note I've been in touch with Oliver O'Brien who is behind a lot of the CDRC stuff and he's happy for their data to be re-used in this way]

1
  • I think you will need to create a JSON file that hold the style, you should be able to store it locally and add the location as the "Optional Style URL". Unfortunately I can't help on how to create this (maybe this could help geoslab.com/en/blog/creating-styles-vector-tiles)
    – J.R
    Nov 22, 2022 at 10:31

1 Answer 1

1

You should use a JSON file to properly stylize vector tile.

The URL I used for this example is:

https://undpngddlsgeohubdev01.blob.core.windows.net/admin/adm2_polygons/{z}/{x}/{y}.pbf

Save the following into style.json and load it via the style button in the Symbology tab.

{
  "version": 8,
  "name": "hrea",
  "metadata": {"maputnik:renderer": "mbgljs"},
  "sources": {
    "adm2_polygons": {
      "type": "vector",
      "tiles": [
        "https://undpngddlsgeohubdev01.blob.core.windows.net/admin/adm2_polygons/{z}/{x}/{y}.pbf"
      ],
      "minZoom": 0,
      "maxZoom": 14
    }
  },
  "layers": [
    {
      "id": "small",
      "type": "fill",
      "source": "adm2_polygons",
      "source-layer": "adm2_polygons",
      "minzoom": 0,
      "filter": ["any", ["<", "pop", 500000]],
      "paint": {"fill-color": "#fff541"}
    },
    {
      "id": "mid",
      "type": "fill",
      "source": "adm2_polygons",
      "source-layer": "adm2_polygons",
      "filter": ["all", [">=", "pop", 500000], ["<", "pop", 2000000]],
      "paint": {"fill-color": "#rgba(246 204 54, 1)"}
    },
    {
      "id": "large",
      "type": "fill",
      "source": "adm2_polygons",
      "source-layer": "adm2_polygons",
      "filter": ["any", [">=", "pop", 2000000]],
      "paint": {"fill-color": "#ff7d5d"}
    }
  ],
  "id": "0tmxv7uqt"
}

It will yield soemthing like this:

enter image description here

A nice online editor is: https://maputnik.github.io/editor/#1.37/0/-1.1

4
  • 1
    What's that doing that's different to me manually typing in those filter properties in the layer dialog? I don't think it is. What's the URL of your vector tile source here so I can try and replicate this, or figure out why its different.
    – Spacedman
    Apr 18, 2023 at 15:18
  • Not sure about the difference, but adding the same Filter manually does not work. The interface must be hiding something at the moment... This has been nagging me for a while, too. As for the URL, I edited the answer to highlight it. Apr 18, 2023 at 15:40
  • 1
    Does it work by adding the Filter manually, AND changing the Layer name manually? e.g. in your example change (All layers) to layer0 May 11, 2023 at 12:31
  • 1
    The above worked for me.. I tried with a json style first, which worked. I also then tried adding the filter manually, but I had to also input the layer name manually, then it worked. May 11, 2023 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.