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.

turf.lineOffset precision

See original GitHub issue

Hello, I’m using line offset to build parallels to short segments (a few kilometers long) but I found an issue with the precision of the function:

const turf = require('@turf/turf')
const line = turf.lineString([ [4.35,50.845], [4.347,50.85] ])
const parallel = turf.lineOffset(line, 1) // kilometer
const distance0 = turf.distance(line.geometry.coordinates[0], parallel.geometry.coordinates[0])
const distance1 = turf.distance(line.geometry.coordinates[1], parallel.geometry.coordinates[1])
console.log(distance0, distance1)
// output: 0.7468818837096454 0.7468398187109684

This can be reproduced at other places in the world. Any idea on how to improve precision? Thanks.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
PereUbu7commented, Apr 8, 2021

I made a PR for this: https://github.com/Turfjs/turf/pull/1949 But couldn’t get my env going, so it’s untested.

1reaction
devleakscommented, Apr 7, 2021

To be honnest, I redid the function I needed, it is quite easy: For line (p1, p2), compute the bearing p1->p2. Add or substract 90° to the bearing. Use “destination” function to compute a point with calculated bearing and supplied distance from p1 and from p2. I understand this might not be a “parallel” in spherical geometry, but for short segments (a dozen kilometer long), it is acceptable. I will not work for larger segments. Regards. P.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced geospatial analysis - Turf.js
Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the ... will need to import @turf/line-offset and call the lineOffset method....
Read more >
@turf/line-offset - npm
@turf/line-offset. TypeScript icon, indicating that this package has built-in type declarations · Readme · Code Beta · 3 Dependencies · 8 Dependents ...
Read more >
@turf/line-offset | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Turfjs/turf - Gitter
This definition is listed in a few places, and I think it is a good (reasonably precise) description: "A buffer is an area...
Read more >
Top 5 @turf/invariant Code Examples - Snyk
Learn more about how to use @turf/invariant, based on @turf/invariant code examples ... {precision: 7}); switch (splitterType) { case 'Point': return ...
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