# QGIS

QGIS is an open GIS (Geospatial Information System) desktop application that allows you to display, interrogate, visualise and create geospatial information including from geo-centric APIs (for example, a Vector Tiles Service).

{% hint style="info" %}
**QGIS currently does not fully support all the text rotation functions that are supplied in the style JSON files**

Therefore, we've created [custom QGIS stylesheets (QML files)](https://github.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets/tree/main/QGIS%20Stylesheets%20\(QML\)) that respect the correct text rotation functions that you can apply to the OS Vector Tile API.
{% endhint %}

## What you need

* OS Vector Tile API added to an API project in the OS Data Hub with an API Key; see [getting-started-with-an-api-project](https://docs.os.uk/os-apis/core-concepts/getting-started-with-an-api-project "mention") for more information
* QGIS (version 3.22.0 or later)

## Connecting to the API

{% stepper %}
{% step %}
**Set up a new connection**

Once a new project with a base map has been set up, select *Layer* > *Add Layer* > *Add Vector Tile Layer*.

<figure><img src="https://4043944746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEzqrBzRGoJw7nQyLj1W%2Fuploads%2Fgit-blob-4541e0a598a4e3a5540351d1ac3d950aa77d2cc6%2FStep%202%20-%20Add%20VT%20Layer.png?alt=media" alt="QGIS UI with the Add Vector Tile Layer option selected."><figcaption><p>QGIS UI with the Add Vector Tile Layer option selected.</p></figcaption></figure>
{% endstep %}

{% step %}
**Create a new connection**

In the Data Source Manager | Vector Tile dialog:

* Click *New*.
* Select *New Generic Connection*...

<figure><img src="https://4043944746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEzqrBzRGoJw7nQyLj1W%2Fuploads%2Fgit-blob-ad51137150797f60c4d646031d0513fb34e31b54%2FStep%203%20-%20VT%20Connections.png?alt=media" alt="QGIS Data Source Manager | Vector Tile dialog."><figcaption><p>QGIS Data Source Manager | Vector Tile dialog.</p></figcaption></figure>

In the Vector Tile Connection dialog:

* **Name**: Provide a name for the connection.
* **Style URL**: Input the [Retrieve Style](https://docs.os.uk/os-apis/accessing-os-apis/technical-specification#vts-resources-styles) request URL for the OS Vector Tile API.
* **Source URL**: Input the [Retrieve Tile](https://docs.os.uk/os-apis/accessing-os-apis/technical-specification#vts-tile-z-y-x-.pbf) request URL for the OS Vector Tile API.
* **Min. and Max. Zoom Levels**: Set these as follows:
  * **Web Mercator (EPSG: 3857)**: Min. Zoom Level = 6; Max. Zoom Level = 19
* **Authentication**: Leave these settings at their defaults.
* **Other**: Leave all other settings at their defaults.
* Click *OK*.

{% hint style="info" %}
To retrieve tiles and style them appropriately, you will need two URLs. The URLs have slight variations based on the tileset and projection.

Here are some example URLs to retrieve the basemap in **Web Mercator (EPSG: 3857)**:

* [https://api.os.uk/maps/vector/v1/vts/tile/{z}/{y}/{x}.pbf?srs=3857\&key=](https://api.os.uk/maps/vector/v1/vts/tile/%7Bz%7D/%7By%7D/%7Bx%7D.pbf?srs=27700\&key=){INSERT\_YOUR\_API\_KEY}
* [https://api.os.uk/maps/vector/v1/vts/resources/styles?srs=3857\&key=](https://api.os.uk/maps/vector/v1/vts/tile/%7Bz%7D/%7By%7D/%7Bx%7D.pbf?srs=3857\&key=){INSERT\_YOUR\_API\_KEY}

To learn more about the data available in OS Vector Tile API, please see the ['What data is available?' page](https://docs.os.uk/os-apis/accessing-os-apis/os-vector-tile-api/what-data-is-available).
{% endhint %}

<figure><img src="https://4043944746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEzqrBzRGoJw7nQyLj1W%2Fuploads%2Fgit-blob-35071cce6999e562cb7970c62bbe0864eeb45881%2FQGIS%20Add%20VT%20Connection.png?alt=media" alt="QGIS Vector Tiles Connection dialog."><figcaption><p>QGIS Vector Tiles Connection dialog.</p></figcaption></figure>
{% endstep %}

{% step %}
**Add a layer**

Navigate to *Layer > Data Source Manager > Vector Tile*.

In the Data Source Manager | Vector Tile dialog:

* Select your new connection to OS Vector Tile API.
* Click *Add*.

\_The layer will then display in the Layers panel and the data will display on the map:

<figure><img src="https://4043944746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEzqrBzRGoJw7nQyLj1W%2Fuploads%2Fgit-blob-034307ae8aa52f60315f7e2115905039d13ee505%2Fimage.png?alt=media" alt="QGIS UI showing rendered Vector Tile layer"><figcaption><p>QGIS UI showing OS Vector Tile API in the map area.</p></figcaption></figure>
{% endstep %}
{% endstepper %}

## Add a custom style

{% stepper %}
{% step %}
**Find a style**

Once you have an existing OS Vector Tile API connection, go to the [OS-Vector-Tile-API Stylesheets Repo in GitHub](https://github.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets) and select the required style file.
{% endstep %}

{% step %}
**Get a Style URL**

With the custom stylesheet file open:

* Click *Raw* (a new window will open).
* Copy the URL to link to the style JSON file.

<figure><img src="https://4043944746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEzqrBzRGoJw7nQyLj1W%2Fuploads%2Fgit-blob-7de40f234d84d943ffec9cabe08a701f4294ade6%2FQGIS%20Get%20Style%20URL.png?alt=media" alt="A  style file open on GitHub with the Raw button highlighted."><figcaption><p>GitHub UI with a custom stylesheet file open and the Raw button highlighted.</p></figcaption></figure>
{% endstep %}

{% step %}
**Update the Style URL connection**

In QGIS, open the Data Source Manager | Vector Tile dialog and click \_Edit.

<figure><img src="https://4043944746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEzqrBzRGoJw7nQyLj1W%2Fuploads%2Fgit-blob-e18af8e4d9f519221a92dd5c37997d939b4e2832%2FQGIS%20Edit%20connection.png?alt=media" alt="Data Source Manager | Vector Tile dialog"><figcaption><p>QGIS Data Source Manager | Vector Tile dialog.</p></figcaption></figure>

In the Vector Tiles Connection dialog:

* Replace the Style URL with the URL to the custom style JSON.
* Click *OK*.

<figure><img src="https://4043944746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEzqrBzRGoJw7nQyLj1W%2Fuploads%2Fgit-blob-1083ea7eb20ffb4c8139248b57b911ba450965fd%2FQGIS%20Update%20Style%20URL.png?alt=media" alt="QGIS Vector Tiles Connection dialog"><figcaption><p>QGIS Vector Tiles Connection dialog.</p></figcaption></figure>
{% endstep %}
{% endstepper %}
