0

I have created the following node.js code with turf.js:

const turf = require('@turf/turf')

let polygon = [
  [
    [ -46.70527960466082, -23.515693805007327 ],
    [ -46.70525061354379, -23.515706130219414 ],
    [ -46.70521688456519, -23.515720493550234 ],
    [ -46.70515408370665, -23.51574718295358 ],
    [ -46.70514380411614, -23.51575153885141 ],
    [ -46.70534467952754, -23.51614450729978 ],
    [ -46.70550423529982, -23.516075408203687 ],
    [ -46.705303857919084, -23.515683517916514 ],
    [ -46.70527960466082, -23.515693805007327 ]
  ]   
]  
let turfPolygon = turf.polygon(polygon)
let bufferedPolygon = turf.buffer(turfPolygon, 500, {units: 'meters'})

console.log(JSON.stringify(bufferedPolygon))

On this code, polygon is a polygon that doesn`t have a circular shape. However, the result that I get from this code is the following JSON:

{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-46.70322088458993,-23.511612661040875],[-46.70324513725736,-23.511602374268882],[-46.70414989865253,-23.511313190193746],[-46.70509871194889,-23.51119085258346],[-46.70605535658333,-23.51124003161756],[-46.70698331312504,-23.51145884991158],[-46.70784715697299,-23.511838954163927],[-46.70861391032006,-23.51236583394781],[-46.70925430084214,-23.51301937549594],[-46.70974387910988,-23.51377462936544],[-46.709944266799546,-23.514166513971112],[-46.71026468528243,-23.51499591890971],[-46.710402822262445,-23.515866661757098],[-46.71035338468864,-23.516745400734823],[-46.71011826193278,-23.517598487221015],[-46.70970645400013,-23.51839325424125],[-46.70913372739746,-23.519099267466057],[-46.70842201176066,-23.51968949079388],[-46.70759856029236,-23.520141321856958],[-46.70743900069192,-23.52021042308697],[-46.70653192465988,-23.520507341986136],[-46.70557904934411,-23.520635970913354],[-46.704617132929336,-23.520591347859405],[-46.70368328247596,-23.520375194211702],[-46.702813522046306,-23.5199958483299],[-46.70204140267023,-23.519467943791756],[-46.70139670784378,-23.518811844738906],[-46.70090430454788,-23.51805286013362],[-46.70070343947814,-23.517659885989946],[-46.70038195533657,-23.516825929817898],[-46.700244732646844,-23.51595040311668],[-46.700297077557394,-23.515067184373397],[-46.700536960877805,-23.514210449042604],[-46.700955097169526,-23.513413347175494],[-46.701535304545,-23.51270672082495],[-46.70225513117563,-23.51211791083629],[-46.703086724211424,-23.511669699162645],[-46.70309392009424,-23.511666649982637],[-46.703187958960925,-23.511626656930865],[-46.70322088458993,-23.511612661040875]]]}}

Going on https://geojson.io and seeing its result I see the following shape:

enter image description here

I don't get why I'm getting a circle instead of a polygon that follows the shape of my input polygon. What am I getting wrong? Why turf.buffer is returning a circular shaped polygon?

7
  • 1
    try 10m or 50m - without seeing how big your polygon is I would suspect it is too small to make a difference at 500m
    – Ian Turton
    Commented Jul 28, 2021 at 16:42
  • @IanTurton Ah yeah, I've realized now that the buffer makes the edges curved. Do you know if there's any way of making a buffer in a way that it doesn't create these circular patterns on the edges? Or I should be looking at different functions for that?
    – raylight
    Commented Jul 28, 2021 at 16:49
  • 1
    buffering inherently will create curved edges. Consider what happens at a vertex of the original polygon. The locus of points that is the buffer distance away is a circular arc. There's nothing else it could be. Maybe you're looking for transformScale, which preserves the shape, just scales it to a new size.
    – Llaves
    Commented Jul 28, 2021 at 18:43
  • 1
    Simply because the buffer is so big compared to the polygon i.imgur.com/xEvwroR.png
    – user2856
    Commented Jul 29, 2021 at 9:35
  • 1
    Here's a another way to think about a buffer - imagine taking a circle whose diameter equals your buffer distance and roll that along the outside boundary of your polygon. The area traced by the interior of the rolling circle is the buffer. When the circle is large compared to your polygon, you will get the result you saw, which is easily mistaken for a circle.
    – Llaves
    Commented Jul 29, 2021 at 20:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.