Find Nearest Features

Liz Sanderson
Liz Sanderson
  • Updated

Introduction

In this tutorial, you will learn how to find the nearest features using point and polygon datasets. The purpose of this operation is to find the nearest feature from an object of interest based on the straight line distance between features (i.e., starting from a point of interest, such as a school in Vancouver, find the nearest park polygon feature). To accomplish this, use the NeighborFinder transformer. The NeighborFinder is typically used to identify the nearest features, features within a specified distance, or the closest feature in a given direction.

Step-by-step Instructions

In this scenario, you are interested in determining which park with washroom facilities is closest to the starting point, Alexander Academy. In this exercise, you will learn how to query your datasets based on attribute values and perform a simple spatial analysis using a point and polygon dataset. For an in-depth tutorial on finding the nearest neighbors and calculating both the distance and bearing for multiple features, see the Determining Nearest Neighbors article.

Data Sample

The first source dataset is a feature class in the Community geodatabase that contains schools in the City of Vancouver.

SchoolsSource.png

The second source is a MapInfo TAB dataset containing parks and park amenities in the City of Vancouver.

ParkSource.png 

1. Create a New Workspace

Open FME Workbench and create a blank workspace. 

NewWorkspace.png

2. Add an Esri Geodatabase (File Geodb Open API) Reader

Add an Esri Geodatabase (File Geodb Open API) 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 Esri Geodatabase (File Geodb Open API) as the Format, then for Dataset browse to the CommunityMap.gdb dataset, which is available for download from the Files section of this article. Then open the Parameters. 

Geodtabase.png

In the Parameters, click the ellipsis next to Table, then select both the Parks and Schools datasets. Click OK three times to finish adding the reader. 

ReaderParam.png

3. Filter for Dog Parks and Washrooms

We only want parks with washrooms that are not dog parks, so we will use a Tester to filter the data. Click on the Parks reader feature type to select it. Then add a Tester to the canvas by typing “Tester” to bring up the list of FME Transformers in the Quick Add Search. Select the Tester from the list of Transformers by double-clicking or using the arrow keys and Enter to add it. 

QuickAdd.png

TesterConnect.png

Double-click on the Tester to open the Parameters. In the parameters, click on the empty box below Left Value to show the drop-down arrow. Click on the drop-down arrow, expand Attribute Values, then select Washrooms. Set the Operator to =, then type in Y for the Right Value. 

Washrooms = Y

Then, on the next line, set the test to Dog Parks = N. Change the Logic between the two tests from OR to AND. 

Tester1.png

4. Filter for Alexander Academy

Next, we want to filter for school. To filter for the school name more accurately, we can cache the features. Run the Workspace with Data Caching Enabled (formerly Feature Caching). To do this, click on the drop-down arrow next to the Run button, then select Enable Data Caching. Click on the Run button to run the workspace. The Schools dataset data will now be cached. 

FeatureCaching.png

Add another Tester to the canvas and connect the Tester_2 to the Schools reader feature type. In the Tester_2 parameters, set the Left Value to school_name, the Operator to =, then for the Right Value, click on the drop-down arrow and select Cached Values. Since there are multiple schools, this will open a Select Value dialog. 

Tester2.png

In the Select Value dialog, click on Alexander Academy, then click OK twice to confirm the test. 

SelectValue.png

5. Find Neighboring Parks

With the data filtered, we can now find which park is the closest to Alexander Academy. Add a NeighborFinder transformer to the canvas and connect the Base input port to the Tester_2 (from the Schools reader feature type). Then connect the Candidate input port to the Tester (from the Parks reader feature type). Notice how the connection lines cross; this can be fixed by right-clicking the Base port and selecting Move Down. 

Move.png

Neighborfinder.png

 

Open the NeighborFinder parameters and enable Merge Attributes; the other parameters can be left at their defaults. The default parameters return only the closest park, but if we want a list of parks, we can increase the Number of Neighbors to Find parameter. 

Merge.png

6. Keep Attributes

The NeighborFinder transformer also creates multiple attributes; since we merged attributes, we now have both sets of attributes from the Parks and Schools datasets. To clean up the output, let’s only keep the attributes we want. 

Add an AttributeKeeper transformer to the canvas and connect it to the MatchedBase output port on the NeighborFinder. 

AttributeKeeper.png

In the parameters, keep only the following attributes:

  • school_name
  • ParkName
  • _distance

AK.png

7. Run Workspace

Connect an Inspector transformer to the AttributeKeeper Output port. 

Workspace.png

Run the workspace by clicking the Run button on the top toolbar, or by selecting Run > Run Workspace from the top menu bar. 

Run.png

After running the workspace, only Andy Livingstone Park, the park with a washroom closest to Alexander Academy, will be listed. This park is 838.25 map units from the school, which, in this case, is meters. 

VP.png

Data Attribution

The data used here 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?

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.