Closed mourner closed 7 years ago
@mourner Would refactoring @turf/point-on-line
lineIntersects() with @turf/line-intersect
solve this issue?
Gday @DenisCarriere & @mourner
It looks like replacing the lineIntersects
function with @turf/line-intersect
will address the issue. The screenshot below is taken at 80degs latitude.
.
Will tidy up the rejigged code and will put in a pull request, a couple of tests to fix up, but other than that it was a pretty straightforward replacement.
👍 Good catch, @turf/line-intersect
does sound like it would fix this issue (with some "rejigging").
👍 Looks like this got fixed in https://github.com/Turfjs/turf/issues/689.
Added a test case for it: test/in/line-northern-latitude-#344.geojson
The
point-on-line
module doesn't return correct results. Take a look at the official example with a connection line added:As you can see, the line isn't perpendicular, so the snapped point isn't actually the closest one. This happens because the
lineIntersects
routine that's used to calculate the intersection point between a line segment and a line perpendicular to it from the point does the calculation on latitude/longitude values as if they were cartesian coordinates, while they are not — at a local scale, the ratio between latitude and longitude deltas is approximatelycos(latitude)
, not1
.On higher latitudes, the distortion will be more pronounced. Here's how the same example looks on latitude ~78:
cc @morganherlocker @tmcw @tcql