Calculating Area, Perimeter, and Lengths

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

Area, perimeter, and length can be calculated for features using transformers such as the AreaCalculator and LengthCalculator in FME. In this tutorial, you will learn how to calculate the area and perimeter of polygon features, calculate polygon perimeters, and calculate the length of bike paths in the Vancouver area.
 

Step-by-step Instructions

Exercise 1: Calculating the Area of Polygon Features

In this exercise, you will learn how to calculate the area of park polygons using the AreaCalculator. Determining the area of each park will help you understand the distribution of green space throughout the city. 

Source
The source dataset is a MapInfo TAB file containing parks in the City of Vancouver. 
ParkSource.png

1. Generate Workspace
In FME Workbench, generate a new workspace. 
Generate.png
 
In the Generate Dialog, set the Reader Format to MapInfo TAB (MITAB) then browse to the Parks.tab dataset that is available in the Files section of this article. There are no parameters to set. 
Next, set the Writer Format to MapInfo TAB (MITAB), then browse to the Output folder. Click OK to finish generating the workspace. 
Generate.png
Workspace.png
 
2. Update Writer Attributes
After the workspace is generated, double-click on the Parks writer feature type to open the parameters. In the parameters, change the Table Name to ParksArea. 
WriterParams.png
 
Still in the writer feature type parameters, switch to the User Attributes tab, then set the Attribute Definition to Automatic. Click OK to close the dialog. 
Switching the Attribute Definition to Automatic will automatically update the writer to include any attribute changes we make in the workspace, such as adding a new attribute (column).  For more information on User Attributes and Attribute Definitions, see the Documentation.
UserAttributes.png
 
3. Calculate Area
Now we need to add an AreaCalculator to calculate the area of the park. To do this, click on the connection line between the reader and writer feature types to select it. Then add an AreaCalculator to the canvas by typing “AreaCalculator” to bring up the list of FME Transformers in the Quick Add Search. Select the AreaCalculator from the list of Transformers by double-clicking or by using the arrow keys and the Enter key to add it. 
AreaCalc.png
AreaCalcConnection.png

 
Double-click on the AreaCalculator to open the parameters. In the parameters, change the Output Attribute Name to ParkArea. This will add a new column and calculate the area of each polygon feature in the dataset. Leave all other parameters as default and click OK to accept the changes and close the AreaCalculator parameters.
AreaCalcParms.png
Note: the area is calculated in square map units.
 
4. Round Area Values
Next, add an AttributeRounder as you are only interested in finding the area of each park to the nearest map unit (which is meters in this case). Add the AttributeRounder between the AreaCalculator and the writer feature type. 
 AttributeRoundConnection.png
In the AttributeRounder parameters, set the Attributes to Round to the ParkArea attribute. Confirm that Decimal Places is set to 0.  
AttributeRounder.png
 
5. Run the Workspace
Confirm the new ParkArea attribute (column) will be added to the dataset by clicking on the arrow on the writer feature type to expand the attributes. There should now be the ParkArea attribute. 
Expand.png

Run the workspace by clicking on the Run button on the top toolbar, or by using Run > Run Workspace on the top menu bar. 
Run.png
 
After running the workspace, the dataset will have a ParkArea column with the calculated area. You can view the dataset by selecting the writer feature type to open the popup menu and clicking on the View Writen Data button.  
ViewWritten.png

The data will open in Visual Preview, where you will see the newly added ParkArea attribute for each park polygon. 
ParkAreaVP.png
 

Exercise 2: Calculating the Perimeter of Polygon Features

In this exercise, you will learn how to calculate the perimeter of park polygons using the LengthCalculator.

Source
The source dataset is a MapInfo TAB file containing parks in the City of Vancouver. 
ParkSource.png
 
1. Generate Workspace
In FME Workbench, generate a new workspace. 
Generate.png
 
In the Generate Dialog, set the Reader Format to MapInfo TAB (MITAB) then browse to the Parks.tab dataset that is available in the Files section of this article. There are no parameters to set. 
Next, set the Writer Format to MapInfo TAB (MITAB), then browse to the Output folder. Click OK to finish generating the workspace. 
Generate.png
 
2. Update Writer Attributes
After the workspace is generated, double-click on the Parks writer feature type to open the parameters. In the parameters, change the Table Name to ParksPerimeter. 
PerimeterWriter.png
 
Still in the writer feature type parameters, switch to the User Attributes tab, then set the Attribute Definition to Automatic. Click OK to close the dialog. 
Switching the Attribute Definition to Automatic will automatically update the writer to include any attribute changes we make in the workspace, such as adding a new attribute (column). 
UserAttributes.png

