How to use the @turf/line-intersect function in @turf/line-intersect

To help you get started, we’ve selected a few @turf/line-intersect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uber / nebula.gl / modules / layers / src / mode-handlers / split-polygon-handler.js View on Github external
const clickSequence = this.getClickSequence();

    if (!selectedGeometry) {
      // eslint-disable-next-line no-console,no-undef
      console.warn('A polygon must be selected for splitting');
      this._setTentativeFeature(null);
      return editAction;
    }
    const pt = {
      type: 'Point',
      coordinates: clickSequence[clickSequence.length - 1]
    };
    const isPointInPolygon = booleanPointInPolygon(pt, selectedGeometry);
    if (clickSequence.length > 1 && tentativeFeature && !isPointInPolygon) {
      this.resetClickSequence();
      const isLineInterectingWithPolygon = lineIntersect(tentativeFeature, selectedGeometry);
      if (isLineInterectingWithPolygon.features.length === 0) {
        this._setTentativeFeature(null);
        return editAction;
      }
      return this.splitPolygon();
    }

    return editAction;
  }
github Turfjs / turf / packages / turf-nearest-point-on-line / index.ts View on Github external
for (var i = 0; i < coords.length - 1; i++) {
            //start
            var start = point(coords[i]);
            start.properties.dist = distance(pt, start, options);
            //stop
            var stop = point(coords[i + 1]);
            stop.properties.dist = distance(pt, stop, options);
            // sectionLength
            var sectionLength = distance(start, stop, options);
            //perpendicular
            var heightDistance = Math.max(start.properties.dist, stop.properties.dist);
            var direction = bearing(start, stop);
            var perpendicularPt1 = destination(pt, heightDistance, direction + 90, options);
            var perpendicularPt2 = destination(pt, heightDistance, direction - 90, options);
            var intersect = lineIntersects(
                lineString([perpendicularPt1.geometry.coordinates, perpendicularPt2.geometry.coordinates]),
                lineString([start.geometry.coordinates, stop.geometry.coordinates])
            );
            var intersectPt = null;
            if (intersect.features.length > 0) {
                intersectPt = intersect.features[0];
                intersectPt.properties.dist = distance(pt, intersectPt, options);
                intersectPt.properties.location = length + distance(start, intersectPt, options);
            }

            if (start.properties.dist < closestPt.properties.dist) {
                closestPt = start;
                closestPt.properties.index = i;
                closestPt.properties.location = length;
            }
            if (stop.properties.dist < closestPt.properties.dist) {
github Turfjs / turf / packages / turf-line-split / index.js View on Github external
if (splitterType === 'GeometryCollection') throw new Error('splitter cannot be a GeometryCollection');

    // remove excessive decimals from splitter
    // to avoid possible approximation issues in rbush
    var truncatedSplitter = truncate(splitter, {precision: 7});

    switch (splitterType) {
    case 'Point':
        return splitLineWithPoint(line, truncatedSplitter);
    case 'MultiPoint':
        return splitLineWithPoints(line, truncatedSplitter);
    case 'LineString':
    case 'MultiLineString':
    case 'Polygon':
    case 'MultiPolygon':
        return splitLineWithPoints(line, lineIntersect(line, truncatedSplitter));
    }
}
github Turfjs / turf / packages / turf-boolean-crosses / index.ts View on Github external
function doLineStringAndPolygonCross(lineString, polygon: Polygon) {
    const line: any = polygonToLine(polygon);
    const doLinesIntersect = lineIntersect(lineString, line);
    if (doLinesIntersect.features.length > 0) {
        return true;
    }
    return false;
}
github Turfjs / turf / packages / turf-boolean-disjoint / index.ts View on Github external
function isLineInPoly(polygon: Polygon, lineString: LineString) {
    for (const coord of lineString.coordinates) {
        if (booleanPointInPolygon(coord, polygon)) {
            return true;
        }
    }
    const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));
    if (doLinesIntersect.features.length > 0) {
        return true;
    }
    return false;
}
github infra-geo-ouverte / igo2-lib / packages / geo / src / lib / geometry / shared / geometry.utils.ts View on Github external
}

  if (olSlicer.getCoordinates().length > 2) {
    throw new GeometrySliceLineStringError();
  }

  const olGeoJSON = new OlGeoJSON();
  const slicer = olGeoJSON.writeGeometryObject(olSlicer);
  const outerCoordinates = olPolygon.getLinearRing(0).getCoordinates();

  const parts = [[], []];
  let totalIntersectionCount = 0;
  for (let i = 0, ii = outerCoordinates.length - 1; i < ii; i++) {
    const segmentCoordinates = [outerCoordinates[i], outerCoordinates[i + 1]];
    const segment = lineString(segmentCoordinates);
    const intersections = lineIntersect(segment, slicer).features;

    const intersectionCount = intersections.length;
    totalIntersectionCount += intersectionCount;
    if (intersectionCount > 1 || totalIntersectionCount > 2) {
      throw new GeometrySliceTooManyIntersectionError();
    }

    parts[0].push(segmentCoordinates[0]);
    if (intersectionCount === 1) {
      const intersection = intersections[0].geometry.coordinates;
      parts[0].push(intersection);
      parts[1].push(intersection);
      parts.reverse();
    }
  }
github Turfjs / turf / packages / turf-boolean-disjoint / index.ts View on Github external
function isLineOnLine(lineString1: LineString, lineString2: LineString) {
    const doLinesIntersect = lineIntersect(lineString1, lineString2);
    if (doLinesIntersect.features.length > 0) {
        return true;
    }
    return false;
}

@turf/line-intersect

turf line-intersect module

MIT
Latest version published 4 months ago

Package Health Score

97 / 100
Full package analysis

Popular @turf/line-intersect functions