Using the FeatureWriter Transformer with your Database

Sydney Dombowsky
Sydney Dombowsky
  • Updated

Introduction

The FeatureWriter allows you to write data at any point in your workflow, not only at the end of the workspace as with a 'conventional' writer. This gives you the opportunity to post-process the results. 

 

Although this example writes to a GeoPackage database, it is applicable to any spatial database such as Esri Geodatabase, SQL Server, Oracle Spatial, PosGIS, etc.

This demo utilizes the FeatureReader and FeatureWriter transformers to read a CAD dataset and write to OGC GeoPackage format. Post-processing is used to help understand the output data.

The data we will be using is a CAD file with a City of Vancouver water network, water mains, valves, hydrants. The dataset contains a number of attributes related to information about the water network objects. This data, as well as the starting and final workspace templates, can be downloaded from the Files section.

Step-by-Step Instructions

Open the FeatureWriter_Start.fmwt workspace. This workspace includes the following steps:

The FeatureWriter_Start.fmwt workspace includes the following basic steps:

  • Reads CAD Data and Transforms Attributes
    • The AttributeManager is used to rename attributes and set default values
    • The AttributeValueMapper is used to build domain values
    • The GeometryFilter is used to filter for only line features
    • The 2DForcer is used to drop Z values that often appear on CAD geometries
  • Validates Water Network Attribute Values
    • The AttributeValidator validates the network dataset attributes against a number of tests
    • A list of the failed tests is added to features in the Failed port which will allow us to write data later on about which features failed against one or more tests to GeoPackage databases
  •  Extracts Error Messages and Validation Tests of Failed Water Network Objects
    • The ListExploder is used to split the list to create one record per test message
    • The AttributeManager renames the list item attributes
    • The GeoPackage Writer feature type writes the results
  • Writes the Valid Features to the GeoPackage
    • The features that pass the validation are written to the appropriate table in the GeoPackage (CADValidationReport, wControlValve, wHydrant, or wMain)

Run the FeatureWriter_Start.fmwt workspace and preview the resulting GeoPackage by clicking the View Written Data button on each Writer feature type (e.g. wControlValve). This will open the data in the Data Preview window.

 

You're going to modify the workspace by:

  • Replacing the AutoCAD reader with a FeatureReader
  • Replacing the GeoPackage writer with a Writer to a database of your choice (i.e. Esri Geodatabase, Oracle Spatial, SQL Server, PostGIS, etc.)
  • Replacing the GeoPackage writer with a FeatureWriter, writing to the database of your choice (i.e. Geopackage, Esri Geodatabase, Oracle Spatial, SQL Server, PostGIS, etc.)
  • Adding an SQLExecutor to do some post-processing of the data

 

Part 1: Adding a FeatureReader

Replacing the AutoCAD reader with a FeatureReader allows you to pre-process the data, clean-up database tables, or trigger the read using an external input. In this example, we'll just use the Creator transformer.

As of FME 2025.2, many transformers have been updated to not require input from the creator transformer. For a list of all the transformers with this improvement, please see Transformers with an Optional Input Port

1. Disable the AutoCAD Reader

If you haven’t yet, open the FeatureWriter_Start.fmwt workspace. Disable (not delete) the AutoCAD reader. This can be done in the Navigator pane by right-clicking the AutoCAD reader, called CofVWater_small [AUTOCAD_OD], and selecting Disable.

 

 

2. Add a Creator Transformer (If using FME 2025.2+, skip this step)

Begin typing Creator in the canvas and press Enter on your keyboard to add the transformer to the workspace. 

If you are using FME 2025.2 or newer, the Creator transformer is no longer required as an input for the FeatureReader. Continue to step 3.

 

3. Add a FeatureReader Transformer

Add a FeatureReader to the canvas, with the Initiator port connected to the Creator Created port, and double-click the transformer to open the parameters window. Enter the following:

  • Format: Autodesk AutoCAD Map 3D Object Data
  • Dataset: /CofVWater_small.dwg
  • Parameters:
    • Explode Blocks into Entities: Disabled
  • Feature Types to Read: Abandoned Mains, Control Valves, DFPS Mains, Distribution Mains, Hydrants, Transmission Mains

 

4. Add an AttributeExposer

We want to be able to select by feature type, which requires the fme attribute fme_feature_type to be exposed. This is necessary for AttributeManager_4 as it connects three mains (Transmission, Distribution, and DFPS) and the attribute is referenced in the conditional values for Type.

Add an AttributeExposer to the workspace and connect the FeatureReader Transmission Mains, Distribution Mains, and DFPS Mains ports to the AttributeExposer Input port.

Open the AttributeExposer parameters and set the following:

  • Attribute: fme_feature_type

Click OK to close the parameters.

 

5. Connect to AttributeManager and Test Run

Connect the AttributeExposer to AttributeManager_4, then connect the FeatureReader output ports (labeled for each Feature Type) to the appropriate AttributeManager transformer.

Listed below are the FeatureReader output ports and their associated AttributeManager:

FeatureReader Port AttributeManager Name
Abandoned Mains AttributeManager_3
Control Valves AttributeManager
Hydrants AttributeManager_2

