Creating polygons from line fragments in FME

By February 18, 2019March 15th, 2021FME

Creating polygons in FME can be done by using polylines or line objects, and the AreaBuilder function. Since the cycle route network is a set of topologically connected line objects, the AreaBuilder can create polygon features from lines that are connected by vertices/endpoints and form shapes (i.e. a closed polygon). However, areas can also be created from disconnected line features using the LineCloser.


We will work on the Shapefile with bicycle routes from Wroclaw, which can be downloaded from here.


Start FME Workbench
If it isn’t open already, launch FME Workbench, and create a new workspace.

poligony_fme (1)Set the Reader Format
Set the Reader Format to Esri Shapefile.

poligony_fme (2)

Add an AreaBuilder

Add an AreaBuilder function to the script and open its parameters.
Deselect the Create Donuts box to avoid creating polygons with holes.
Attributes Accumulation is set to Use Attributes From One Feature by default, so polygon feature will get attributes from only one polyline creating it. Bicycle routes have three attributes – length, direction and path type. The length will have to be counted again, but the direction and type will not be needed. Let’s set Drop Incoming Attributes as we don’t want to keep the attributes.
Instead, select Generate List and set its name to “dlugosc” (length). Select Add only selected attributes to the list, and select only the SHAPE_LEN attribute. This will cause each created feature to have a list keeping the lengths of the lines that the polygon consists of. It will be used to count the perimeter of each created polygon.

poligony_fme (3)

Creating an identifier for polygons
Add a Counter after  AreaBuilder and open its parameters.
Change the name of the created attribute to PolygonID. This will be a unique, autonumeric identifier for previously created polygons. The rest of the parameters leave as default.

poligony_fme (4)

Count the polygon perimeter
After Counter add the ListSummer and open its settings. As the source list select the dlugosc{}. SHAPE_LEN and call the summed attribute “circuit”.
Counter sums up the elements of the list (lengths of the lines) for each polygon, which will result in an attribute that will hold perimeter for each polygon.

poligony_fme (5)

Keep some attributes
Add AttributeKeeper and open its settings. Select “obwod” (perimeter) and PoligonID attributes to keep them.

Set the Writer Format
Set the Writer Format to Esri Shapefile, and change the definition of the file to automatic, so the filename can be chosen, and the Attribute Definition will also be automatic. This will cause Workbench to automatically define the list of attributes. Further, the list of attributes on the Writer feature type will update automatically whenever attributes are changed (i.e. renamed, removed, etc.) in the workspace.

Run the script.

poligony_fme (6)

After running the script, the results can be viewed by clicking on the saving adapter and the icon with the loupe. As you can see, we were able to create polygons and count the perimeter for each of them. Such polygons can be used in further work to analyze the availability of paths, for example through buffer analysis.


poligony_fme (7)Output

poligony_fme (8)

Transformers we used:

  • AreaBuilder – Takes a set of topologically connected linework and creates topologically correct polygon features where the linework forms closed shapes.
  • Counter – Adds a numeric attribute to a feature and assigns a value. Each subsequent feature passing through the transformer receives an incremented value – in other words, the Counter is counting the features.
  • ListSummer – Computes the sum of all the elements of a list.
  • AttributeKeeper – Removes all attributes and list attributes, except the specific ones you specify to be retained.

If you have more questions about transforming and integrating data or FME in general, reach out to us.