Skip to main content
FME Hub user callenbanff just uploaded a new transformer to the FME Hub.

Nearest Candidate Distance Calculator

Overview

This FME custom transformer computes the 3D Euclidean distance from each input geometry in the Base dataset to its nearest neighbor in the Candidate dataset using a scipy.spatial.KDTree. The script outputs only the calculated distance as a feature attribute, suitable for proximity analysis and model validation.

Purpose

To spatially compare two point datasets (e.g., drillholes vs. model blocks) and output a scalar distance from each Base point to its closest Candidate point.

FME Workspace Context

The workflow includes the following transformers:

VertexExtractor: Converts input geometries to point representations

PythonCaller: Executes the KDTree-based distance computation

Output Ports:

Output: Features with distance result

RejectCode: Rejected features with error metadata

Input Requirements

Two point geometry datasets:

Port

Description

Base

Input geometry features to be tested

Candidate

Reference geometry features

Each geometry is converted into XYZ coordinate attributes:

Attribute

Source

Description

X_Base

Base

Extracted X from geometry

Y_Base

Base

Extracted Y from geometry

Z_Base

Base

Extracted Z from geometry

X_Candidate

Candidate

Extracted X from geometry

Y_Candidate

Candidate

Extracted Y from geometry

Z_Candidate

Candidate

Extracted Z from geometry

Type

Assigned

Either "Base" or "Candidate"

Output

Main Output (Output port)

Attribute

Description

Easting

X coordinate from original Base point

Northing

Y coordinate from original Base point

Elevation

Z coordinate from original Base point

Distance

3D Euclidean distance to nearest Candidate

Rejection Output (RejectCode port)

Rejected features are annotated with:

Attribute

Description

fme_rejection_code

Reason code for rejection

fme_rejection_message

Descriptive rejection message

Methodology

Geometry Conversion

Input geometries are processed into XYZ attributes via VertexExtractor and AttributeManager.

Classification

Features are tagged with "Base" or "Candidate" using custom attribute assignment.

Feature Consolidation

FeatureJoiner merges all features for global analysis in the PythonCaller.

Distance Calculation

KDTree (from scipy.spatial) computes nearest neighbor distances in 3D space.

Output and Cleanup

Distance results are passed to Output. Invalid or empty input arrays are flagged and routed to RejectCode.

Dependencies

Python packages required within the FME environment:

numpy

pandas

scipy

fme, fmeobjects

References

SciPy KDTree Documentation

FME PythonCaller Documentation



Would you like to know more? Click here to find out more details!
Be the first to reply!