3

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!

Captain Caveman
  • 1,448
  • 1
  • 11
  • 24

1 Answers1

2

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