Distance Measurements with the LengthCalculator

Sydney Dombowsky
Sydney Dombowsky
  • Updated

Introduction

Measuring distances is - like measuring areas - very simple in FME. It requires the use of just one transformer: the LengthCalculator. Here, for example, a user is measuring the length of arterial road features:

LengthCalculatorDemo_Workspace
 

The length of each road feature is measured and added to the feature as an attribute called RoadLength.

Length 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 LengthCalculator returns values in 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 3.28084, then the result will be in feet.
  • The result is calculated to a precision not usually required for most uses. The AttributeRounder is often used after the LengthCalculator to round the results to fewer decimal places.
  • A more advanced variation is to use the @Length() function inside a transformer, such as the AttributeManager.
  • A multi-line or aggregate feature returns a length that is the sum of its parts.

The source dataset, which is a line Esri shapefile representing arterial roads, 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 length of linear features.

 

1. Start FME Workbench and Add Arterial Data

Start FME Workbench and click on New to open a blank workspace.

To add the roads data, click the Reader button in the Toolbar. In the Add Reader dialog window, enter the following:

  • Format: Esri Shapefile
  • Dataset: /Arterial.shp
    • Click on the ellipsis (blank document icon for macOS) and browse to the dataset

Then click OK.

ReaderShapefile

 

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 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: Arterial

WriterShapefile

 

3. Add a LengthCalculator Transformer

To calculate the length of each road in the arterial dataset, we will use a LengthCalculator transformer. Type LengthCalculator in the canvas and press Enter on your keyboard to add the transformer to your workspace.

Connect the Arterial reader feature type to the LengthCalculator Input port. Connect the LengthCalculator Output port to the Arterial writer.

LengthCalculator

The Q__area attribute listed under the Arterial writer is a placeholder and will be replaced once we set an output attribute name within LengthCalculator.

Double-click the LengthCalculator transformer to open the dialog, and set the following parameters:

  • Length: RoadLength

 

This will store the calculated length values in an attribute called RoadLength.

 

4. Run Workspace

Click the Run button in the Toolbar to run your workspace. Click the View Written Data button on the Arterial writer feature type to preview the data:

ViewWrittenData

 

You should now see the new RoadLength attribute populated with length 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.

 

DataPreview

 

5. (Optional) Add AttributeRounder

The length values that have been calculated are not rounded, making them difficult to read. We can add an AttributeRounder transformer after the LengthCalculator to fix this problem.

Select the connection line between the LengthCalculator and the Arterial writer. Type AttributeRounder and press Enter on your keyboard to connect the transformer to your workspace:

AttributeRounder

Open the parameters dialog and enter:

  • Attributes to Round: RoadLength
    • Click the ellipsis to select attributes
  • Decimal Places: 3

AttributeRounder_Parameters

 

Now, when you run the workspace and preview the data, the RoadLength attribute values will be rounded to 3 decimal places:

DataPreview_Rounded

 

If you want to take this example one step further, you can calculate the average length of roads using a StatisticsCalculator on the RoadLength attribute.

 

Additional Resources

LengthCalculator 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.

Was this article helpful?

We're sorry to hear that.

Please tell us why.

As of January 14th, 2026, comments on knowledge base articles have been closed. To make sure questions don’t get missed and to enable more community support, we’ve moved discussions to the FME Community. If you have a question or a comment about this article, please create a new post or create a support ticket.