Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the result of turf.lineIntersect() don't match the exact point #2660

Open
HNQX opened this issue Jul 22, 2024 · 0 comments
Open

the result of turf.lineIntersect() don't match the exact point #2660

HNQX opened this issue Jul 22, 2024 · 0 comments

Comments

@HNQX
Copy link

HNQX commented Jul 22, 2024

Please provide the following when reporting an issue:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "coordinates": [
          [
            120.179402,
            31.247428
          ],
          [
            120.700497,
            31.365937
          ]
        ],
        "type": "LineString"
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "coordinates": [
          [
            120.445638,
            31.381745,
            0
          ],
          [
            121.033588,
            31.055778,
            0
          ],
          [
            121.094159,
            31.046175,
            0
          ],
          [
            121.167627,
            31.042088,
            0
          ]
        ],
        "type": "LineString"
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "coordinates": [
          120.539991319355,31.32943431295146
        ],
        "type": "Point"
      }
    }
  ]
}

I use turf.lineIntersect method to get the intersection of the two line,
i got result is

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[120.539991319355,31.32943431295146]}}]}

the result seems not match in geojson.io ..

3

        const line1 = [
            [120.179402, 31.247428, 0],
            [120.700497, 31.365937, 0]
        ]

        const line2 = [
            [120.445638, 31.381745, 0],
            [121.033588, 31.055778, 0],
            [121.094159, 31.046175, 0],
            [121.167627, 31.042088, 0]
        ]

        const point = intesection(line1, line2)

        console.log(JSON.stringify(point));
        function intesection(lineString1, lineString2) {

            const line1 = turf.lineString(lineString1)
            const line2 = turf.lineString(lineString2)

            var intersects = turf.lineIntersect(line1, line2);

            return intersects
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants