New module @turf/line-intersect
See original GitHub issueProposing to create a new core module @turf/line-intersect
Description: Takes two GeoJSON LineStrings and returns the intersecting point(s).
Future use: Need to use this functionality in @turf/polygon-slice
.
Branch: line-intersect
Geometry Support
- LineString & MultiLineString & Polygon & MultiPolygon
- Geometry & Feature & FeatureCollection
Dependencies
- RBush (to quickly detect intersecting lines divided into pairs of 2 coordinates)
@turf/helpers
@turf/meta
(using coordReduce & featureEach)@turf/bbox-polygon
(debugging purposes)
Benchmark
double-intersect x 76,313 ops/sec ±0.86% (87 runs sampled)
feature-collection x 34,139 ops/sec ±1.80% (89 runs sampled)
multi-linestring x 23,185 ops/sec ±2.06% (84 runs sampled)
simple x 237,005 ops/sec ±1.41% (86 runs sampled)
JSDocs
/**
* Takes two GeoJSON LineStrings and returns the intersecting point(s).
*
* @name lineIntersect
* @param {Feature<LineString>} line1 GeoJSON LineString Feature
* @param {Feature<LineString>} line2 GeoJSON LineString Feature
* @returns {FeatureCollection<Point>} point(s) that intersect both lines
* @example
* var line1 = {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "LineString",
* "coordinates": [
* [126, -11],
* [129, -21]
* ]
* }
* };
* var line2 = {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "LineString",
* "coordinates": [
* [123, -18],
* [131, -14]
* ]
* }
* };
* var points = turf.lineIntersect(line1, line2);
* //= points
*/
export default function (line1, line2) {
Issue Analytics
- State:
- Created 7 years ago
- Comments:15 (8 by maintainers)
Top Results From Across the Web
@turf/line-intersect - npm
turf line-intersect module. Latest version: 6.5.0, last published: a year ago. Start using @turf/line-intersect in your project by running ...
Read more >@turf/line-intersect | Yarn - Package Manager
@turf/boolean-within. Boolean-within returns true if the first geometry is completely within the second geometry. The interiors of both geometries must ...
Read more >Advanced geospatial analysis - Turf.js
Divides a LineString into chunks of a specified length. If the line is shorter than the segment length then the original line is...
Read more >Detecting line intersections between MultiPolygon and ...
To do this I am using the lineIntersect method in Turf.js which should allow me to pass a LineString and MultiPolygon .
Read more >How to use the @turf/union function in @turf/union - Snyk
booleanOperation === 'intersection') { updatedGeometry = turfIntersect(selectedFeature, feature); } else { // eslint-disable-next-line no-console,no-undef ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You’re on fire Denis, keep it up!
@shawnmgoulet Thanks for pointing this out, ~I believe we decided to drop the Polygon support since it would create a bit of confusion on how the Polygons are being handle.~
~Easy solution that you can do right now is use the
@turf/polygon-to-linestring
module which will do exactly what the name of the module will do.~~Note: Handling Multi-Polygons with holes will return a FeatureCollection of MultiLineStrings.~
Edit:
@turf/line-intersect
does work with Polygons & Multi-Polygons.