---
title: "The Distance Model Can Change Which AI Neighbor Is Nearest"
description: "Leviathan Systems — Technical content Published 2026-10-21; updated 2026-10-21."
canonical: "https://www.leviathansystems.co/articles/geospatial-ai-coordinate-distance-neighbor-model"
last-updated: "2026-10-21"
---

# The Distance Model Can Change Which AI Neighbor Is Nearest

Leviathan Systems — Technical content
Published 2026-10-21; updated 2026-10-21.

Compare the offered distance model with the spatial-neighbor rule required by the AI feature. Correctly interpreted coordinates can still produce different nearest neighbors under different metrics. In the invented example here, a Cartesian comparison of degree coordinates selects B; shortest surface arcs on an explicitly defined sphere select A. A radius requirement also needs its model and units attached.

## Define what near means for the feature

Here, a neighbor is a geographic observation selected to supply an AI feature. The feature might carry the nearest observation's attribute or summarize observations within a radius. Its definition therefore needs to say which distance determines selection.

Treat the reference point, eligible observations and their interpreted positions as agreed inputs. The related GeoJSON/WMS guide explains the axis-order question. This article starts after that interpretation is resolved and asks what distance the recipient assigns between those positions.

If a feature carries the nearest observation's value, changing the selected neighbor changes whose value enters the feature. That is a change in feature construction. Its effect on model quality requires separate evidence.

## PostGIS 3.6 separates coordinate-plane and surface distance

The PostGIS 3.6 ST_Distance reference defines geometry distance as minimum two-dimensional Cartesian separation in spatial-reference units. Its EPSG:4326 geometry example uses degrees. A numeric result therefore needs its reference system and units.

For geography, the default is minimum geodesic separation in meters on the spheroid selected by the SRID. Setting use_spheroid to false selects a spherical calculation. Sphere and spheroid remain distinct models.

A meter unit alone also leaves projection distortion unresolved. Identify the actual model and its applicability to the feature's requirement before treating an offered distance as equivalent.

