Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect intersection Turf.js, First and last Position are not equivalent

Utilizing Turf.js version 3.0.12. The function below should return the intersection between the two polygons or null if they do not intersect. The polygons do intersect. I have tried several different polygons and receive the same error:

"Error: First and last Position are not equivalent."

I referenced this example: http://turfjs.org/docs#intersect

checkForIntersection = () => {
    const boundingBox1 = turf.polygon([
      [
        [-11638128.151894445, 4697704.8042823635],
        [-11538591.465504704, 4932847.347657125],
        [-11773734.008879466, 5032384.034046866],
        [-11873270.695269207, 4797241.490672104]
      ]
    ]);

    const boundingBox2 = turf.polygon([
      [
        [-11545948.977350365, 4658759.839788924],
        [-11483057.72508946, 5032936.709591224],
        [-11857234.59489176, 5095827.961852129],
        [-11920125.847152665, 4721651.092049829]
      ]
    ]);

    const intersection = turf.intersect(boundingBox1, boundingBox2);

    console.log("intersection: ", intersection);
  };

Thanks for looking!

like image 239
Captain Caveman Avatar asked Sep 15 '25 00:09

Captain Caveman


1 Answers

this because the first and last point or positions must be same for each polygon. so the boundingBox1 & boundingBox2 will be :

checkForIntersection = () => {
    const boundingBox1 = turf.polygon([
      [
        [-11638128.151894445, 4697704.8042823635],
        [-11538591.465504704, 4932847.347657125],
        [-11773734.008879466, 5032384.034046866],
        [-11873270.695269207, 4797241.490672104],
        [-11638128.151894445, 4697704.8042823635],
      ]
    ]);

    const boundingBox2 = turf.polygon([
      [
        [-11545948.977350365, 4658759.839788924],
        [-11483057.72508946, 5032936.709591224],
        [-11857234.59489176, 5095827.961852129],
        [-11920125.847152665, 4721651.092049829],
        [-11545948.977350365, 4658759.839788924],
      ]
    ]);

    const intersection = turf.intersect(boundingBox1, boundingBox2);

    console.log("intersection: ", intersection);
  };
like image 155
MOHAMED Khaled Avatar answered Sep 16 '25 13:09

MOHAMED Khaled