Input geometry is not a valid Polygon in turf.js

Viewed 622

I try to use turf.js and its function intersect in my Leaflet project. My original question can be found here. The problem is I cannot get a proper polygon in order to call it. The idea is to get the waypoints of the calculated route make a polgyon out of them and check where they intersect with a given buffered area.

    var testpoint = turf.point([9.9354, 49.799]);
    var buffered = turf.buffer(testpoint, 50, {units: 'meters'});
    
    var array = []
    control._routes[0]['coordinates'].forEach(function(e){

      array.push([e['lat'],e['lng']])
      
    });

    var test = turf.polygon(L.polygon([[array]]))
    var intersection = turf.lineIntersect(buffered, test)

I am getting the following error message:

Uncaught Error: Input geometry is not a valid Polygon or MultiPolygon

Here I have to point out that, when using line.intersect(buffered,buffered) it is working correctly, therefore I am assuming that the buffered variable is correct.
When it comes down to the test variable, I have tried with no [], one pair and double pair. But they all result in the same problem. I also tried to pass the array to turf.polygon but it couldn`t be done.

0 Answers
Related