Exercise 3 | Residential Garbage Collection Zones |
Data | Addresses (Esri Geodatabase), Zones (MapInfo TAB) |
Overall Goal | Create boundaries for residential garbage collection |
Demonstrates | Readers and Writers |
Start Workspace | C:\FMEData2018\Workspaces\DesktopBasic\Design-Ex3-Begin.fmw |
End Workspace | C:\FMEData2018\Workspaces\DesktopBasic\Design-Ex3-Complete.fmw |
Here we continue with a project to redefine garbage collection schedules.
In the first two exercises, we used various transformers to divide addresses into five separate groups, according to zoning type. Then we wrote the data to Geopackage.
Now the task is to replace the groups of point features with a polygon boundary.
1) Open Copy of Workspace
Open your workspace from the previous exercise.
If you gave that workspace a version number in its name, then you should make a copy of the workspace with a new version number. For example, if you saved it to GarbageCollection-v2.fmw then make a copy named GarbageCollection-v3.fmw and open that for editing.
Alternatively you can open the workspace C:\FMEData2018\Workspaces\DesktopBasic\Design-Ex3-Begin.fmw:
2) Run Workspace
Turn on feature caching using Run > Run with Feature Caching on the menubar.
Now re-run the workspace. The process will take a little longer than the standard translation time, as caches are being created and filled. Take note of the time taken (1 minute 7 seconds on my machine).
Once complete, click on some caches to prove that the data can be inspected directly in the FME Data Inspector.
3) Add HullReplacer
Move the HullReplacer transformer from the "Transformers" bookmark into the "Create Boundaries" bookmark. Connect it between the Aggregator and writer feature type:
Notice how the HullReplacer has no cache because it is newly placed.
4) Re-Run Workspace
Now let's re-run the workspace. But rather than run the whole translation, click on the HullReplacer transformer and on the icons that pop up, click Run from This:
Notice how hovering shows what parts of the workspace will be run. The translation this time should take less than one second since the results of prior portions of the workspace are already stored in a cache.
The output now includes polygons, to prove that the translation has functioned correctly:
5) Clean Up Overlaps
The problem with the output is that all of the polygons overlap to some extent. That needs to be fixed so that there are no overlaps. What's more, we should check which zone an overlap belongs to by seeing which group contains most of its addresses.
Because this is unexpected, we don't have an area of the workspace set aside yet. Add a new bookmark (or move the now-empty Transformers bookmark) and name it Clean Up Overlaps:
6) Add AreaOnAreaOverlayer
Overlaps can be dissected using the AreaOnAreaOverlayer transformer, so add one of these to the new bookmark, connected to the HullReplacer transformer. Check the parameters and set the Attribute Accumulation Mode to Drop Incoming Attributes.
Re-run the translation by clicking the AreaOnAreaOverlayer and choosing Run From Here. There's no need to add an Inspector transformer because the data can be inspected by simply clicking on the Cache icon.
7) Add PointOnAreaOverlayer
The overlaps are now separate features, but we do not yet know to which area they should be assigned. It should be the one with most addresses; for example, if an overlap contains 31 addresses from group one, and 52 addresses from group two, then it should be assigned to the group two polygon.
We can start on this by using a PointOnAreaOverlayer. This transformer will let us create a list of which addresses an overlap contains.
So add a PointOnAreaOverlayer transformer. The area features will be the output from the AreaOnAreaOverlayer.
The point features should be a copy of the addresses. The simplest way to get these is to make a second connection from the SpatialSorter:
Inspect the parameters. Under Attribute Accumulation, set the following parameters:
Merge Attributes | Yes |
Generate List on Output 'Area' | Yes |
'Area' List Name | PointList |
Selected Attributes | GroupID |
Doing so will create an FME list attribute. A list attribute is an attribute with multiple values. Here the list will contain a record of the point features (and their GroupID values) that fall inside a polygon.
Confirm this works correctly by running the workspace at the new PointOnAreaOverlayer. Notice how the translation pulls data from two caches; the AreaOnAreaOverlayer and SpatialSorter transformers:
Inspect the Area features. Querying a feature will show (in the Feature Information window) the list attribute and all of its values.
8) Add ListHistogrammer
To count the most frequent GroupID for each list on an overlap's we'll use the ListHistogrammer transformer.
TIP |
This is not a commonly used transformer, so don't worry if you weren't aware of it, or if you are concerned about the large number of transformers available in FME. You will learn more about these transformers with practice. For now the ability to use partial runs is much more important. |
Place a ListHistogrammer transformer connected to the PointOnAreaOverlayer:Area output port. Inspect the parameters and select PointList{}.GroupID as the source attribute:
Re-run the workspace (from the ListHistogrammer) and inspect the results. Notice that a new list attribute is created; a list of the number of different GroupID values with the most frequent GroupID at the top of the list. So we merely need to use that GroupID to merge areas.
8) Add Dissolver
Finally add a Dissolver transformer to merge the features together. Connect the Dissolver to the ListHistogrammer output port:
Inspect the parameters. Under Group By select the attribute _histogram.value:
You'll be prompted for a value; this is which item in the list do we want. We want the first element because it has the most values, so this field should be set to zero (which it will be by default):
Re-run the workspace from the Dissolver and inspect the output:
We now have five polygon features to represent garbage collection areas, each with approximately the same number of residents. Connect the Dissolver:Area port to the writer feature type and this workspace is complete... nearly.
9) Remove Sampler
To complete the project let's run the workspace on the full dataset. You can do this by deleting the Sampler transformer (the simplest solution) or by replacing the PostalAddress-Sampler connection with a PostalAddress-PointOnAreaOverlayer connection:
So far we have set the Grid Size parameter for the SpatialSorter to 16 (i.e., less precise) to increase performance. Now that we are nearly finished we should increase the Grid Size to 256 (i.e., more precise).
For reasons of time and performance, turn off the Run with Caching option and then re-run the translation.
As expected, the result will look different, now that we're using the full dataset:
CONGRATULATIONS |
By completing this exercise you have learned how to:
|