FME Version
Files
-
- 800 KB
- Download
Introduction
In this tutorial, you will learn how to find the nearest point from a point of interest based on the straight line distance between features. This is done in FME using the NeighborFinder transformer, which can be used to identify the nearest features, features within a specified distance, or the closest feature in a certain direction.
The NeighborFinder locates the nearest feature(s) and transfers its attributes to create a record of that neighbor. It also adds attributes to record the distance and bearing (angle) to that neighbor.
To learn how to find nearest neighbors with non-point features, such as polygons, see the Find Nearest Features article.
Step-by-Step Instructions
In this scenario, we have residential address points in an Esri File Geodatabase and cell phone tower locations in a CSV (Comma-Separated Value) file.We want to find the nearest tower to each address and write that information into a new address dataset.
Download the attached workspace template and source data to follow along.
1. Generate a new workspace
Open FME Workbench and choose Generate Workspace. Set the reader and writer as follows:
- Reader Format: Esri Geodatabase (File Geodb Open API)
- Reader Dataset: <Path to tutorial download>/Addresses.gdb
- Writer Format: Esri Geodatabase (File Geodb Open API)
- Writer Dataset: <Path to tutorial download>/NewAddresses.gdb
Note we are writing to a new Geodatabase instead of updating the same one.
Click OK. When prompted, select only the PostalAddress table, not the PostcodeBoundaries table.
Click OK.
The generated workspace should include a Geodatabase reader and writer.
2. Add writer attributes
Double-click the writer feature type to open its Feature Type Properties dialog. Click the User Attributes tab and add two new attributes:
- Name: STATIONID, Type: int
- Name: STATIONDISTANCE, Type: double
3. Add a CSV reader
Click the Add Reader icon and add a reader with the following parameters:
- Format: CSV (Comma Separated Value)
- Dataset: <Path to tutorial download>/CellTowers.csv
- Coord. System: LL84
If you click Parameters, you will notice the reader automatically sets the data type for the longitude attribute to x_coordinate, and the data type for the latitude attribute to y_coordinate.
Click OK. The workspace now includes two readers.
4. Add a Reprojector transformer
Before we use the NeighborFinder, we have to get the datasets into the same coordinate system. Add a Reprojector transformer and connect it after the CSV (cell tower) feature type. Open the parameters and configure it as follows to reproject the data to UTM83-10.
Click OK.
5. Add a NeighborFinder transformer
Add a NeighborFinder transformer. Connect the PostalAddress feature type to the Base port, and connect the Reprojector to the Candidate port. Connect the MatchedBase output port to the writer feature type.
Open the NeighborFinder parameters dialog.
- We only need to find 1 nearest feature, so leave Number of Neighbors to Find set to 1
- Set Maximum Distance to 500
- Under Attribute Accumulation, check Merge Attributes
Click OK.
6. Map attributes
Expand the attributes on the NeighborFinder:MatchedBase output port and the writer feature type. Map StationID to STATIONID on the writer and _distance to STATIONDISTANCE.
Alternatively, you can use an AttributeManager transformer to map the attributes.
7. Run the workspace
Run the workspace and inspect the output. Each address should now include attributes that record the nearest cell phone tower (STATIONID) and the distance to that tower (STATIONDISTANCE).
Tips
You may want to attach an Inspector transformer to the NeighborFinder:UnmatchedBase port to catch any addresses that did not find a matching tower within 500 metres.
To find out how many towers are within 500 metres of an address, open the NeighborFinder parameters dialog. Delete the value of the Number of Neighbors to Find parameter so FME no longer stops at a single neighbor. Enter a value (such as "MyList") in the Close Candidate List Name parameter. A list of towers will now be created on the output and can be counted using the ListElementCounter transformer. This will take longer to run. To learn more about working with list attributes, see the Tutorial: Getting Started with List Attributes.
Comments
0 comments
Please sign in to leave a comment.