Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript

Home Page:https://turfjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

destination() 90 degrees confusion

molexx opened this issue · comments

When using destination() with a bearing of 90 degrees I think I expect the result to be at the same latitude but it is not - in the example below the start point is at 20 degrees latitude and the result point is at 16 degrees.

Am I misunderstanding what this is supposed to do?

I'm using destination() three times to calculate the corners of a level rectangle where I have the ground width and height in km.

Thank you.

$ node

let destination = await import('@turf/destination')
destination.default([0,20], 4000, 90)

result:

{
  type: 'Feature',
  properties: {},
  geometry: {
    type: 'Point',
    coordinates: [ 37.6824696535442, 16.069040661633917 ]
  }
}

Versions:

$ npm list | grep turf
├── @turf/center@7.0.0
├── @turf/destination@7.0.0
├── @turf/distance@7.0.0
├── @turf/helpers@7.0.0
├── @turf/point-to-line-distance@7.0.0
├── @turf/projection@7.0.0
├── @turf/transform-rotate@7.0.0

(6.5 also had the same behaviour)

Hi @molexx. This is the correct behaviour for @turf/destination

Short answer - try @turf/rhumb-destination instead. That's uses a different way to calculate the finish point. Think of it as working on a flat paper map. The result from your example would come out to [ 38.28146965642418, 20.000000000000004 ] instead.

Longer answer - @turf/distance calculates the final point on a globe using a great circle. You can see in the second diagram on that page that the slice of the great circle doesn't follow latitude lines, even if you were to start out walking exactly due east / 90 degrees.

Hope that helps!

Hi @smallsaucepan , thank you for the explanation, it makes sense. And yes rhumb-destination does what i need. Thank you!