FME Version
Files
-
- 70 KB
- Download
Introduction
A common GIS operation is to merge (or dissolve) polygons together; for example, two (or more) polygons have their shared boundary removed to become a single polygon.
For example, I might have a dataset of polygons representing the provinces of Canada. I want to dissolve them together in order to get a single polygon representing Canada as a whole.
The transformer to carry out this operation in FME is called the Dissolver. Often polygons need to be dissolved according to some attribute value and the "Group-By" parameter in the Dissolver allows this to happen.
Note that polygons do not have to have exact boundaries to be dissolved. It is equally possible to dissolve polygons whose boundary overlaps; either those whose boundaries naturally overlap or those whose boundaries are meant to coincide but are badly defined.
Video
This video was recorded using FME 2016. The interface may look different but the concepts are still the same
Source Data
The source datasets for these examples are an Excel spreadsheet of election results and a polygon dataset in GML format representing election boundaries.
This example will merge the election results onto the election boundaries so that neighboring boundaries won by the same candidate/party can be dissolved together.
Step-by-step Instructions
1. Add GML Reader
Start FME Workbench and begin with an empty canvas. Select Readers > Add Reader from the menubar.
Set the data format to OGC GML (Geography Markup Language). Select the ElectionBoundaries.gml file as the source dataset, which is available to download from the Files section of this article. When prompted select only the VotingDivisions feature type (layer) to add to the workspace.
2. Add Excel Reader
Once more select Readers > Add Reader from the menubar. This time set the format to Microsoft Excel and select the ElectionResults.xls Excel file as the source.
When prompted, select only the PartyResults sheet to add to the workspace.
3. Merge Features
Add a FeatureMerger transformer to the workspace. Connect the VotingDivisions feature type to the Requestor port and the PartyResults feature type to the Supplier port:
Open the parameters dialog and select the Division attribute under the Requestor and Supplier Join attributes:
This will merge all of the attributes from the PartyResults table (Supplier) on to the VotingDivision polygons (Requestor) where the Division attribute is a match.
4. Color Each Party Differently
We'll want to inspect the output of the Dissolver in a way that each party's wins are colored differently, so add a FeatureColorSetter transformer connected to the FeatureMerger:Merged port.
Open the parameters dialog. Set the Color Scheme to Random and set the Randomize Based On parameter to "Attributes". Select the Winner attribute (which was copied from the PartyResults table) as the attribute to randomize by:
This will color each polygon the same where it was won by the same party.
5. Inspect Output
Attach an Inspector transformer and run the workspace. In Visual Preview, you should find each polygon is colored according to the winner, but adjacent polygons of the same color are not (yet) merged:
6. Dissolve Polygons
Now add a Dissolver transformer into the workspace, before the FeatureColorSetter:
Open the parameters dialog for the Dissolver. Under the Group-By parameter select the Winner attribute. This will ensure that polygons are only merged where the value of the Winner attribute is a match.
Under the Attributes to Sum parameter select the attributes Party1, Party2, Party3. These attributes represent the number of votes per area, per party. By selecting them here the votes of each dissolved polygon will be added together.
Re-run the workspace. The result will now look like this:
Notice that adjoining areas - where they were won by the same party - have been dissolved together. Also notice that the number of votes for each party in each dissolved area have been added together to provide a new value for the single dissolved polygon.
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.
Comments
0 comments
Please sign in to leave a comment.