3. Calculate Perimeter
Now we need to add a LengthCalculator to calculate the perimeter of the park. To do this, click on the connection line between the reader and writer feature types to select it. Then add a LengthCalculator to the canvas by typing “LengthCalculator” to bring up the list of FME Transformers in the Quick Add Search. Select the LengthCalculator from the list of Transformers by double-clicking or by using the arrow keys and the Enter key to add it. 
LengthCalcQuick.png
LengthCalcConnect.png
 
Double-click on the LengthCalculator to open the parameters. In the parameters, change the Output Attribute Name to ParkPerimeter. This will add a new column and calculate the perimeter of each polygon feature in the dataset. Leave all other parameters as default and click OK to accept the changes and close the LengthCalculator parameters.
LengthCalcParams.png
Note: the perimeter is calculated in map units.
 
4. Round Area Values
Next, add an AttributeRounder as you are only interested in finding the perimeter of each park to the nearest map unit (which is meters in this case). Add the AttributeRounder between the LengthCalculator and the writer feature type. 
AttrRoundConnection2.png
In the AttributeRounder parameters, set the Attributes to Round to the ParkPerimeter attribute. Confirm that Decimal Places is set to 0.  
AttRoundParm2.png
 
5. Run the Workspace
Confirm the new ParkPerimeter attribute (column) will be added to the dataset by clicking on the arrow on the writer feature type to expand the attributes. There should now be the ParkPerimeter attribute. 
Expand2.png

Run the workspace by clicking on the Run button on the top toolbar, or by using Run > Run Workspace on the top menu bar. 
Run.png
 
After running the workspace, the dataset will have a ParkPerimeter column with the calculated perimeter. You can view the dataset by selecting the writer feature type to open the popup menu and clicking on the View Written Data button.  
ViewWritten2.png

The data will open in Visual Preview, where you will see the newly added ParkPerimeter attribute for each park polygon. 
VP2.png
 

Exercise 3: Calculating Length of a Line

In this exercise, you will learn how to calculate the Length of bike paths using the LengthCalculator. To learn more about calculating length, see the Distance Measurements with the LengthCalculator article.

Source
The source dataset is an Esri Shapefile containing bike paths in the City of Vancouver.BikeSource.png
 
1. Generate Workspace
In FME Workbench, generate a new workspace. 
Generate.png
 
In the Generate Dialog, set the Reader Format to Esri Shapefile then browse to the BikePaths.shp dataset that is available in the Files section of this article. There are no parameters to set. 
Next, set the Writer Format to Esri Shapefile, then browse to the Output folder. Click OK to finish generating the workspace. 
Generate3.png

2. Update Writer Attributes
After the workspace is generated, double-click on the BikePaths writer feature type to open the parameters. In the parameters, change the Table Name to BikePathLength. 
Writer3.png
 
Still in the writer feature type parameters, switch to the User Attributes tab, then set the Attribute Definition to Automatic. Click OK to close the dialog. 
Switching the Attribute Definition to Automatic will automatically update the writer to include any attribute changes we make in the workspace, such as adding a new attribute (column).  
WriterParams3.png
 
3. Calculate Length
Now we need to add a LengthCalculator to calculate the length of the bike path. To do this, click on the connection line between the reader and writer feature types to select it. Then add a LengthCalculator to the canvas by typing “LengthCalculator” to bring up the list of FME Transformers in the Quick Add Search. Select the LengthCalculator from the list of Transformers by double-clicking or by using the arrow keys and the Enter key to add it. 
QuickAdd3.png
 
Double-click on the LengthCalculator to open the parameters. In the parameters, change the Output Attribute Name to PathLength. This will add a new column and calculate the length of each bike path line feature in the dataset. Leave all other parameters as default and click OK to accept the changes and close the LengthCalculator parameters.
PathLength.png
Note: length is calculated in map units.
 
4. Round Area Values
Next, add an AttributeRounder as you are only interested in finding the length of each bike path to the nearest map unit (which is meters in this case). Add the AttributeRounder between the LengthCalculator and the writer feature type. 
AttRoundConnect3.png
 
In the AttributeRounder parameters, set the Attributes to Round to the PathLength attribute. Confirm that Decimal Places is set to 0.  
LengthCalc3.png
 
5. Run the Workspace
Confirm the new PathLength attribute (column) will be added to the dataset by clicking on the arrow on the writer feature type to expand the attributes. There should now be the PathLength attribute. 
Expand3.png

Run the workspace by clicking on the Run button on the top toolbar, or by using Run > Run Workspace on the top menu bar. 
Run.png
 
After running the workspace, the dataset will have a PathLength column with the calculated length. You can view the dataset by selecting the writer feature type to open the popup menu and clicking on the View Written Data button.  
View3.png

The data will open in Visual Preview, where you will see the newly added PathLength attribute for each bike path. 
VP3.png

 

Data Attribution

Data used in this tutorial originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.