Files
-
- 100 KB
- Download
Introduction
The easiest way to measure areas in FME Workbench is to use the AreaCalculator transformer. This example utilizes park data and the AreaCalculator, which calculates the area of each park feature and adds it as an attribute called ParkArea, then writes the data to a Shapefile.
Area is measured in the units of the coordinate system being used. For example, if the source data is in a coordinate system based on meters, then the AreaCalculator returns values in square meters.
•The multiplier parameter sets a value by which the result is
multiplied. This is most used when converting between units; for example,
if
the source data is in meters and the multiplier is set to 0.000247105, then
the
result will be in acres.
• The result is calculated to a precision not usually required
for most uses. The AttributeRounder is often used after the AreaCalculator
to
round the results to fewer decimal places.
• A more advanced variation is to use the @Area() function inside
a transformer such as the AttributeManager.
• Non-area features output via the rejected port.
• A multi-polygon or aggregate feature returns an area that
is the sum of its parts.
The source dataset, which is a polygon Esri shapefile representing parks, as well as the workspace for this demo, can be downloaded from the Files section.
Video
This video was recorded using FME 2016.1, the interface may be different but the concepts are the same.
Step-by-Step Instructions
Follow these steps as an example of how to calculate the area of polygon features.
1. Start FME Workbench and Add Parks Data
Start FME Workbench and click on New to open a blank workspace.
To add the parks data, click the Reader button in the Toolbar. In the Add Reader dialog window, enter the following:
- Format: Esri Shapefile
-
Dataset: /Parks.shp
- Click on the ellipsis (blank document icon for macOS) and browse to the dataset
Then click OK.
2. Add a Writer to the Workspace
We want the final dataset to be in the same format as the input, so we will add an Esri Shapefile writer feature type for the output data to be written to.
Click Writer in the Toolbar and set the following parameters:
- Format: Esri Shapefile
-
Dataset: /Output
- Choose or create the destination folder for your output dataset
Click OK. A Feature Type dialog box will pop up. Set the name for the output Shapefile, then click OK:
- Shapefile Name: ParksAndArea
3. Add an AreaCalculator Transformer
To calculate the area of each park in the dataset, we will use an AreaCalculator transformer. Type AreaCalculator in the canvas and press Enter on your keyboard to add the transformer to your workspace.
Connect the Parks reader feature type to the AreaCalculator Input port. Connect the AreaCalculator Output port to the ParksAndArea writer feature type.
The Q__area attribute listed under the ParksAndArea writer is a placeholder and will be replaced once we set an output attribute name within AreaCalculator.
Double-click the AreaCalculator transformer to open the dialog, and set the following parameters:
-
Output Attribute Name:
- Area: ParkArea
This will store the calculated area values in an attribute called ParkArea.
4. Run Workspace
Click the Run button in the Toolbar to run your workspace. Click the View Written Data button on the writer feature type to preview the data:
You should now see the new ParkArea attribute populated with area values.
The area values are in square meters since the coordinate system is UTM83-10. The coordinate system for source data is listed in the Record Information window under the Geometry property.
5. (Optional) Add AttributeRounder
The area values that have been calculated are not rounded, making them difficult to read. We can add an AttributeRounder transformer after the AreaCalculator to fix this problem.
Select the connection line between the AreaCalculator and the ParksAndArea writer feature type. Type AttributeRounder and press Enter to connect the transformer to your workspace:
Open the parameters dialog and enter:
-
Attributes to Round: ParkArea
- Click the ellipsis to select attributes
- Decimal Places: 2
Now, when you run the workspace and preview the data, the ParkArea attribute values will be rounded to 2 decimal places:
If you want to take this example one step further, you can calculate the average area of the parks using a StatisticsCalculator on the ParkArea attribute.
Additional Resources
AreaCalculator Transformer Documentation
AttributeRounder Transformer Documentation
StatisticsCalculator Transformer Documentation
Data Attribution
The data used here originates from data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.