I am trying to return attributes of polygons (from the SAC feature) that intersect the buffer created around the route, but I keep getting:
Uncaught Error: geojson must be a valid Feature or Geometry
Here is my code:
/*OVERLAYS*/
var SAC = L.geoJson({{ sac }} , {
style: function(feature) {
return {
color: "black",
fill:'url(img/image.gif)',
weight: 1,
opacity: 0.8
};
},
onEachFeature: function(feature, layer) {
const p = feature.properties
p.title = p.SAC_NAME || p.name
layer.on('mouseover', function() {
this.setStyle({
'fillColor': '#0000ff'
});
});
layer.on('mouseout', function() {
this.setStyle({
'fillColor': 'transparent'
});
});
//mouse tooltip properties
if (p && p.name) {
layer.bindTooltip(p.name, {
closeButton: false,
offset: L.point(0, -20)
});
layer.on('mouseover', function() {
layer.openPopup();
});
layer.on('mouseout', function() {
layer.closePopup();
});
}
}
})
Add buffer layer around route:
document.getElementById('radius').onchange = function() {
var radius = parseInt(document.getElementById('radius').value);
// if (isNaN(radius)) radius = 500;
var buffered = turf.buffer(PreferredTerrestrialRoute.toGeoJSON(), radius , {units: 'kilometres'});
map.removeLayer(roadbuf);/* remove existing laer*/
roadbuf = new L.GeoJSON(buffered, {
style: function(feature) {
return {
color: "green",
fill:"green",
weight: 1,
// fillColor: "transparent",
// color: "blue",
opacity: 0.8
};
},
})
map.addLayer(roadbuf)
var polyintersect = turf.intersect(SAC.toGeoJSON(), roadbuf.toGeoJSON());
console.log( polyintersect.features.length +" points in this poly");
alert("results "+JSON.stringify(ptsWithin4));
}
TomazicM
27.3k25 gold badges33 silver badges43 bronze badges
lang-js
turf.intersect
expects two GeoJSON polygons, so there is something wrong with eitherSAC.toGeoJSON()
orroadbuf.toGeoJSON()
. Examine contents of those two.