GML Reading

Liz Sanderson
Liz Sanderson
  • Updated

Introduction

The overall objective of this GML tutorial is to demonstrate a complete example workflow for reading from GML and loading it into a database. In the next tutorial, we'll read the database and write back to GML with full validation. This is a common workflow required for those using GML as an exchange format. In some cases, GML downloaded from a geoportal needs to be loaded into a local database, such as the basemap data used in this exercise. In other cases, tables from a local database need to be exported to GML for sharing with other users or for uploading to a geoportal. For these exercises, the database employed is OGC Geopackage.

In general, it’s often beneficial to use a standardized GML profile described by a well-defined application schema. This allows the data to be validated at each step, ensuring quality and completeness. The data and schemas employed for this exercise are a comprehensive base map dataset for the Gloucester area from UK Ordnance Survey OpenMap Local GML, downloaded from the UK OS geoportal. This dataset and others like it for other areas of the UK can be downloaded by tile in GML from the UK OS Open Map Geoportal

Geoportal.png

Screenshot from the UK OS Open Map Geoportal home page. 

Requirements

  • XML Editor - Such as Notepad++ with the XML Tools plug-in
    • This allows inspection of the actual source XML/GML documents and the FME writers’ XML/GML outputs. This can reveal problems in the data that may not be visible in FME Data Inspector or other XML/GML viewing software.

Step-by-Step Instructions

In the following exercise, we will see how to read GML using an application schema and write to a GeoPackage file. The files used in this exercise can be found in the Files section of the article. 

1. Open FME Workbench and Add a GML Reader

Open FME Workbench and create a blank workspace. Add a reader to the canvas and set the following:

Click Parameters.

Reader.png

In the parameters, set:

  • Application Schema: OSOpenMapLocal.xsd
  • Validate GML Dataset File: Yes
  • Feature Properties:
    • Map Predefined Properties: Enabled

Click OK twice to finish adding the reader.

ReaderParams.png

2. Inspect Data

Then run the workspace with Data Caching (formerly Feature Caching) enabled and view the data in Data Preview (formerly Visual Preview). 

InputVP.png

Map tiles by Stamen Design, under CC-BY-3.0. Data by OpenStreetMap, under CC-BY-SA.

3. Add a GeoPackage Writer

Add a writer to the canvas and set the following:

  • Format: OGC GeoPackage
  • Dataset: OSOpenMapLocal_Gloucester.gpkg
    • Click on the ellipses to navigate to a location on your computer to save the file
  • Table Definition: Copy from Reader

Next, open the Parameters. 

GpkWriter.png

In the parameters, set the following:

  • Overwrite Existing Database: enabled

Click OK twice to finish adding the writer. 

WriterParams.png 

In the Select Feature Types dialog, select all and then click OK. 

4. Connect Feature Types

There are too many feature types to connect manually. To save time, we’ll use the Feature Type Connections window. On the top menu bar, go to View > Windows > and then enable Feature Type Connections. 

FeatureTypeConnections.png

In the Feature Type Connections window, click and drag to select all of the Source feature types. Once they are all selected, click Auto Connect. Since both the reader and writer feature types have the same name, they will be automatically connected on the canvas. 

SelectFT.png

5. Set Geometry

The final step before we can write the data out is to set the geometry for each writer feature type. Open the Building writer feature type parameters, and using the drop-down, select geopackage_polygon for Geometry. Now we can apply the geometry change to all of the other writer feature types using the Apply to button at the bottom of the parameters. 

PolygonGeom.png

The Apply to button provides a variety of parameters that can be changed across the writer feature types. We are only interested in changing the geometry. Set Change Geometry to Yes, then click OK twice. You will be prompted to confirm the change across the writer feature types; click Yes. 

ChangeGeom.png

To save time, we changed ALL writer feature types to geopackage_polygon, but some feature types are point and line. 

Next, we’ll change the point geometry. Open the CarChargingPoint writer feature type. Change the Geometry to geopackage_point, then click Apply to. 

PointGeom.png

In the Change Multiple Feature Types dialog, click on the ellipsis for Feature Types to Change. Now we can select which writer feature types to update to points. Select MotorwayJunction, NamedPlace, RailwayStation, and Roundabout. Then set Change Geometry to Yes. Click OK twice. 

PointFT.png

Finally, we’ll set the geopackage_linestring geometry. Open the ElectricityTransmissionLine writer feature type parameters and set the Geometry to geopackage_linestring. Click Apply to. In the Change Multiple Feature Types dialog, select RailwayTrack, RailwayTunnel, Road, RoadTunnel, TidalBoundary, and SurfaceWater_Line as the Feature Types to Change. Set Change Geometry to Yes and click OK twice. 

6. Run the Workspace

With the geometry set for all of the writer feature types, we can now run the workspace.

WorkspaceFinal.png

If you get an “Unable to Delete File” error, ensure that you have Data Preview or FME Data Inspector closed. The GeoPackage cannot overwrite itself (if you have previously run the workspace) when it is open. 

7. View GeoPackage Results in FME Data Inspector

Open FME Data Inspector and read the GeoPackage back in, including all tables. The data should look similar to what we saw when we inspected the GML data at the beginning of this exercise.  You should now see geometries for all the feature types.

OutputVP.png 

Map tiles by Stamen Design, under CC-BY-3.0. Data by OpenStreetMap, under CC-BY-SA.

You have successfully consumed Gloucester basemap GML data from the OS OpenMap Local standard and loaded it into a local GeoPackage database.

Data Attribution

The data here originates from the Ordnance Survey (OS) OpenMap Portal and contains OS data © Crown copyright and database right 2022. It contains information licensed under the Open Government License - United Kingdom. 

Was this article helpful?

We're sorry to hear that.

Please tell us why.

As of January 14th, 2026, comments on knowledge base articles have been closed. To make sure questions don’t get missed and to enable more community support, we’ve moved discussions to the FME Community. If you have a question or a comment about this article, please create a new post or create a support ticket.