References: [D1](https://postgis.net/docs/manual-3.6/ST_Distance.html)

## GEO-N2: the degree-coordinate plane selects B

GEO-N2 is an invented two-dimensional comparison with longitude written first and latitude second, both in degrees. The reference is P = (0, 60). The only eligible candidates are A = (0.01, 60) and B = (0, 60.009). Their axis interpretation is a premise.

Define the coordinate-plane metric as d_plane = √((Δlongitude)² + (Δlatitude)²), using the numeric degree differences. A differs from P only in longitude, giving d_plane(P,A) = √(0.01² + 0²) = 0.01°. B differs only in latitude, giving d_plane(P,B) = √(0² + 0.009²) = 0.009°.

Under this metric, B is nearer because 0.009 is less than 0.01. The calculation consistently answers the coordinate-plane question it was given. Whether it answers the intended feature definition remains a separate comparison.

## The stipulated sphere selects A

Now keep the positions and candidate set unchanged, but define distance as the shortest surface arc on a hypothetical sphere with radius R = 6,371,000 m. All results in this case are mathematical derivations from that sphere. They are neither PostGIS outputs nor exact WGS84 spheroidal distances, and they describe no terrain or travel route.

For longitude λ and latitude φ expressed in radians, the spherical relation is h = sin²((φ₂ − φ₁)/2) + cos(φ₁) cos(φ₂) sin²((λ₂ − λ₁)/2), followed by d_sphere = 2R asin(√h). The formula includes latitude in the longitude contribution; the coordinate-plane norm gives equal weight to a numeric degree on either axis.

P and A have equal latitude, 60° = π/3 radians. Their longitude difference is 0.01°. Substitution gives d_sphere(P,A) = 2R asin(cos(π/3) sin(0.01π/360)), approximately 555.9746 m.

P and B share a meridian. Their latitude difference is 0.009°, so d_sphere(P,B) = R × 0.009π/180, approximately 1,000.7543 m.

A is nearer on this sphere. The ranking reversal follows from changing the metric while retaining the same points. No single degrees-to-meters multiplier can reverse the coordinate-plane ranking, because multiplying both coordinate distances by the same positive constant preserves their order.

## A 700 m radius includes only A

Define a second feature using all eligible observations whose spherical distance from P is at most 700 m, with the same R. A qualifies because approximately 555.9746 m is below 700 m. B does not, because approximately 1,000.7543 m exceeds it. The resulting neighbor set is {A}.

Nearest-neighbor selection and radius membership answer different questions. With these two candidates, nearest-neighbor selection returns one observation under either metric, but the observation's identity changes. The spherical radius rule additionally excludes B.

Comparing the degree-coordinate values 0.01 and 0.009 directly with the number 700 would mix units. The radius requirement needs a distance expressed under its stated surface model; retaining the same coordinates alone does not supply it.

## Check the operation that actually selects neighbors

A platform or data-type label can leave the selection operation unresolved. The PostGIS 3.6 nearest-neighbor operator reference documents spherical geography KNN distance for PostgreSQL 9.5 and later. This differs from the spheroidal default of geography ST_Distance.

A reported spheroidal distance for an already selected observation establishes that observation's distance. It does not establish which rule selected the observation from the full eligible set. Ask the provider to identify the rules used to select the neighbor and report its distance.

The radius operation has its own contract. PostGIS 3.6 ST_DWithin uses spatial-reference units for geometry and requires the same coordinate system. Geography thresholds are in meters, with spheroidal measurement by default and a spherical option.

For a combined nearest-within-radius feature, establish the model used at each boundary: which candidates pass the radius condition, and how the surviving candidates are ranked. If an intermediate candidate screen is offered, its evidence needs to explain how it preserves the neighbors required by the final rule.

References: [K1](https://postgis.net/docs/manual-3.6/geometry_distance_knn.html), [D1](https://postgis.net/docs/manual-3.6/ST_Distance.html), [R1](https://postgis.net/docs/manual-3.6/ST_DWithin.html)

## Compare offers against one feature definition

Consider two fictional offers for GEO-N2. Offer Plane defines selection by the Cartesian norm of the supplied degree coordinates and returns B. Offer Sphere defines selection by shortest arcs on the specified 6,371,000 m sphere and returns A, with {A} for the 700 m radius requirement.

If the required feature uses that sphere, Offer Sphere matches the stipulated mathematical selection and Offer Plane answers a different distance question. If the feature explicitly requires coordinate-plane proximity, Offer Plane supplies that rule. A requirement for spheroidal distances needs its own evidence; the invented sphere's numbers cannot establish that deliverable.

For a real offer, obtain an example that identifies the reference and candidate positions, coordinate reference, distance model and parameters, actual selection operation, units, resulting distances and selected identifiers. Keep the eligible population fixed while comparing metrics. Resolve ties, empty neighbor sets and any radius-boundary convention where those cases affect the feature.

This comparison makes the provider's distance claim assessable without choosing a universal geometry or geography type. The related COG guide addresses which raster samples are supplied. Raster resolution, coordinate interpretation and spatial-neighbor selection each contribute a different part of the intended AI input.

## Scope any surrounding physical cabling separately

If the selected storage and compute equipment independently needs physical connections, Leviathan's Structured Cabling & Fiber Installation service is the relevant route for agreed installation, dressing, endpoint labels and connection records. Use the related project inquiry to share a nonconfidential outline of the equipment, site, approved endpoints and material responsibilities. Geospatial processing and AI feature implementation remain with the appointed data and software providers.

References: [L1](https://www.leviathansystems.co/services/structured-cabling)

## Primary sources

- [D1 — PostGIS 3.6: ST_Distance](https://postgis.net/docs/manual-3.6/ST_Distance.html). Checked 2026-10-21. Defines geometry and geography distance semantics and illustrates differing coordinate units and surface models.
- [K1 — PostGIS 3.6: nearest-neighbor distance operator](https://postgis.net/docs/manual-3.6/geometry_distance_knn.html). Checked 2026-10-21. Documents geography KNN's spherical model and the PostgreSQL 9.5-and-later behavior discussed here.
- [R1 — PostGIS 3.6: ST_DWithin](https://postgis.net/docs/manual-3.6/ST_DWithin.html). Checked 2026-10-21. Defines radius-test units, geometry coordinate-system requirements and geography surface-model options.
- [L1 — Leviathan Systems: Structured Cabling & Fiber Installation](https://www.leviathansystems.co/services/structured-cabling). Checked 2026-10-21. Describes the separately agreed physical equipment-cabling scope and connection records.

## Related Leviathan resources

- [GeoJSON and WMS: establish coordinate interpretation first](/articles/geospatial-ai-geojson-wms-axis-order)
- [GeoTIFF: distinguish raster resolution from storage tiles](/articles/geospatial-ai-cog-overview-resolution-window-tiles)
- [Structured Cabling & Fiber Installation](/services/structured-cabling)
- [Discuss a separate physical equipment-cabling project](/contact?service=structured-cabling&from=%2Farticles%2Fgeospatial-ai-coordinate-distance-neighbor-model)
- [Two Model Paths Can Refer to One Mutable File](/articles/ai-model-hardlink-names-shared-file-identity)

## Does the surrounding equipment need physical cabling?

Share a nonconfidential outline of the equipment, site, approved endpoints and material responsibilities to discuss a separate physical installation and handoff.

[Discuss the scope](/contact?service=structured-cabling&from=/articles/geospatial-ai-coordinate-distance-neighbor-model)
