This gem runs in .
Overview
Find the closest spatial point(s) between two datasets based on geographic distance. This gem compares each point in the first dataset to all points in the second dataset and returns the nearest matches.Prerequisites
- Add
ProphecyDatabricksSqlSpatialversion 0.0.3 or higher to your project.
Input and Output
The output schema of out contains:
- All columns from in0.
- All columns from in1.
rank_number: The rank of each match, where1is the closest point.distance: The calculated distance between the source and target points in the unit of measurement that you specify.cardinal_direction: The compass direction from the source point to the target point (e.g.,NWfor northwest).
Geographic points must be in Well-known Text
(WKT) format. Use the
CreatePoint gem to convert longitude and latitude
coordinates to WKT format.
Parameters
Configure the FindNearest gem using the following parameters.Spatial Object Fields
Select Output Options
Example: Customer service centers
Assume you have two tables:-
customer_locationsthat contains the location of each customer. -
service_centersthat contains the location of each service center.
- Add the FindNearest gem to your pipeline canvas.
- Connect the
customer_locationstable to the FindNearestin0input port. - Connect the
service_centerstable to the FindNearestin1input port. - Open the FindNearest gem configuration.
- For Source Centroid Type, select Point.
- For Source Centroid Column, select the
customer_pointcolumn. - For Target Centroid Type, select Point.
- For Target Centroid Column, select the
center_pointcolumn.
- Type
2in the How many nearest points to find? field. - Type
1000and choose Kilometers in the Maximum distance field. - Lastly, save and run the gem.
Result
The output contains the two closest service centers to each customer. Ranks begin at1, with 1 being the closest point. Note that customer C002 only has one service center within 1000 km from their location.

