I have two geojson data sets. One of them is polygon feature "yolbuf" and the other one is a polygon feature collection "polygon". I want to calculate intersections of every feature in polygon feature collection and add these intersected polygon geometries to my map. But I can not calculate intersection. I cerate a loop for every feature in "polygon" feature collection and calculate intersections using turf.js but I receive an error "geojson must be a valid Feature or Geometry Object" for the line where I call turf intersection function. I could not figure it out. Any help would be very helpfull. Here is my code that I tried so far:
var polygon =
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
33.23123550240566,
39.92248701096464
],
[
33.23151584974473,
39.92228723799442
],
[
33.23143457753136,
39.92220902313792
],
[
33.2313766303031,
39.92214733535532
],
[
33.23102868523483,
39.92232101813538
],
[
33.23123550240566,
39.92248701096464
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
33.23123550240566,
39.92248701096464
],
[
33.23151584974473,
39.92228723799442
],
[
33.23143457753136,
39.92220902313792
],
[
33.2313766303031,
39.92214733535532
],
[
33.23102868523483,
39.92232101813538
],
[
33.23123550240566,
39.92248701096464
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
33.23102868523483,
39.92232101813538
],
[
33.2313766303031,
39.92214733535532
],
[
33.23135637097489,
39.92212650848449
],
[
33.23127259690326,
39.92202385548821
],
[
33.23088430660423,
39.92220634322857
],
[
33.23090957419321,
39.9222345005147
],
[
33.23102868523483,
39.92232101813538
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
33.23102868523483,
39.92232101813538
],
[
33.2313766303031,
39.92214733535532
],
[
33.23135637097489,
39.92212650848449
],
[
33.23127259690326,
39.92202385548821
],
[
33.23088430660423,
39.92220634322857
],
[
33.23090957419321,
39.9222345005147
],
[
33.23102868523483,
39.92232101813538
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
33.23106496596528,
39.92212143765926
],
[
33.23093691284885,
39.92195591156596
],
[
33.23075984311377,
39.92201316928995
],
[
33.23079351450731,
39.92209278466239
],
[
33.23084284247113,
39.92216013703721
],
[
33.23088430660423,
39.92220634322857
],
[
33.23106496596528,
39.92212143765926
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
33.23106496596528,
39.92212143765926
],
[
33.23093691284885,
39.92195591156596
],
[
33.23075984311377,
39.92201316928995
],
[
33.23079351450731,
39.92209278466239
],
[
33.23084284247113,
39.92216013703721
],
[
33.23088430660423,
39.92220634322857
],
[
33.23106496596528,
39.92212143765926
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
33.23127259690326,
39.92202385548821
],
[
33.23122986841128,
39.92197283593117
],
[
33.23116334430379,
39.92188269157665
],
[
33.23095417047043,
39.92195033107802
],
[
33.23093691284885,
39.92195591156596
],
[
33.23106496596528,
39.92212143765926
],
[
33.23127259690326,
39.92202385548821
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
33.2296955135001,
39.92243952105167
],
[
33.22980597686984,
39.9222961545936
],
[
33.22960217368549,
39.92221433149345
],
[
33.22945999098032,
39.92240277126455
],
[
33.2296955135001,
39.92243952105167
]
]
]
}
}
]
};
var yol = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"genislik": 15
},
"geometry": {
"type": "LineString",
"coordinates": [
[
33.2292425071561,
39.92113004776218,
0
],
[
33.229473546304,
39.92133376987435,
0
],
[
33.22950227387721,
39.92138603150682,
0
],
[
33.22960053796574,
39.92157730010621,
0
],
[
33.22965706684388,
39.92175869708733,
0
],
[
33.22970824225857,
39.92193301273533,
0
],
[
33.22974032375962,
39.92199270354748,
0
],
[
33.22978752905556,
39.92205207615689,
0
],
[
33.22983673278315,
39.92210059742482,
0
],
[
33.22990544410934,
39.92214802439388,
0
],
[
33.23003228674187,
39.92224919395576,
0
],
[
33.23012431533797,
39.92230792049544,
0
],
[
33.23021705388681,
39.92235584040844,
0
],
[
33.23029337496003,
39.92238853644901,
0
],
[
33.23039243416922,
39.92242594245815,
0
],
[
33.2304371756197,
39.92245401139586,
0
],
[
33.23047032061119,
39.92249271442368,
0
]
]
}
}
]
};
var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
var myStyle2 = {
"color": "#483D8B",
"weight": 5,
"opacity": 0.65
};
var myStyle3 = {
"color": "#DC143C",
"weight": 5,
"opacity": 0.65
};
var myStyle4 = {
"color": "#00CED1",
"weight": 5,
"opacity": 0.65
};
L.geoJSON(polygon, {
style: myStyle
}).addTo(mymap);
L.geoJSON(yol, {
style: myStyle2
}).addTo(mymap);
var road = new L.GeoJSON(yol, {style:myStyle3});
road.addTo(mymap);
var buffered = turf.buffer(road.toGeoJSON(), 0.02, {units: 'kilometers'});
var yolbuf = new L.GeoJSON(buffered, {style:myStyle3});
yolbuf.addTo(mymap);
var parseller = polygon.features;
intersections = [];
for (var i = 0; i < parseller.length; i++ ){
var parsel = parseller[i];
var intersection = turf.intersect(parsel, yolbuf);
if (intersection != null){
intersections.push(intersection);
}
}
Best Answer
Your buffer distance was too small to touch a parcel boundary; This is your code working: