GML Reading

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2022.0


The overall objective of this GML tutorial is to demonstrate a complete example workflow for reading from GML and loading it into a database. Then in the next tutorial, we'll read the database and then 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 to be shared with other users or uploaded 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 to ensure 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.
Screenshot from the UK OS Open Map Geoportal home page. 



  • XML Editor - Such as Notepad++ with the XML Tools plug-in
    • This allows the inspection of the actual source XML / GML documents and 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.
1. Open FME Workbench and Add a GML Reader
Open FME Workbench and create a blank workspace. Add an OGC GML (Geography Markup Language) reader to the canvas and browse to the OSOpenMapLocal_SO_Gloucester.gml dataset, which can be downloaded from the Files section of this article. Before clicking OK, open the Parameters. 
In the parameters, set the Application Schema to OSOpenMapLocal.xsd, then set Validate to Yes. Next, expand the Feature Properties section and enable Map Predefined Properties. Click OK twice to finish adding the reader.
In the Select Feature Type dialog, ensure all the feature types are selected then click OK. 
2. Inspect Data
Then run the workspace with Feature Caching enabled and view the data in Visual Preview. 
Map tiles by Stamen Design, under CC-BY-3.0. Data by OpenStreetMap, under CC-BY-SA.
3. Add a GeoPackage Writer
Add an OGC GeoPackage writer to the canvas, and browse to an Output folder. Name the dataset OSOpenMapLocal_Gloucester.gpkg. Ensure that the Feature Type Definition is set to Copy from Reader, then open the Parameters. 
In the parameters, enable Overwrite Existing Database. Click OK twice to finish adding the writer. 

In the Select Feature Types dialog, select all 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 > then enable Feature Type Connections. 
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. 
5. Set Geometry
The final step before we can write the data out is to set the geometry for each of the writer feature types. 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. 
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. 
To save time, we changed ALL of the writer feature types to geopackage_polygon, but there are some feature types that are point and linestrings. 
Next, we’ll change the point geometry. Open the CarChargingPoint writer feature type. Change the Geometry to geopackage_point then click Apply to. 
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. 
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.

If you get an “Unable to Delete File” error, ensure that you have Visual 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 with all of the tables. The data should look similar to when we inspected the GML data at the beginning of this exercise.  You should now see geometries for all the feature types.
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 Contains OS data © Crown copyright and database right 2022. It contains information licensed under the Open Government License - United Kingdom. 

Was this article helpful?



Please sign in to leave a comment.