turf icon indicating copy to clipboard operation
turf copied to clipboard

Turf buffer buffer distance slightly off

Open mclaeysb opened this issue 7 years ago • 13 comments

Buffering points creates circles with the required radius, but buffering polygons seems to create buffers with a wrong radius. Here's an example on a very small polygon, buffered with radius 1 miles:

screen shot 2017-06-18 at 18 45 16

Radius of @turf/buffer output is to small

screen shot 2017-06-18 at 18 45 12

Buffer with correct radius

Inner object made with @turf/buffer, outer object made with this old PR of turf-buffer (but same can be made using @turf/destination).

I used this data as input.

Not sure what this is due to..

mclaeysb avatar Jun 18 '17 16:06 mclaeysb

Judging from the initial picture in #786, it seems like this might be related to that issue..

mclaeysb avatar Jun 19 '17 17:06 mclaeysb

Definitely looks like there's a bug somewhere... looks like it might be the reprojection.

DenisCarriere avatar Jun 19 '17 17:06 DenisCarriere

I'm running into the same issue:

let p1 = point([-0.12, 51.2])
let p2 = point([-0.13, 51.8])
let l1 = lineString([[-0.12, 51.2], [-0.13, 51.8]])
let d1 = lineDistance(l1, 'kilometers')
console.log('distance 1: ' + d1)
// distance 1: 66.74149167617327
let b = buffer(p1, d1, 'kilometers')
let e1 = envelope(b)
let l2 = lineString([e1.geometry.coordinates[0][0], e1.geometry.coordinates[0][1]])
let d2 = lineDistance(l2, 'kilometers')
console.log('distance 2: ' + d2 / 2)
// distance 2: 58.858493793982554
let c = circle(p1, d1, 64, 'kilometers')
let e2 = envelope(c)
let l3 = lineString([e2.geometry.coordinates[0][0], e2.geometry.coordinates[0][1]])
let d3 = lineDistance(l3, 'kilometers')
console.log('distance horizontal 3: ' + d3 / 2)
// distance horizontal 3: 67.60143597789236
let l4 = lineString([e2.geometry.coordinates[0][1], e2.geometry.coordinates[0][2]])
let d4 = lineDistance(l4, 'kilometers')
console.log('distance vertical 3: ' + d4 / 2)
// distance vertical 3: 66.74149167617331

EDIT: Corrected variable reference for e2 from b to c -> circles appear good for vertical measurements but off for horizontal measurements per @stebogit comment

songololo avatar Aug 14 '17 20:08 songololo

@shongololo it seems actually that d2 and d3 are equals in your example because e1 and e2 are both "enveloping" b. @turf/circle doesn't seem to have issues. screen shot 2017-08-14 at 11 15 02 pm

Also, you might want to measure the vertical side of the envelop (lineString([e2.geometry.coordinates[0][1], e2.geometry.coordinates[0][2]])) to compare with the vertical radius of the circle (lineString([[-0.12, 51.2], [-0.13, 51.8]])), because the projection does cause some small difference (see #684).

stebogit avatar Aug 15 '17 06:08 stebogit

@stebogit thanks, corrected the typo, circles now are good for vertical though still off for horizontal distances per discussion #684 in your comment.

songololo avatar Sep 04 '17 12:09 songololo

:+1:

stebogit avatar Sep 04 '17 14:09 stebogit

How do you guys get this circle? Turf returns an oval when I use buffer.

jaapster avatar Nov 06 '17 10:11 jaapster

Which version of turf are you using?

DenisCarriere avatar Nov 06 '17 13:11 DenisCarriere

@DenisCarriere package.json version is 3.14.3

I'll try updating to the latest version

jaapster avatar Nov 06 '17 13:11 jaapster

Yep that will help, I think the buffet got fixed in 4.5 or so

DenisCarriere avatar Nov 06 '17 13:11 DenisCarriere

@DenisCarriere Yes, that solved it, thanks!

jaapster avatar Nov 07 '17 08:11 jaapster

Hi, where to get the latest version of turf?

omar-alnayme avatar Sep 28 '20 11:09 omar-alnayme

I get the oval buffer as well.

omar-alnayme avatar Sep 28 '20 12:09 omar-alnayme

This looks suspiciously like a duplicate of #1470. Closing given it's age and similarities. If still an issue on later versions of Turf please reopen.

smallsaucepan avatar Dec 09 '23 06:12 smallsaucepan