Exercise 3 | Grounds Maintenance Project - Calculating Statistics |
Data | City Parks (MapInfo TAB) |
Overall Goal | Calculate the size and average size of each park in the city, to use in Grounds Maintenance estimates for grass cutting, hedge trimming, etc. |
Demonstrates | Content Transformation. Schema Mapping |
Start Workspace | C:\FMEData2019\Workspaces\DesktopBasic\DataTransformation-Ex3-Begin.fmw |
End Workspace | C:\FMEData2019\Workspaces\DesktopBasic\DataTransformation-Ex3-Complete.fmw C:\FMEData2019\Workspaces\DesktopBasic\DataTransformation-Ex3-Complete-Advanced.fmw |
Let's continue your work on the grounds maintenance project.
In case you forgot, the team responsible for maintaining parks and other grassed areas needs to know the area and facilities of each park to plan their budget for the upcoming year.
In this part of the project, we’ll calculate the size and average size of each park, and ensure that information is correctly mapped to the destination schema.
1) Start FME Workbench
Start FME Workbench (if necessary) and open the workspace from Exercise 2. Alternatively you can open C:\FMEData2019\Workspaces\DesktopBasic\DataTransformation-Ex3-Begin.fmw
2) Add an AreaCalculator Transformer
To measure the area of each park feature, an AreaCalculator transformer must be used. “Calculator” is the term for when FME computes new attribute values.
Click on the connection between Tester:Passed port and the writer feature type ParksMaintenanceData. Start typing the letters “areac”. You will see the Quick Add list of matching transformers appear beneath.
Select the transformer named AreaCalculator by double-clicking it:
3) Add a StatisticsCalculator Transformer
Using the same method, place a StatisticsCalculator transformer between the AreaCalculator:Output port and the ParksMaintenanceData feature type. By default the output connection will be on the Summary port, but we want the complete dataset, so move the connection to the Complete port:
4) Check the AreaCalculator Parameters
Inspect the AreaCalculator parameters:
The default settings cause the calculated value to be placed into an attribute called _area. However, the ParksMaintenanceData schema requires an attribute called ParkArea, so change this parameter to create the correct attribute:
Once you click OK or Apply, notice that the attribute on the writer feature type is now flagged as connected.
5) Check the StatisticsCalculator Parameters
A red cogwheel icon indicates the StatisticsCalculator has parameters that need to be defined.
Inspect the StatisticsCalculator transformer's parameters. The Attribute to Analyze is the one containing the calculated area; so select ParkArea:
Examine what the default setting is for an attribute name for average (mean) park size. Currently, it doesn't match the ParksMaintenanceData schema, which requires an attribute named AverageParkArea.
Change the Mean Attribute from _mean to AverageParkArea. For Best Practice reasons, delete/unset any StatisticsCalculator output attributes that aren't required (for example _min and _sum).
6) Run the Workspace
Add another bookmark if you wish and run the workspace. Once the workspace has finished running, click on the ParksMaintenanceData writer feature type to bring up the popup menu, then click on the View Written Data button to view the data in Visual Preview.
The results will then be displayed in the Visual Preview window:
The Table View window shows the area of each park and the average area of all parks.
7) Save the Workspace
Save the workspace – it will be completed in further examples.
Advanced Exercise |
Notice that the numbers in the Table View show the results have been calculated to 12 decimal places. This is in excess of the precision that you require. As an advanced task - if you have time - use the AttributeRounder transformer to reduce the values to just 2 decimal places.
If you wish, you can also calculate the smallest, largest, and total park areas; but don't forget to add them to the writer schema if you want them to appear in the output. |
CONGRATULATIONS |
By completing this exercise you have learned how to:
|