GML Writing

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

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, which we did in the previous tutorial. Now in this 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.
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 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 write GML using an Application Schema with data coming from a Geopackage.
 
1. Open FME Workbench and Add an OGC GeoPackage Reader
Open FME Workbench and create a blank workspace. Add an OGC GeoPackage reader to the canvas and browse to the OSOpenMapLocal_Gloucester.gpkg file located in the Data folder, or you can use the output dataset from the previous tutorial. 
Reader.png
 
Click OK to add the reader, and in the Select Feature Types dialog, select all. 
 
2. Add a GML Writer
Add a GML Writer. Browse to an Output folder and name the file OSOpenMapLocal_SO_Gloucester_export.gml. Change the Feature Type Definition to Import from Dataset, then open the Parameters. 
WriterParams.png
 
In the GML writer parameters, set the GML Version to GML Application Schema, then set the Application Schema to the OSOpenMapLocal.xsd dataset. Next, expand Pretty Printing and set Pretty Print to Yes. Then expand Feature Properties and enable Map Predefined Properties. Finally, expand Advanced, and set Validate Output File to Yes. Click OK twice. Writer.png

 
In the Import Writer Feature Types dialog, keep the Format set to OGC GML, but delete the Dataset path; this should now be blank. Open the parameters and confirm that the Application Schema and Map Predefined Properties are the same as what was set in the writer. Click OK twice to finish importing the schema. 
Import.png
 
Finally, in the Select Feature Types dialog, Select All. 
  
3. Connect Reader Feature Types
Now we will use the Feature Connection Window to connect all of the reader feature types to their matching writer feature types. You can find the Feature Connection Window by going to View > Windows on the top menu bar. 
FeatureTypeConnections.png
 
In the Feature Connection Window, click and drag all of the Sources to select them all then click Auto Connect. 
AutoConnect.png
 
There will be four writer feature types without a connection; Building, FunctionalSite, Glasshouse, and Transaction. Move them to the side to clean up the workspace or remove them. 
Connections.png
 
4. Run and Review Translation Log
Once the source feature types are connected to their destinations, click Run > Run workspace. Review the Translation Log and observe any errors. Pay special attention to comments about what is missing and what is not allowed.
TranslationError.png
 
5. Review Results
Open the Output in an XML Editor like Notepad++ and note what is present or missing. In particular notice the lack of geometry in the GML Output:
MissingGeom.png
 
6. Setting the Geometry
The reason the geometries are not appearing is that we have to set the geometry name according to what is required by the destination schema. Our main clue as to what to name the geometry shows up in the destination feature type as the properties with the xml_geometry data type.
GeomType.png
 
For example, most of the destination feature types store their geometry in the ‘geometry’ property, which shown above, has data type = xml_geometry. 
 
Add a GeometryPropertySetter to the workspace. Set the Property to Set to Geometry Name, then set the Geometry Name to geometry. Be sure to set up the GeometryPropertySetter prior to connecting it, otherwise, it will pick up the geometry attribute name from the source. The name needs to be geometry and not the geometry value.
GEomPropSet.png 

Using the Feature Type Connections window, disconnect all of the connections except for FeatureCollection. You can de-select FeatureCollection by holding the ctrl/cmd key and clicking on it.  Then reconnect them (except FeatureCollection) to the GeometryPropertySetter, which can be found at the bottom of the Destinations list. 
Disconnect.png
Reconnect.png

After connecting the GeometryPropertySetter, move the FeatureCollection reader/writer feature type connection to the top of the workspace. 
GEomConnection.png

 
7. Filter Feature Types
Add a FeatureTypeFilter to the canvas and connect it to the Set output port on the GeometryPropertySetter. In the parameters, select Update to import the Feature Type Names. 
SelectUpdate.png
 
8. Connect FeatureTypeFilter Outputs
Using the Feature Type Connections window, select all of the FeatureTypeFilter sources, then click Auto Connect. This will automatically connect the FeatureTypeFilter output ports to their corresponding writer feature types. 
FilterConnect.png

9. Run Workspace
Rerun the workspace, review any errors in the log file, and re-check the data using an XML editor like Notepad++ again.
 
10. Cleanup Attributes 
Note that while we now should be seeing geometry in the output, we are still getting a number of errors due to unexpected properties. To correct this, add an AttributeRemover between the GeometryPropertySetter and the FeatureTypeFilter. Copy and paste the following comma-delimited list into the Attributes to Remove field:

gml_boundedBy,gml_priorityLocation,gml_location,gml_identifier,gml_identifier.codeSpace,gml_name,gml_name.codeSpace
AttributeRemover.png


 

11. Run the Workspace 
Run Workspace again, review the log for any errors, and review the output in the Text Editor. Try reading the output GML file into FME Data inspector with the Application Schema set to OSOpenMapLocal.xsd.
 
12. Feature Collection Attributes
Copy the AttributeRemover used between the GeometryPropertySetter and the FeatureTypeFilter. Paste this and connect the  FeatureCollection Reader. Uncheck the gml_boundedBy attribute since we need that for the dataset Bounding Box.
Attribute2.png
 
13. Feature Collection Geometry
Add a GeometryPropertySetter to the canvas but don’t connect it yet. In the parameters, set the Property to Set to Geometry Name, followed by the Geometry Name to boundedBy. Again make sure this value is literal and not pointing to the attribute value. 
GeomProp2.png
 
Once the parameters are set, connect the GeometryPropertySetter_2 between the AttributeKeeper_2 and the FeatureCollection writer feature type. The writer feature type should be connected to the Set output port. 
FeatureCollection2.png 
14. Run Workspace
Rerun and observe any errors, or warnings.
 
15. View Output
View output in Notepad++ and in FME Data Inspector. Compare the views in FME Data Inspector depending on whether or not you enabled map predefined properties.
OutputVP.png
Map tiles by Stamen Design, under CC-BY-3.0. Data by OpenStreetMap, under CC-BY-SA.
 
Congratulations, you have now successfully exported the Gloucester basemap data from your local GeoPackage database to a GML file in the UK OS OpenMap Local profile / format. This completes the GML tutorial in which we completed the round trip from reading the GML, importing it into a database, and then exporting it from the database back out to GML again. You can also compare your GML output to the original GML input from the GML Reading exercise to see if there are any substantive differences.
 

Optional

16. Optional Step: Modify GML Properties for NamedPlace
Connect an AttributeCreator between the FeatureTypeFilter NamedPlace output port and the NamedPlace writer feature type. 
NamedPlaceConnection.png
 
In the parameters, create the following attributes:

New Attribute Attribute Value
textOrientation @Evaluate(@Value(textOrientation)+0.01)
textOrientation.uom radians

AttributeCreator.png

FinalWorkspace.png

Rerun workspace and inspect output gml searching for NamedPlace elements in both your XML editor and in FME Data Inspector. Note how the textOrientation and nested uom properties have been updated.
NamedPlaceOutput.png

 

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?

Comments

0 comments

Please sign in to leave a comment.