I'm working on a buffer analysis and then intersection using turf.js. I have a buffered output layer to which I need to intersect another polygon layer and get the output. Below is my code,
function calculateBuffer() {
var fc1 = turf.featureCollection(fc1Layer.getLayers().map(function(f){
return f.toGeoJSON()
}));
var buffer = turf.buffer(fc1, 5, 'kilometers');
buffer.properties = {
"fill": "#6BC65F",
"stroke": "#25561F",
"stroke-width": 2
};
bufferLayer.setGeoJSON(buffer);
//var bufferGeojson=bufferLayer.setGeoJSON(buffer);
//polygon layer//
var fc = turf.featureCollection(fcLayer.getLayers().map(function(f){
return f.toGeoJSON()
}));
//buffer layer//
var buffer = turf.featureCollection(bufferLayer.getLayers().map(function(f){
return f.toGeoJSON()
}));
//intersection//
var polygon = turf.intersect(fc,buffer);
polygon.properties = {
"fill": "#25561F",
"stroke": "#25561F",
"stroke-width": 10
};
intersectLayer.setGeoJSON(polygon);
}
I'm getting the following error:turf.min.js:16 Uncaught TypeError: o.intersection is not a function. Could anyone help me on this?
Best Answer
I think
turf.intersect()
takes only single features withPolygon
geometry as arguments.You should separate your layers into individual Polygons and compute the intersection between your 2 sets of Polygons by iteration.