# Working with GML data

## Loading GML <a href="#id-9._loading_gml" id="id-9._loading_gml"></a>

This section provides step-by-step instructions on how to load the Geography Markup Language (GML) format of AddressBase Premium products into FME and a database.

GML is an XML dialect which can be used to model geographic features. It was designed by the Open Geospatial Consortium (OGC) as a means for people to share information regardless of the applications or technology that they use.

In the first instance, GML was used to overcome the differences between different GIS applications by providing a neutral file format as an alternative to proprietary formats. Because it is independent of applications, it can also be moved between databases or other types of application, which allows a wider application than just GIS data transfer.

### Loading GML via a translator <a href="#id-9.1_loading_gml_via_a_translator" id="id-9.1_loading_gml_via_a_translator"></a>

Several organisations provide a loader which will translate AddressBase Premium from GML and insert the data into a database or a GIS. Due to the relational nature of AddressBase Premium, GML will not load straight into most GIS applications, meaning an external translator would be helpful to most users. If you would like to load AddressBase Premium in GML format into a GIS, please contact your vendor for more details.

For more information on Ordnance Survey Partners who provide GML loaders, please visit the [Ordnance Survey Partner website](https://www.ordnancesurvey.co.uk/customers/businesses/find-a-business-partner).

<details>

<summary>FME</summary>

GML data can be viewed and loaded into Safe FME. When AddressBase Premium is read into FME, the non-spatial tables within the product are automatically related to the spatial tables.

*Note: The following instructions use FME version 2020.0, but should work in most versions.*

1. Open FME Workbench.

2. Click the *Reader* button in the ribbon.<br>

   <figure><img src="/files/Xil82j5bx4OdLIeIged3" alt="Safe FME Reader button"><figcaption><p>Safe FME Reader button</p></figcaption></figure>

3. An Add Reader dialog box will appear.<br>

   <figure><img src="/files/TAegms95aKsDR9YqqMnA" alt="Safe FME Reader dialog" width="563"><figcaption><p>Safe FME Reader dialog</p></figcaption></figure>

4. Select *GML (Geography Markup Language)* as the Format.

5. Select a coordinate reference system from the Coord. System dropdown list. \
   \&#xNAN;*It’s recommended that British National Grid (EPSG:27700) is selected as the coordinate reference system; however, you can select a different coordinate reference system if required.*

6. Click the *three dots* button next to the Dataset box. This will bring up another dialog box where you can select the GML dataset to read into FME.

7. Click *OK* and *OK* again.

8. A Select Feature Types dialog box will appear in which you can select what feature types should be read into FME. \
   \&#xNAN;*The BasicLandPropertyUnit and Street feature types also include the non-spatial table information, such as LPI and organisation.*<br>

   <figure><img src="/files/6R4f9vqZpJQXtDUe1mdD" alt="Safe FME Select Feature Types dialog" width="413"><figcaption><p>Safe FME Select Feature Types dialog</p></figcaption></figure>

9. Click *OK*.

10. The three feature types should appear as readers.

[More information on GML readers in FME](https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_ReadersWriters/gml/gml.htm) is available on the Safe Software website.

</details>

<details>

<summary>PostgreSQL using GDAL</summary>

*Note - The following instructions are based on PostgreSQL version 12.3 and assume that you have set-up your database with the PostGIS spatial extension in a Windows environment.*&#x20;

#### Requirements:

* A development platform for PostgreSQL (for example, pgAdmin or dBeaver)
* A PostgreSQL database
* PostGIS extension
* GDAL extension
* Access to a Command Prompt or similar
* &#x20;A basic understanding of database terminology

#### Instructions

*Note - Before you start, make sure the AddressBase Premium GML is stored in a suitable location and the file is unzipped.*

1. Open the Command Prompt by clicking the Windows *Start* button in the bottom left-hand side of the screen and typing `cmd` into the search bar.<br>

   <figure><img src="/files/JLQFkNpFjwteWhyFJfEx" alt="Windows Start menu showing Command Prompt app" width="563"><figcaption><p>Windows Start menu showing Command Prompt app</p></figcaption></figure>

2. The Command Prompt will appear.

3. Change the directory of the Command Prompt App if necessary. The directory needs to point to the folder where the GML is stored. For this example, the GML to be loaded into PostgreSQL is stored in a `C:\Temp` folder.

4. In the Command Prompt, type *`cd`* followed by the directory of the location of the GML. Press *Enter* on the keyboard. \
   \&#xNAN;*This will change the directory.*<br>

   <figure><img src="/files/sQYh24GQBAO7CumsM67a" alt="Windows Command Prompt showing cd command"><figcaption><p>Windows Command Prompt showing <code>cd</code> command</p></figcaption></figure>

5. Enter the following command:<br>

   <pre data-overflow="wrap"><code>ogr2ogr -f "PostgreSQL" PG:"host=&#x3C;host> port=&#x3C;port> dbname=&#x3C;database> user=&#x3C;username> password=&#x3C;password>" &#x3C;data_name.gml> -overwrite -progress -t_srs EPSG:&#x3C;CRS>
   </code></pre>

   \
   Where:\
   \
   `<host>`, `<port>`, `<database>`, `<username>` and `<password>` can be found within the subsequent database.\
   `<data_name.gml>` is the AddressBase Premium GML file, for example, `AddressBasePremium_AOI_2021-04- 12_001_gml.gml`.\
   `<CRS>` is the coordinate reference system. British National Grid (27700) is recommended but you can use alternative coordinate reference systems if required.\
   \
   Example:<br>

   <pre data-overflow="wrap"><code>ogr2ogr -f "PostgreSQL" PG:"host=localhost port=5432 dbname=osdata user=postgres password=pgdata1234" AddressBasePremium_AOI_2021-04-12_001_gml.gml -overwrite - progress -t_srs EPSG:27700
   </code></pre>

6. Open your chosen development platform by going to the Windows *Start* button and selecting your chosen software.

7. In your Database Navigator, move to the database you loaded data into and expand the schema.

8. From using the code above, the GML files should be in your default schema (shown in bold). The data should load into two tables: `basiclandpropertyunit` and `street`. Data in non-spatial tables will automatically be matched to the spatial tables based on a unique identifier.

9. Once loaded, you may want to add Primary and Foreign Keys to the data. These can only be added on columns where the data values are unique. Where there are no unique data values, an index may be added which will aid searching. For the BLPU table, the UPRN provides a unique value.

*Note - You can also manage your database using the PostGRES SQL Command Prompt.*

</details>


---

# 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/os-downloads/products/addresses-and-names-portfolio/addressbase-premium/addressbase-premium-getting-started-guide/working-with-gml-data.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.
