npoints does not work correctly for greatCircle for anti-meridian cases
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 10.5k
- Forks
- 1k
- Avg merge
- 1h 11m
- Merged PRs (30d)
- 4
Description
Hi,
We are on v6.5.0. In order to improve performance we limit the no of points we want drawn in greatCircle using the "npoints" optional parameter. We observe it to not be working correctly for when line crosses the anti-meridian.
fyi - the coordinates specified below cross anti-meridian
Without "npoints" -
const fromLat = -33.868801, fromLng = 151.209305
const toLat = 34.052235, toLng = -118.243683
const feature = turf.greatCircle([fromLng, fromLat], [toLng, toLat])
We observe that "MultiLineString" is returned and line is plot correctly.

With "npoints" -
const MAX_POINTS_PER_LINE = 20
const fromLat = -33.868801, fromLng = 151.209305
const toLat = 34.052235, toLng = -118.243683
const feature = turf.greatCircle([fromLng, fromLat], [toLng, toLat], {
npoints: MAX_POINTS_PER_LINE,
})
We observe that feature gets converted to LineString and the line goes around the globe instead.

JSFiddle - https://jsfiddle.net/sakshibhasin96/14f0ot76/
It is observed that without the limit on no of points, the MultiLineString takes 31 and 71 points respectively to plot from "from" coordinate to -180/180 and to plot from -180/180 to "to" coordinate. (Please check jsfiddle)
It seems the issue here is that instead of applying "npoints" to each LineString constituting the MultiLineString, it is instead converting the MultiLineString to LineString which is not the expected behaviour.
Thank you for your time.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the greatCircle entry point and reproduce the v6.5.0 behavior using the linked JSFiddle, comparing calls with and without npoints. Done means an anti-meridian route remains a MultiLineString when npoints is set, with the point limit applied to its constituent LineStrings rather than connecting across the globe.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100