How to use @turf/nearest-point-on-line - 10 common examples

To help you get started, we’ve selected a few @turf/nearest-point-on-line 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 Turfjs / turf / packages / turf-line-overlap / index.ts View on Github external
// Overlaps already exists - only append last coordinate of segment
                    if (overlapSegment) overlapSegment = concatSegment(overlapSegment, segment);
                    else overlapSegment = segment;
                // Match segments which don't share nodes (Issue #901)
                } else if (
                    (tolerance === 0) ?
                        booleanPointOnLine(coordsSegment[0], match) && booleanPointOnLine(coordsSegment[1], match) :
                        nearestPointOnLine(match, coordsSegment[0]).properties.dist <= tolerance &&
                        nearestPointOnLine(match, coordsSegment[1]).properties.dist <= tolerance) {
                    doesOverlaps = true;
                    if (overlapSegment) overlapSegment = concatSegment(overlapSegment, segment);
                    else overlapSegment = segment;
                } else if (
                    (tolerance === 0) ?
                        booleanPointOnLine(coordsMatch[0], segment) && booleanPointOnLine(coordsMatch[1], segment) :
                        nearestPointOnLine(segment, coordsMatch[0]).properties.dist <= tolerance &&
                        nearestPointOnLine(segment, coordsMatch[1]).properties.dist <= tolerance) {
                    // Do not define (doesOverlap = true) since more matches can occur within the same segment
                    // doesOverlaps = true;
                    if (overlapSegment) overlapSegment = concatSegment(overlapSegment, match);
                    else overlapSegment = match;
                }
            }
        });
github ibi-group / datatools-ui / lib / editor / util / map.js View on Github external
export function projectStopOntoLine (stop: GtfsStop, line: GeoJsonLinestring): {
  distanceInMeters: number,
  insertIndex: number,
  insertPoint: GeoJsonPoint
} {
  const stopPoint = stopToPoint(stop)
  // Find nearest point on line
  const insertPoint = nearestPointOnLine(line, stopPoint)
  // Determine insert index based on nearest point operation segment index.
  // FIXME is this the right spot to insert
  const insertIndex = insertPoint.properties.index
  // Determine distance traveled to stop/shape point
  // Distance returned from nearestPointOnLine defaults to km.
  const distanceInMeters = insertPoint.properties.location * 1000
  return {insertPoint, insertIndex, distanceInMeters}
}
github uber / nebula.gl / modules / layers / src / mode-handlers / split-polygon-handler.js View on Github external
const currentDistance = turfDistance(firstPoint, groundCoords, { units: 'meters' });
        return turfDestination(firstPoint, currentDistance, lastBearing, {
          units: 'meters'
        }).geometry.coordinates;
      }
      return groundCoords;
    }
    // Allow only 90 degree turns
    const lastPoint = clickSequence[clickSequence.length - 1];
    const [approximatePoint] = generatePointsParallelToLinePoints(
      clickSequence[clickSequence.length - 2],
      lastPoint,
      groundCoords
    );
    // align point with current ground
    const nearestPt = nearestPointOnLine(lineString([lastPoint, approximatePoint]), groundCoords)
      .geometry.coordinates;
    return nearestPt;
  }
github Turfjs / turf / packages / turf-line-split / index.js View on Github external
featureEach(lines, function (segment) {
        var pt = nearestPointOnLine(segment, point);
        var dist = pt.properties.dist;
        if (dist < closestDistance) {
            closestFeature = segment;
            closestDistance = dist;
        }
    });
    return closestFeature;
github uber / nebula.gl / modules / layers / src / mode-handlers / split-polygon-handler.js View on Github external
lines.forEach(line => {
        const snapPoint = nearestPointOnLine(line, firstPoint);
        const distanceFromOrigin = turfDistance(snapPoint, firstPoint);
        if (minDistance > distanceFromOrigin) {
          minDistance = distanceFromOrigin;
          closestPoint = snapPoint;
        }
      });
