Turf: Turf buffer buffer distance slightly off

Created on 18 Jun 2017  路  13Comments  路  Source: Turfjs/turf

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..

bug remove-jsts

All 13 comments

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

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

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

@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 thanks, corrected the typo, circles now are good for vertical though still off for horizontal distances per discussion #684 in your comment.

:+1:

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

Which version of turf are you using?

@DenisCarriere package.json version is 3.14.3

I'll try updating to the latest version

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

@DenisCarriere Yes, that solved it, thanks!

Hi, where to get the latest version of turf?

I get the oval buffer as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rheh picture rheh  路  5Comments

DenisCarriere picture DenisCarriere  路  3Comments

stebogit picture stebogit  路  5Comments

tsemerad picture tsemerad  路  4Comments

morganherlocker picture morganherlocker  路  5Comments