Files
Introduction
In order to correct topology errors, you should first test which features break the appropriate topology rule for your dataset. In this article, you will learn how to use FME to identify topological errors using the SpatialFilter. To see more data validation scenarios, check out the Tutorial: Data Validation and QA with FME tutorial.
Data Source
The source dataset for both exercises is an Esri Shapefile of bike paths in the City of Vancouver that has been modified to include topology errors.
Step-by-step Instructions
Exercise 1: Testing for Topology Errors on Linear Features
In this exercise, you will test for topological errors in a linear dataset. You are testing your dataset to ensure it was digitized correctly and that bike path segments are snapped together.
1. Create a New Workspace
Open FME Workbench and create a blank workspace.
2. Add an Esri Shapefile Reader
Add an Esri Shapefile reader to the canvas by clicking on the Reader button on the top menu bar or by going to Readers > Add Reader. In the Add Reader dialog, select Esri Shapefile as the Format, then for Dataset browse to the BikePathTopology.shp dataset, which is available for download from the Files section of this article. Then click OK to finish adding the reader.
3. Filter Features
Click on the BikePathTopology reader feature type to select it. Then add a SpatialFilter transformer to the canvas by typing “SpatialFilter” to bring up the list of FME Transformers in the Quick Add Search. Select the SpatialFilter from the list of Transformers by double-clicking or by using the arrow keys and the Enter key to add it.
The BikePathTopology reader feature type will automatically be connected to the Filter input port on the SpatialFilter. We also need to connect the reader feature type to the Candidate input port so we can compare the features to themselves. Click and drag a connection line from the BikePathTopology reader feature type to the Candidate input port on the SpatialFilter.
Double-click on the SpatialFilter to open the parameters. In the parameters, click on the ellipsis next to Spatial Predicate to Test. Select Filter OGC-Touches Candidate as the Test, then deselect any other tests. Click OK. Then uncheck Merge Attributes.
4. Run Workspace
Connect an Inspector transformer to the Passed output port on the SpatialFilter, then connect another Inspector to the Failed output port. The one connected to the Passed output port will include all bike paths that touch, and the failed output port will include the features that are disjoint.
Run the workspace by clicking the Run button on the top toolbar, or by selecting Run > Run Workspace from the top menu bar.
After running the workspace, the output will be opened in Data Preview (formerly Visual Preview). In Data Preview, 12 bike paths are disjoint and not topologically correct. In the screenshot below, the paths are in green. We will continue in this workspace in Exercise 2 to resolve these topological errors.
Exercise 2: Correcting Topology Errors
In exercise 1, we tested for topological errors in a linear dataset by checking for disjoint lines. In this exercise, we will be correcting the disjoint features (identified by the <missing> predicate attribute) using the Snapper transformer. The goal of this exercise is to eliminate errors that were introduced by not snapping line segments to vertices/endpoints.
5. Disable SpatialFilter
Since we know what needs to be fixed, we can disable the SpatialFilter and the connecting Inspectors. A quick way to do this is to add a bookmark around the SpatialFilters and Inspectors by clicking and dragging a box around the objects, then selecting Ctrl-B or Cmd-B on your keyboard. Bookmarks can also be added by right-clicking on the canvas and selecting Create Bookmark. Name this bookmark Topology Inspector. After the bookmark has been added, right-click on it and select Disable All Objects in Bookmark.
With the objects disabled, move the bookmark out of the way.
6. Add a Snapper
Since the SpatialFilter tests for touching bike path segments, we want to correct the segments that fail this test. Add a Snapper to the canvas and connect it to the BikePathTopology reader feature type.
Open the Snapper parameters, then set the Snapping Type to Vertex Snapping. Next, set the Snapping Distance to 20. The Snapping Distance is measured in map units, which, for this dataset, are meters.
7. Recheck Topology
At this point, now that the snapper features are fixed, we could write the data using a FeatureWriter. You can do this step if you wish, but for demonstration purposes, let’s use a Junction transformer to take the place of the FeatureWriter. Add a Junction to the canvas and connect both the Snapped and Untouched output ports from the Snapper.
Next, duplicate the previous SpatialFilter and the two connected Inspectors (Ctrl+D). Then connect both the Filter and Candidate input ports from the SpatialFilter_2 to the Junction output port. We could have skipped the junction and connected the input and output ports directly, but we would have had multiple crossing lines.
8. Run Workspace
Run the workspace and notice that there are no disjoint features from the SpatialFilter_2; this indicates that the topology was corrected.
If we enable the Topology Inspector bookmark and rerun the workspace, we can see exactly where the topology was corrected. In the screenshot below, the brown, thick line shows the corrected topology, and the blue line shows the topology with errors.
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.