turf
turf copied to clipboard
the result of turf.lineIntersect() don't match the exact point
Please provide the following when reporting an issue:
- [ turf 7 ] https://cdn.jsdelivr.net/npm/@turf/turf@7/turf.min.js https://geojson.io/
{
"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 ..
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
}