Counting Vertices and Parsing Coordinates

Evie Lapalme
Evie Lapalme
  • Updated

FME Version

Introduction

The VertexCounter extracts a feature’s total number of vertices, storing the result in an attribute. The CoordinateExtractor transformer will retrieve your coordinate values based on the projection or coordinate system that the data is stored in. In this tutorial, we will go over how to use these transformers with line and polygon datasets. 
  

Step-By-Step Instructions

Part 1: Lines

Source
The source dataset is a manually created FME Feature Store dataset of four points creating a route. 
Source1.png

1. Create a New Workspace
Open FME Workbench and create a blank workspace. 
NewWorkspace.png
 
2. Add an FME Feature Store (FFS) Reader
Add an  FME Feature Store (FFS) reader to the canvas by clicking on the Reader button on the top menu bar or by going to Readers > Add Reader. In the Add Reader dialog, select  FME Feature Store (FFS) as the Format, then for Dataset browse to the Route.ffs dataset which is available for download from the Files section on this article. Then click OK to finish adding the reader.
RouteReader.png
 
3. Count Vertices
Click on the Route reader feature type to select it.  Then add a VertexCounter transformer to the canvas by typing “VertexCounter” to bring up the list of FME Transformers in the Quick Add Search. Select the VertexCounter from the list of Transformers by double-clicking or by using the arrow keys and the Enter key to add it. We can accept the default parameters. 
QuickAdd1.png
Connection1.png
 
4. Extract Coordinates
Next, add a CoordinateExtractor to the canvas and connect it to the VertexCounter. Double-click on the CoordinateExtractor to open the parameters. In the parameters, change the Mode to Specify Coordinate; this will create an attribute for x, y, and z coordinates. 
CoordExtract1.png

5. Run Workspace
Connect an Inspector transformer to the Output port on the CoordinateExtractor. 
Workspace1.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 output will be opened in Visual Preview. In Visual Preview, each of the vertices will have their x and y values extracted, as well as a count of how many vertices for each line. 
Output1.png


Part 2: Polygons

Source
The source dataset is a randomly created FME Feature Store dataset containing a polygon. 
Source2.png

1. Create a New Workspace
Open FME Workbench and create a blank workspace. 
NewWorkspace.png
 
2. Add an FME Feature Store (FFS) Reader
Add an  FME Feature Store (FFS) reader to the canvas by clicking on the Reader button on the top menu bar or by going to Readers > Add Reader. In the Add Reader dialog, select  FME Feature Store (FFS) as the Format, then for Dataset browse to the coquitlam.ffs dataset which is available for download from the Files section on this article. Then click OK to finish adding the reader.
Reader2.png
 
3. Count Vertices
Click on the coquitlam reader feature type to select it.  Then add a VertexCounter transformer to the canvas by typing “VertexCounter” to bring up the list of FME Transformers in the Quick Add Search. Select the VertexCounter from the list of Transformers by double-clicking or by using the arrow keys and the Enter key to add it. We can accept the default parameters. 
Quickadd2.png
Connection2.png
 
4. Extract Coordinates
Next, add a CoordinateExtractor to the canvas and connect it to the VertexCounter. Double-click on the CoordinateExtractor to open the parameters. In the parameters, set the Mode parameter to All Coordinates and leave the rest as defaults. This will create a list attribute on the output feature(s) called _indices containing coordinates for each polygon vertex.
CoordExtract2.png
 
5. List Management
The output of the CoordinateExtractor in this Mode outputs a list called _indices, which will appear in the Feature Information window inside of Visual Preview. For more information on lists, see the Tutorial: Getting Started with List Attributes ​​​​​​article. 
image.png

Add a ListExploder to the canvas and connect it to the CoordinateExtractor Output port. In the parameters, set the List Attribute to _indices{}. This transformer will make each list object into its own feature. 
ListExplode.png
 
6. Run Workspace
Connect an Inspector transformer to the Elements output port on the ListExploder. 
 Workspace2.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 output will be opened in Visual Preview. In Visual Preview, each of the vertices will have their x and y values extracted, as well as a count of how many vertices for the polygon. 
Output2.png

 

Data Attribution

Data used in this tutorial originates from data made at Safe Software

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.