0

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));

}
4
  • 1
    There is a lot of code. At which line you are getting the error? – TomazicM Mar 15 at 14:22
  • @TomazicM this line var polyintersect = turf.intersect(SAC.toGeoJSON(), roadbuf.toGeoJSON()); console.log( polyintersect.features.length +" points in this poly"); alert("results "+JSON.stringify(ptsWithin4)); – lloyd Mar 15 at 15:22
  • Are you trying to do something similar to this and could that help? gis.stackexchange.com/a/388414/88814 – Babel Mar 15 at 15:39
  • turf.intersect expects two GeoJSON polygons, so there is something wrong with either SAC.toGeoJSON() or roadbuf.toGeoJSON(). Examine contents of those two. – TomazicM Mar 15 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.