# Importing GeoJSON or WKT to your data model

There are two valid data formats that the visual accepts to display custom geometry in the Features Layer via the Features Layer: WKT or GeoJSON Geometries field well. These geometries need to be properly formatted within your data in order to be displayed on the map.

The instructions on this page describe how to get WKT or GeoJSON data into the Power BI data model in a form that you can add to the map via the Features Layer: WKT or GeoJSON Geometries field well.

{% hint style="warning" %}

### Power BI field length limitation

There is a 32KB limitation imposed by Power BI on field lengths, which means that complex geometries can't be displayed with the method described on this page.
{% endhint %}

{% hint style="info" %}

### Which approach to choose?

In some circumstances it may be preferable to upload your spatial data into the visual instead. See the [Displaying your own geometries within the Power BI Visual page](/more-than-maps/advanced-applications/os-ngd-data-in-dashboards/os-power-bi-map-visual/os-power-bi-map-visual-getting-started-guide/displaying-your-own-geometries-within-the-power-bi-visual.md) for an in-depth look at the differences between the methods.
{% endhint %}

## How to use WKT data to add custom geometry to a map

Because WKT is simply a text-based geometry format, it's quite common that it might be present as a column in an existing table such as a database table or query, or a CSV file.

For example you might have downloaded some data from the [OS Select and Build](https://docs.os.uk/osngd/getting-started/downloading-with-os-select+build) service, selecting the CSV format.

In this case, you can simply add that table to your Power BI data model by selecting *Get Data / Text/CSV* and following the steps to load the CSV file into your data model, and establish appropriate relationships between it and your other queries. You can then add the WKT column straight into the visual.

<figure><img src="/files/e1a8052be19fb0b289f82f286aa968fda586577d" alt="A screenshot of the Features Layer tab showing geom_wkt selected"><figcaption></figcaption></figure>

{% hint style="info" %}

### WKT geometry data

Your data needs to include a column that consists of WKT geometry to display it on the map.

Values in this column might look something like this:

`POLYGON((443676.485 240103.531,443679.085 240104.831,443676.681 240109.636,443674.081 240108.336,443676.485 240103.531))`

The coordinate values must be either latitude / longitude or British National Grid coordinates.

A column like this can be added straight to the *Features Layer: WKT or GeoJSON Geometries* field.
{% endhint %}

## How to use GeoJSON data to add custom geometry to a map

GeoJSON is another text-based format, which can be used to represent geometries (as with WKT, above), or entire features or feature collections (a feature comprises both geometry and attributes).

It's possible to have GeoJSON geometries or features present as a column in an existing table such as a CSV file. In this case, the process for adding the features to the visual is identical to the one for adding WKT as described above.

{% hint style="info" %}

### GeoJSON as an attribute in a table

If you have GeoJSON present as an column in a table, the values in that column might look something like this (this is a GeoJSON geometry):

`{"type": "Polygon", "coordinates": [...]}`

Or something like this (this is a GeoJSON feature, with attributes):

`{"type": "Feature", "properties": {...}, "geometry": ...}`

A column containing values like the above can be added straight to the *Features Layer: WKT or GeoJSON Geometries* field.

If the feature has properties, these will be added to map pop-ups by default, but will be replaced if a column is dragged into the *Features Layer: Pop-ups* field.
{% endhint %}

## Load a GeoJSON file to a Power BI query

It's more likely that you may have a standalone GeoJSON file. The following steps describe how you can import a GeoJSON file into Power BI, to turn it into a table that you can add into the visual by following the steps above.

These instructions may be easier to follow by navigating to the *Add some data* tab on the landing page then looking for the *GeoJSON (from Power BI data model)* section. The landing page can be accessed via the *Question Mark* button in the bottom left. You can copy and paste the necessary code from there.

<figure><img src="/files/pR3nJslHVDrqfIxc3CBV" alt="Getting started with OS Power BI Map Visual Add some data tab" width="563"><figcaption><p>Getting started with OS Power BI Map Visual Add some data tab.</p></figcaption></figure>

{% stepper %}
{% step %}

### Find the GeoJSON file

Go to *Get data* > *JSON* > *Connect* and navigate to your *GeoJSON file*.

This should open your data in query view and your features will be automatically expanded, giving you columns like 'features.geometry.type'.

Performing this action may have expanded your GeoJSON more than necessary, so in the Query Settings panel (probably on the right side of the window), click the cross next to *Expanded features.geometry.coordinates* in *Applied Steps* to remove the step that expands your coordinates.
{% endstep %}

{% step %}

### Make a custom column to drag into the visual's GeoJSON field

In the toolbar at the top, go to *Add Column Custom Column*. In the dialog box, add a name such as '*geom*' and enter the following formula:

{% code title="Formula" %}

```powerquery
{" & """type""" & ":" & """" & [features.geometry.type] & """" & "," & """coordinates""" & ":" & Text.FromBinary(Json.FromValue([features.geometry.coordinates])) & "
```

{% endcode %}

Click *OK*, go back to the Home tab and Close & Apply, then drag your new 'geom' column into the *Features Layer: GeoJSON* or *WKT Geometries field* in Build visual.
{% endstep %}
{% endstepper %}

## Converting your data

You might have geometry in shapefile, GeoPackage, or another format. You can use GIS software such as QGIS to turn those formats into WKT that the visual will accept.

Start by loading your geometry into QGIS by dragging it into the QGIS window. Then, under *Layers*, right-click and select *Export* > *Save Feature as*. Save your file as a CSV, then under *Geometry* you want to select *AS\_ WKT*.

<figure><img src="/files/49d60a836f7da60da83ce72ddfa531c2bfbed410" alt="A screenshot of the Save Vector Layer as dialog box in QGIS"><figcaption><p>Save Vector Layer as dialog box in QGIS.</p></figcaption></figure>

Exporting your file as a CSV will create a file with every polygon listed as a separate entry alongside any additional metadata associated with those polygons from the original file. The WKT column in that CSV is what you’d drag into the Features Layer: GeoJSON or WKT Geometry in the OS Visual to display the geometry.

## Simplifying your data

If you are having problems with the 32KB limitation described previously, you can also use QGIS to simplify your geometry and remove unnecessary precision, which may help to get around the issue.

{% hint style="info" %}

### QGIS alternatives

As an alternative to QGIS, you may be able to use an online service such as [Map Shaper](https://mapshaper.org/) to simplify your data.
{% endhint %}

Start by loading the data into QGIS as described above.

Next you can experiment with simplifying the data to remove unnecessary coordinates. The Simplify tool can be found under *Vector / Geometry Tools / Simplify* in the current version of QGIS. An appropriate 'tolerance' depends on the size of your features and how far you need to be able to zoom in the map. If you are not using Premium zoom levels, then a tolerance of 1 or 2 metres would certainly not result in any visible degradation of the features. At the higher Premium zoom levels, a smaller value may be needed. This may or may not make a difference to the size of your geometries, depending on how much detail was in them to start with.

Next, you can also reduce the precision of the coordinates so that they are stored in the WKT using fewer digits, thereby taking less space. This is a two step process:

1. Firstly export the data to GeoJSON, using an appropriate value for coordinate precision. If the data are in BNG coordinates (metres) there is no benefit in storing numbers to multiple decimal places, so a value of 1 is fine. For data in latitude/longitude coordinates (degrees), a value of 6 would represent [less than 1 metre](https://gis.stackexchange.com/a/8674/10742) so is generally appropriate.

<figure><img src="/files/30d03c0c8610570bd33b1cbb8f6b5c084e6e7eaa" alt="A screenshot of the Save Vector Layer as window showing COORDINATE_PRECISION circled in the Layer Options dropdown."><figcaption><p>A screenshot of the Save Vector Layer as window showing COORDINATE_PRECISION circled in the Layer Options dropdown.</p></figcaption></figure>

2. Next, add the exported GeoJSON back into your QGIS map, and then re-export this to CSV with WKT geometries, following the process described above. You should now find that the geometry coordinates in the file have been rounded, and occupy less space.

If, after following all these steps, you are still unable to add the data to the visual due to the 32KB limitation, we recommend that you load the data using the approach on the [Loading spatial data into the visual page](/more-than-maps/advanced-applications/os-ngd-data-in-dashboards/os-power-bi-map-visual/os-power-bi-map-visual-getting-started-guide/displaying-your-own-geometries-within-the-power-bi-visual/loading-spatial-data-into-the-visual.md) instead.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.os.uk/more-than-maps/advanced-applications/os-ngd-data-in-dashboards/os-power-bi-map-visual/os-power-bi-map-visual-getting-started-guide/displaying-your-own-geometries-within-the-power-bi-visual/importing-geojson-or-wkt-to-your-data-model.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