Test your FeatureReader by running the modified workspace. If the results look good, delete the AutoCAD reader.

Save the workspace. 

 

Part 2: Adding FeatureWriter

You're now going to add a FeatureWriter to the workspace, replacing the GeoPackage writer.

1. Disable the GeoPackage Writer

Disable, but do not delete, the GeoPackage writer.

 

2. Add a FeatureWriter Transformer

Add a FeatureWriter transformer to the workspace and open the Parameters dialog. 

  • Format: OGC GeoPackage
  • Dataset: /CoVWaterDatabase.gpkg

Under the Feature Types box, click the plus (+) symbol, then Import from Dataset. In the Import Schema Definitions window, set:

  • Format: OGC GeoPackage
  • Dataset: /CoVWaterDatabase.gpkg

Click OK and a schema definition window will open. Select the following:

  • wControlValve
  • wHydrant
  • wMain

Click OK to add the transformer to the workspace.

 

3. Connect Transformers and Test Workspace

Connect the FeatureWriter input ports to the appropriate AttributeValidator Passed ports:

AttributeValidator FeatureWriter Port
AttributeValidator wControlValve
AttributeValidator_2 wHydrant
AttributeValidator_3 wMain

Run the workspace and, if it runs correctly, delete the OGC GeoPackage writer.

 

Part 3: Post-Processing

Now we can do some simple post-processing or validation of the output. For example, you could create an attribute or spatial index using the SQLExecutor. 

In this workspace, you are going to validate the number of features written. FME reports the number of features written, but this sometimes does not match the actual number of features inserted into the database. This can occur if you are using transactions and one of the inserts fails. 

You're going to add a SQLExecutor to check the number of records in the database after all the features have been written by the FeatureWriter.

1. View Summary Output

Run the workspace with Data Caching enabled, then click the green icon next to the FeatureWriter Summary port to view the output. 

The FeatureWriter outputs a single feature with a list of all the feature types written. These can be found in the Record Information panel:

  • _total_features_written 4309
  • _feature_type{0}.count 1481
  • _feature_type{0}.name wControlValve
  • _feature_type{1}.count 514
  • _feature_type{1}.name wHydrant
  • _feature_type{2}.count 2314
  • _feature_type{2}.name wMain

In the list, 'name' is the table name and 'count' is the number of features FME thought it wrote.

 

2. Add a ListExploder

Add a ListExploder to the workspace and connect it to the FeatureWriter Summary port. In the parameters select the list attribute:

  • List Attribute: _feature_types{}

This will result in a separate summary feature for each feature type that was written.

 

3. Add an SQLExecutor

Add an SQLExecutor to workspace and connect the ListExploder (ListExploder_2) Elements port to the SQLExecutor Initiator port.

Open the parameters and set the following:

  • Format: OGC GeoPackage
  • Dataset: /CoVWaterDatabase.gpkg
  • SQL Statement: 

    SELECT COUNT(*) AS "rows" FROM "@Value(name)"
    • This queries the database and returns the row count of each table in the 'name' attribute
  • Attributes to Expose: rows
    • Click the ellipsis to enter ‘rows’ into the list
  • Combine Attributes: Keep Result Attributes if Conflict
  • Ignore Nulls: No
  • Combine Geometry: Initiator Geometry Only

 

4. Add a TestFilter

Connect the SQLExecutor Result output port to a TestFilter Input port and open the Parameters dialog.

Double-click the first cell, next to ‘If’ and under ‘Test’ to open the Test Conditions dialog. Set the following:

  • Left Value: count
    • Click into the cell and use the drop-down menu to select the attribute
  • Operator: =
  • Right Value: rows
  • Output Port: CountMatch

Click OK. Under the Output Port column and the Else row, set the output port to CountFailed:

  • OutputPort: CountFailed

This will compare the ‘count’ value of the features written versus the ‘rows’ value returned by the SQLExecutor.

 

5. Run the Workspace and View Output

Run the workspace with Data Caching enabled, then view the output ports (CountMatch and CountFailed) of the TestFilter. CountFailed shows the features that have different ‘count’ values from ‘rows’ values.

  

 

Other Post-Processing Options

The workspace in the FeatureWriter_Final.fmwt file has some additional ideas that you can investigate:

  • JSON Reader: Using a JSON reader to initiate the FeatureReader would allow you to publish this workspace to FME Server and drive the validation using a directory watcher publication.
  • DropboxConnector: The DropboxConnector allows you to move the GeoPackage database file to a dropbox folder. If you don't have a dropbox account you'll need to disable this transformer. Or try one of the other connectors: GoogleDriveConnector, OneDriveConnector, BoxConnector.
  • Emailer: The Emailer will email the validation GeoPackage database file to a friend. You'll need to configure the Emailer with your own email account information or disable the transformer to avoid errors.

The demo workspace will not run if the Emailer or DropboxConnector is not configured. If you do not have suitable accounts, disable these parameters.

Additional Resources

FeatureWriter Transformer [Documentation]

FeatureReader Transformer [Documentation]

The FeatureReader Transformer [Article]

The FeatureWriter Transformer [Article]

 

Data Attribution

The data used here originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.

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.