What is @turf/line-intersect?
@turf/line-intersect is a module from the Turf.js library that provides geospatial analysis tools. This specific module is used to find the intersection points between two or more lines. It is useful in various geospatial applications, such as mapping, urban planning, and geographic information systems (GIS).
What are @turf/line-intersect's main functionalities?
Find Intersection Points
This feature allows you to find the intersection points between two lines. In the code sample, two lines are defined, and the `lineIntersect` function is used to find their intersection points.
const turf = require('@turf/turf');
const line1 = turf.lineString([[0, 0], [2, 2]]);
const line2 = turf.lineString([[0, 2], [2, 0]]);
const intersections = turf.lineIntersect(line1, line2);
console.log(intersections);
Other packages similar to @turf/line-intersect
jsts
JSTS is a JavaScript library of spatial predicates and functions for processing geometry. It is a port of the Java Topology Suite (JTS). JSTS provides more comprehensive geometry processing capabilities compared to @turf/line-intersect, including operations like buffering, union, and difference.
martinez-polygon-clipping
Martinez Polygon Clipping is a library for performing boolean operations on polygons, such as intersection, union, and difference. While it focuses on polygon operations, it can also be used to find intersections between line segments within polygons, offering more specialized functionality compared to @turf/line-intersect.
@turf/line-intersect
lineIntersect
Takes any LineString or Polygon GeoJSON and returns the intersecting point(s).
Parameters
-
line1
GeoJSON any LineString or Polygon
-
line2
GeoJSON any LineString or Polygon
-
options
Object Optional parameters (optional, default {}
)
options.removeDuplicates
boolean remove duplicate intersections (optional, default true
)options.ignoreSelfIntersections
boolean ignores self-intersections on input features (optional, default false
)
Examples
var line1 = turf.lineString([[126, -11], [129, -21]]);
var line2 = turf.lineString([[123, -18], [131, -14]]);
var intersects = turf.lineIntersect(line1, line2);
var addToMap = [line1, line2, intersects]
Returns FeatureCollection<Point> point(s) that intersect both
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Installation
Install this single module individually:
$ npm install @turf/line-intersect
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf