You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically, I have two neighboring polygons. I use Turf to create a LineString running from the centroid of one to the centroid of the other. What I want to do now is use lineIntersects() to find the point where this LineString intersects the boundary of one of the polygons.
My code looks roughly like this:
// Calculate the distance beteween centroid of highlighted polygon and the centroid of the neighboring polygon.consthighlight_centroid=turf.centerOfMass(highlight_feature);constcentroid=turf.centerOfMass(neighbor_feature);constline=turf.lineString([highlight_centroid,centroid]);// Find the intersection of this line with the boundary of neighbor_feature// First, check if it intersects. Turf says TRUE, the line DOES intersect neighbor_featureconsole.log(turf.booleanIntersects(line,neighbor_feature));// But lineIntersect() returns an empty feature collection.// There should be a point coordinateconstintersection=turf.lineIntersect(line,neighbor_feature);console.log(intersection);
Turf's booleanIntersects() method returns TRUE -- because the line and polygon do intersect.
But when I try to use lineIntersect() to obtain the intersection point, Turf just returns an empty feature collection. And it does the same if I try other similar methods like lineOverlap() or lineSplit().
Am I doing something wrong, or is there an issue with these line-related methods?
The text was updated successfully, but these errors were encountered:
booleanIntersects will find out if there is shared geometry between two geometries.
So if you have a Polygon and a LineString, booleanIntersects will also return true if the LineString is completely contained by the Polygon, meaning that the LineString does not intersect with any of the edges of the Polygon.
lineIntersect will only find intersections between lines (edges of the Polygon and the LineString).
This may be a reason why no Points are returned.
booleanCrosses might be useful to you in this case (not exactly sure what it does), or a combination of booleanIntersect and booleanWithin
Yes, finding an intersection between a lineString and the edge of a polygon is exactly what I'm trying to do with lineIntersect(). (please see my codepen example) It should work.
I'm having trouble with running
lineIntersects()
on a line and a polygon.I'm using TurfJS 6, via https://cdn.jsdelivr.net/npm/@turf/turf@6/turf.min.js. I'm mapping the results in Leaflet 1.7.1.
A working example of my issue (including sample GeoJSON data) can be found here:
https://codepen.io/Kirkman/pen/JjOxjwP
Basically, I have two neighboring polygons. I use Turf to create a LineString running from the centroid of one to the centroid of the other. What I want to do now is use
lineIntersects()
to find the point where this LineString intersects the boundary of one of the polygons.My code looks roughly like this:
Turf's booleanIntersects() method returns TRUE -- because the line and polygon do intersect.
But when I try to use lineIntersect() to obtain the intersection point, Turf just returns an empty feature collection. And it does the same if I try other similar methods like lineOverlap() or lineSplit().
Am I doing something wrong, or is there an issue with these line-related methods?
The text was updated successfully, but these errors were encountered: