Skip to content

Improve distance computation and add distance tool#156

Open
LionelZoubritzky-IGN wants to merge 7 commits into
ignfab:mainfrom
LionelZoubritzky-IGN:betterdistance
Open

Improve distance computation and add distance tool#156
LionelZoubritzky-IGN wants to merge 7 commits into
ignfab:mainfrom
LionelZoubritzky-IGN:betterdistance

Conversation

@LionelZoubritzky-IGN

Copy link
Copy Markdown

Replace the previous distance helper implementation with a purely turf-based implementation (1c7885d).

Also add a distance tool to expose this primitive to the LLM for the specific case of point-to-point computation. This tool works with four different profiles:

  • direct: distance as the crow flies (close Distance between two points tool #138).
  • vincenty for exact ellipsoid distance.
  • car and pedestrian: distances along an itinerary, computed with the Geoplateforme.

With the two latest mode, the time of travel is also returned. The itinerary can be chosen as the shortest time or the shortest distance.

@esgn

esgn commented Jun 25, 2026

Copy link
Copy Markdown
Member

@LionelZoubritzky-IGN Would have been nice to have the details of what was done on the distance calculation algorithm

@LionelZoubritzky-IGN

LionelZoubritzky-IGN commented Jun 25, 2026

Copy link
Copy Markdown
Author

Sure! That's commit 1c7885d

Input

Two geometries gA and gB

Previous algorithm

Find the two points A in gA and B in gB that minimizes the A-B distance using DistanceOp from jsts. According to the comments in the code, this projected gA and gB in flat-Earth approximation.
Then, the returned distance was the geodesic distance between A and B, obtained from turf.

New algorithm

Split all geometry cases:

  • if one is a Point and the other is a Point, use @turf/distance.
  • if one is a Point and the other is a LineString, use @turf/pointToLineDistance.
  • if one is a Point and the other is a Polygon: return 0 if @turf/booleanPointInPolygon, otherwise decompose the polygon into its constitutive LineStrings and use the minimum of @turf/pointToLineDistance on them.
  • otherwise: return 0 if @turf/booleanIntersects, else decompose each geometry into a set of points (ptsA and ptsB) and a set of segments (segsA and segsB), and compute the minimum of the distances between each point of one geometry and each segment of the other geometry using pointToLineDistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Distance between two points tool

2 participants