question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Find nearest position on a linestring

See original GitHub issue

Is there a way to determine the nearest position on a linestring to a given point? I’m looking to snap a point to its closest position on a line.

nearestPointOnLine returns the nearest vertex while pointToLineDistance returns the distance to the nearest position, but not the actual coordinate.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
wishinghandcommented, Feb 26, 2019

Oh hell, I just figured it out. Turf uses Long/Lat, and Leaflet uses Lat/Long.

0reactions
wishinghandcommented, Feb 26, 2019

Something I noticed when I put my numbers into a fiddle for demonstrating this function is that it’s waaaay off.

Compare a jsfiddle with real numbers that we’d use here: https://jsfiddle.net/wishinghand/jeb1o72p/2/

and one with numbers I had to tweak in order for it not to be in Antarctica: https://jsfiddle.net/wishinghand/mjtz6yLc/10/

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get the nearest point on a linestring to a given point?
The solution I found is to select all the linestrings within my point using the expand() method and determine the distance between each...
Read more >
How to find closest point to a linestring in python?
I want to find a closest point to a linestring. I tried something but I guess it doesn't work. How can I do...
Read more >
ST_LineLocatePoint - PostGIS
Returns a float between 0 and 1 representing the location of the closest point on a LineString to the given Point, as a...
Read more >
ST_NearestPoints function - IBM
This example finds the nearest points on the linestring to the point with coordinates (10,0). In this case, the nearest point is at...
Read more >
get index of nearest feature — st_nearest_feature • sf - r-spatial
st_nearest_points for finding the nearest points for pairs of feature geometries ... ls2, ls3)) #> Geometry set for 3 features #> Geometry type:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found