[GIS] Buffer and intersect using turf.js and leaflet

bufferintersectleafletturf

I have 2 geojson feature collections in leaflet. One of them is road and the other one is parcels. I want to calculate buffer for road and then intersect this buffer layer with parcels. How can I do this using turf.js and leaflet. I am a newby in both of them. I tried to write a little script but it does not work. Could you tell me what ı am doing wrong. Here is a little part of my code that I wrote so far:

  var buffered = turf.buffer(road, road.width, {units: 'meters'});
  var roadbuf = L.polygon(buffered, {style:myStyle}).addTo(mymap);

Best Answer

Try something like this.

var buffered = turf.buffer(road.toGeoJSON(), road.width, {units: 'meters'});
var roadbuf = L.polygon(buffered, {style:myStyle}).addTo(mymap);

A Leaflet layer is not quite the same thing as a Turf GeoJSON layer.