github Turfjs / turf / packages / turf-line-slice / index.js View on Github external
function lineSlice(startPt, stopPt, line) {
    var coords;
    if (line.type === 'Feature') {
        coords = line.geometry.coordinates;
    } else if (line.type === 'LineString') {
        coords = line.coordinates;
    } else {
        throw new Error('input must be a LineString Feature or Geometry');
    }

    var startVertex = nearestPointOnLine(line, startPt);
    var stopVertex = nearestPointOnLine(line, stopPt);
    var ends;
    if (startVertex.properties.index <= stopVertex.properties.index) {
        ends = [startVertex, stopVertex];
    } else {
        ends = [stopVertex, startVertex];
    }
    var clipCoords = [ends[0].geometry.coordinates];
    for (var i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
        clipCoords.push(coords[i]);
    }
    clipCoords.push(ends[1].geometry.coordinates);
    return linestring(clipCoords, line.properties);
}
github Turfjs / turf / packages / turf-line-slice / index.js View on Github external
function lineSlice(startPt, stopPt, line) {
    var coords;
    if (line.type === 'Feature') {
        coords = line.geometry.coordinates;
    } else if (line.type === 'LineString') {
        coords = line.coordinates;
    } else {
        throw new Error('input must be a LineString Feature or Geometry');
    }

    var startVertex = nearestPointOnLine(line, startPt);
    var stopVertex = nearestPointOnLine(line, stopPt);
    var ends;
    if (startVertex.properties.index <= stopVertex.properties.index) {
        ends = [startVertex, stopVertex];
    } else {
        ends = [stopVertex, startVertex];
    }
    var clipCoords = [ends[0].geometry.coordinates];
    for (var i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
        clipCoords.push(coords[i]);
    }
    clipCoords.push(ends[1].geometry.coordinates);
    return linestring(clipCoords, line.properties);
}
github uber / nebula.gl / modules / core / src / lib / editable-feature-collection.js View on Github external
(lineString, prefix) => {
            const lineStringFeature = toLineString(lineString);
            const candidateIntermediatePoint = nearestPointOnLine(
              lineStringFeature,
              referencePoint
            );
            if (
              !intermediatePoint ||
              candidateIntermediatePoint.properties.dist < intermediatePoint.properties.dist
            ) {
              intermediatePoint = candidateIntermediatePoint;
              positionIndexPrefix = prefix;
            }
          }
        );
github PieceMaker / max-inscribed-circle / max-inscribed-circle.js View on Github external
//define borders of polygon and holes as LineStrings
    for(let j = 0; j < polygon.geometry.coordinates.length; j++) {
        polygonBoundaries.features.push({
            type: "Feature",
            properties: {},
            geometry: {
                type: "LineString",
                coordinates: polygon.geometry.coordinates[j]
            }
        })
    }

    for(let k = 0; k < ptsWithin.features.length; k++) {
        for(let l = 0; l < polygonBoundaries.features.length; l++) {
            if(l === 0) {
                vertexDistance = nearestPointOnLine(polygonBoundaries.features[l], ptsWithin.features[k], {units: units}).properties.dist;
            } else {
                vertexDistance = Math.min(vertexDistance,
                    nearestPointOnLine(polygonBoundaries.features[l], ptsWithin.features[k], {units: units}).properties.dist);
            }
        }
        if(vertexDistance > labelLocation.maxDist) {
            labelLocation.coordinates = ptsWithin.features[k].geometry.coordinates;
            labelLocation.maxDist = vertexDistance;
        }
    }

    return point(labelLocation.coordinates, {radius: labelLocation.maxDist, units: units});
};

@turf/nearest-point-on-line

turf nearest-point-on-line module

MIT
Latest version published 3 years ago

Package Health Score

78 / 100
Full package analysis

Popular @turf/nearest-point-on-line functions

Similar packages