# Working with tiled data

Tiled orders allow you to select a small region of Great Britain (GB), rather than having to order the whole of GB. Ordering tiles, as opposed to full GB coverage, reduces the amount of data supplied. This reduces data storage size and the time it takes to process the data.

AddressBase Core tiles can be downloaded through Ordnance Survey’s download service. See [Downloading a dataset](https://docs.os.uk/os-downloads/products/addresses-and-names-portfolio/addressbase-core/addressbase-core-getting-started-guide/downloading-a-dataset) for full details about accessing this service. To order tiles:

1. Access the OS orders site and select *AddressBase Core – 5km DOWNLOAD*.
2. Select either a self-drawn polygon, a rectangle or a postcode/place. These options are available in the toolbar above the map. Once you have selected your area of interest (AOI), you can proceed to place your order.\\

   <figure><img src="https://1897589978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNpJpLP8RROUaWVQo5ea%2Fuploads%2FxEbLlU664gmrhDml7Gu8%2Fimage.png?alt=media&#x26;token=84d15bec-94c6-4b54-a322-067cd9b58f93" alt="Toolbar about map for selecting an AOI in OS Data Hub"><figcaption><p>Toolbar about map for selecting an AOI in OS Data Hub</p></figcaption></figure>

Dependent on whether you are a PSGA customer or an OS Partner, the tiles are supplied as either GPKG or CSV.

You are provided with all 5km tiles that intersect the drawn polygon. The diagram below shows what is supplied when completing a tile order. An area of interest is drawn (blue lines) and a tile is provided for anywhere the drawn area of interest intersects (green lines).

For a GPKG download, you receive tiled data incorporated into one single GPKG file. For CSV tile supplies, individual 5km tiles are supplied for each tile which intersects your AOI.

<figure><img src="https://1897589978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNpJpLP8RROUaWVQo5ea%2Fuploads%2FHNLtjrOjxZYbxEbAGQQe%2Fimage.png?alt=media&#x26;token=bd7cb825-9400-4eaf-8433-83adbf3b8975" alt="Diagram showing what is supplied in a tiled order"><figcaption><p>Diagram showing what is supplied in a tiled order</p></figcaption></figure>

The diagram below illustrates the format, coverage and supply type of AddressBase Core, specifically highlighting the tile supply options.

<figure><img src="https://1897589978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcNpJpLP8RROUaWVQo5ea%2Fuploads%2FJbSKDZaT9TWCDG0uQPK5%2Fimage.png?alt=media&#x26;token=c8e09b00-cca4-4d94-9f39-63ba7760ad23" alt="An illustration of AddressBase Core format, coverage, and supply types specifically for tile supplies"><figcaption><p>An illustration of AddressBase Core format, coverage, and supply types specifically for tile supplies</p></figcaption></figure>

Each supply type is covered in the sections that follow.

## GPKG <a href="#id-6.1-geopackage" id="id-6.1-geopackage"></a>

Both GB coverage and tiled supply of GPKG is produced as a full supply onl&#x79;*.* Both product variants result in you receiving one consolidated GPKG file for your order.

To use this in your GIS software, please refer to [Getting started with AddressBase Core > GPKG data](https://docs.os.uk/os-downloads/products/addresses-and-names-portfolio/addressbase-core/addressbase-core-getting-started-guide/working-with-gpkg-data), which provides instructions to load GPKG into ArcGIS Pro, ArcMap, QGIS, MapInfo Professional and CadCorp Map Modeller.

## CSV <a href="#id-6.2-csv" id="id-6.2-csv"></a>

Tiled orders are also an option for CSV supplies of AddressBase Core. The CSV is divided into 5km tiles with an individual CSV produced for each tile. This is the case for both full supply and COU. Each CSV is also be provided with a header, which needs to be considered if you want to consolidate multiple individual tiles into one single file.

One use case for taking tiled coverage is if you only need a small subset of addresses within GB, as this provides you with a smaller data holding than taking all of GB .

If you are planning on using the tile supplies for COU purposes, you need to understand the data structure of the full supply and COU files you will download.

If you select to receive COU tile supplies, if any record within a selected 5km tile is changed between two releases of data (each week), you will receive the entire 5km tile in your next supply containing all of the latest live records for that tile.

For example, as demonstrated in the table below, the original full supply contains the address *17 THE BROADS, PAMPHILL, WIMBORNE, BH21 4DR,* and the next COU data does not . However, the full supply does include an additional record, *37 THE BADGERS, PAMPHILL, BH21 4SH*. This means that the *17 THE BROADS* address has been deleted between the two releases, and *37 THE BADGERS* is a new address.

| Original full supply                                 | COU records                                          | COU change type |
| ---------------------------------------------------- | ---------------------------------------------------- | --------------- |
| BUNGALOW, BLANDFORD ROAD, WIMBORNE MINSTER, BH21 4DS | BUNGALOW, BLANDFORD ROAD, WIMBORNE MINSTER, BH21 4DS | I (INSERT)      |
| 17 THE BROADS, PAMPHILL, WIMBORNE, BH21 4DR          | No data supplied                                     | Not applicable  |
| 33 THE BROADS, PAMPHILL, WIMBORNE, BH21 4DR          | 33 THE BROADS, PAMPHILL, WIMBORNE, BH21 4DR          | I (INSERT)      |
| No data supplied                                     | 37 THE BADGERS, PAMPHILL, BH21 4SH                   | I (INSERT)      |

To implement COU, we recommend that you process the full supply and the COU data files into a common structure to be used in conjunction with SQL. You can do this by appending a `tilename` column onto the full supply and COU data when the CSVs are merged, as shown in the table below.

`AddressBaseCore_COU_2020-01-30_SU2075.csv.zip`

<table data-full-width="true"><thead><tr><th width="186">POST_TOWN</th><th width="113">ISLAND</th><th width="142">POSTCODE</th><th width="265">DELIVERY_POINT_SUFFIX</th><th width="92">GSS_CODE</th><th width="172">CHANGE_CODE</th><th>TILENAME</th></tr></thead><tbody><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td>SN4 0HJ</td><td>1A</td><td>E06000030</td><td>I</td><td>SU2075</td></tr><tr><td>MARLBOROUGH</td><td></td><td>SN8 1SZ</td><td>1A</td><td>E06000054</td><td>I</td><td>SU2075</td></tr><tr><td>MARLBOROUGH</td><td></td><td>SN8 1SZ</td><td>1B</td><td>E06000054</td><td>I</td><td>SU2075</td></tr></tbody></table>

Ordnance Survey provides FME Workbench and NodeJS scripts to help to pre-process the data as described in the sections that follow. You can access these scripts in our GitHub repository:

* [FME workbench](https://github.com/OrdnanceSurvey/AddressBase/tree/master/Data%20Translating/FME/AddressBase_Core)
* [NodeJS](https://github.com/OrdnanceSurvey/AddressBase/tree/master/Data%20Translating/Code/AddressBase_Core/NodeJS)

A README file with usage instructions is provided for both scripts.

{% hint style="info" %}
You **do not** need you to unzip the data before processing.
{% endhint %}

The data, either full supply or COU, should now be combined in one CSV file, under one header, with an appended `tilename` column. Once the data has been pre-processed, it can be loaded into any database. The next sub-sections will detail the different loads of full supply and COU.

### Full supply <a href="#id-6.2.1-full-supply" id="id-6.2.1-full-supply"></a>

Once the full supply CSV has been pre-processed, the COPY load method can be used to load the data into your primary database table:

{% code overflow="wrap" %}

```sql
COPY addressbase_core FROM ‘PATH TO PROCESSED FULL SUPPLY ' DELIMITER ',' CSV HEADER;
```

{% endcode %}

In this example, `addressbase_core` is the name of the table. You may use a different name. To use this table in a geospatial setting, geometry columns will need to be inserted using the following SQL:

{% code overflow="wrap" %}

```sql
SELECT AddGeometryColumn (<schema_name>, 'addressbase_core', <column_name>, 27700, 'POINT', 2);
COMMIT;
UPDATE addressbase_core SET geom = ST_GeomFromText('POINT(' || easting || ' ' || northing || ') ', 27700 )
COMMIT;
```

{% endcode %}

### COU supply <a href="#id-6.2.2-cou-supply" id="id-6.2.2-cou-supply"></a>

A similar method can be used to insert the COU data into a database. Similarly, `addressbase_core_cou` is the name given to the database table. You may use a different name.

{% code overflow="wrap" %}

```sql
COPY addressbase_core_cou FROM ‘PATH TO PROCESSED COU CSV ' DELIMITER ',' CSV HEADER;
SELECT AddGeometryColumn (<schema_name>, 'addressbase_core_cou', <column_name>, 27700, 'POINT', 2);
COMMIT;
UPDATE addressbase_core_cou SET geom = ST_GeomFromText('POINT(' || easting || ' ' || northing || ') ', 27700 );
COMMIT;
```

{% endcode %}

### Application of COU to the primary table <a href="#id-6.2.3-application-of-cou-to-the-primary" id="id-6.2.3-application-of-cou-to-the-primary"></a>

1. If you are applying COU to your primary table, you should now have two tables in your selected database:
   * A primary table which contains some out-of-date data.
   * A COU table with the live data.
2. To update your primary table, there are two basic steps to follow using SQL commands:
   * Delete all rows that contain tilenames that match the tilenames of the incoming COU.
   * Insert all rows from the COU table to the primary table.

The following SQL commands will complete the application of COU into the primary table:

1. Index the tilename column on to the primary table: \\

   {% code overflow="wrap" %}

   ```sql
   CREATE INDEX ON addressbase_core (tilename);
   ```

   {% endcode %}
2. Index the tilename column on to the COU table: CREATE INDEX ON addressbase\_core\_cou (tilename);\\

   {% code overflow="wrap" %}

   ```sql
   CREATE INDEX ON addressbase_core_cou (tilename);
   ```

   {% endcode %}
3. Delete from the primary table any records which have a tilename that matches a tilename from your COU table:\\

   {% code overflow="wrap" %}

   ```sql
   DELETE FROM addressbase_core WHERE tilename IN (SELECT DISTINCT(tilename) FROM addressbase_core_cou);
   COMMIT;
   ```

   {% endcode %}
4. Insert the live COU data into the primary table:\\

   {% code overflow="wrap" %}

   ```sql
   INSERT INTO addressbase_core_cou SELECT * FROM abcore.abcore_cou; COMMIT;
   ```

   {% endcode %}
