question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New module @turf/line-intersect

See original GitHub issue

Proposing 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)

image

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:closed
  • Created 7 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
mournercommented, Mar 2, 2017

You’re on fire Denis, keep it up!

1reaction
DenisCarrierecommented, Sep 20, 2017

@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.

image

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found