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));
}
TomazicM
27.3k25 gold badges33 silver badges43 bronze badges
asked Mar 15, 2021 at 13:51
4
  • 1
    There is a lot of code. At which line you are getting the error? Commented Mar 15, 2021 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)); Commented Mar 15, 2021 at 15:22
  • Are you trying to do something similar to this and could that help? gis.stackexchange.com/a/388414/88814 Commented Mar 15, 2021 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. Commented Mar 15, 2021 at 15:44

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.