How to use @turf/point-to-line-distance - 8 common examples

To help you get started, we’ve selected a few @turf/point-to-line-distance 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 / core / src / lib / utils.js View on Github external
export function generatePointsParallelToLinePoints(
  p1: Position,
  p2: Position,
  groundCoords: Position
): Position[] {
  const lineString: LineString = {
    type: 'LineString',
    coordinates: [p1, p2]
  };
  const pt = point(groundCoords);
  const ddistance = pointToLineDistance(pt, lineString);
  const lineBearing = bearing(p1, p2);

  // Check if current point is to the left or right of line
  // Line from A=(x1,y1) to B=(x2,y2) a point P=(x,y)
  // then (x−x1)(y2−y1)−(y−y1)(x2−x1)
  const isPointToLeftOfLine =
    (groundCoords[0] - p1[0]) * (p2[1] - p1[1]) - (groundCoords[1] - p1[1]) * (p2[0] - p1[0]);

  // Bearing to draw perpendicular to the line string
  const orthogonalBearing = isPointToLeftOfLine < 0 ? lineBearing - 90 : lineBearing - 270;

  // Get coordinates for the point p3 and p4 which are perpendicular to the lineString
  // Add the distance as the current position moves away from the lineString
  const p3 = destination(p2, ddistance, orthogonalBearing);
  const p4 = destination(p1, ddistance, orthogonalBearing);
github uber / nebula.gl / modules / core / src / lib / editable-feature-collection.js View on Github external
type: 'Feature',
        geometry: {
          type: 'LineString',
          coordinates: [this._clickSequence[0], groundCoords]
        }
      });
    } else if (this._clickSequence.length === 2) {
      const lineString: LineString = {
        type: 'LineString',
        coordinates: this._clickSequence
      };

      const [p1, p2] = this._clickSequence;
      const pt = point(groundCoords);
      const options = { units: 'miles' };
      const ddistance = pointToLineDistance(pt, lineString, options);
      const lineBearing = bearing(p1, p2);

      // Check if current point is to the left or right of line
      // Line from A=(x1,y1) to B=(x2,y2) a point P=(x,y)
      // then (x−x1)(y2−y1)−(y−y1)(x2−x1)
      const isPointToLeftOfLine =
        (groundCoords[0] - p1[0]) * (p2[1] - p1[1]) - (groundCoords[1] - p1[1]) * (p2[0] - p1[0]);

      // Bearing to draw perpendicular to the line string
      const orthogonalBearing = isPointToLeftOfLine < 0 ? lineBearing - 90 : lineBearing - 270;

      // Get coordinates for the point p3 and p4 which are perpendicular to the lineString
      // Add the distance as the current position moves away from the lineString
      const p3 = destination(p2, ddistance, orthogonalBearing, options);
      const p4 = destination(p1, ddistance, orthogonalBearing, options);
github conveyal / analysis-ui / lib / utils / get-existing-stops-along-pattern.js View on Github external
stops.forEach(stop => {
      // Ignore the source segment's start and end stops
      if (stop.stop_id !== segment.fromStopId && stop.stop_id !== segment.toStopId) {
        const stopPoint = turf.point([stop.stop_lon, stop.stop_lat])
        if (pointToLineDistance(stopPoint, line) <= STOP_SEARCH_BUFFER_KM) {
          const pointOnLine = nearestPointOnLine(line, stopPoint)
          // Ignore points too close to start or end stops
          if ((!segment.stopAtStart ||
            pointOnLine.properties.location > APPROX_MIN_SPACING_KM) &&
            (!segment.stopAtEnd ||
            segmentLengthKm - pointOnLine.properties.location > APPROX_MIN_SPACING_KM)
          ) {
            pointOnLine.properties.stopId = stop.stop_id
            pointOnLine.properties.stopCoords = [stop.stop_lon, stop.stop_lat]
            candidateStops.push(pointOnLine)
          }
        }
      }
    })
    // cluster stops that are close to each other
github uber / nebula.gl / modules / layers / src / utils.js View on Github external
export function generatePointsParallelToLinePoints(
  p1: Position,
  p2: Position,
  groundCoords: Position
): Position[] {
  const lineString: LineString = {
    type: 'LineString',
    coordinates: [p1, p2]
  };
  const pt = point(groundCoords);
  const ddistance = pointToLineDistance(pt, lineString);
  const lineBearing = bearing(p1, p2);

  // Check if current point is to the left or right of line
  // Line from A=(x1,y1) to B=(x2,y2) a point P=(x,y)
  // then (x−x1)(y2−y1)−(y−y1)(x2−x1)
  const isPointToLeftOfLine =
    (groundCoords[0] - p1[0]) * (p2[1] - p1[1]) - (groundCoords[1] - p1[1]) * (p2[0] - p1[0]);

  // Bearing to draw perpendicular to the line string
  const orthogonalBearing = isPointToLeftOfLine < 0 ? lineBearing - 90 : lineBearing - 270;

  // Get coordinates for the point p3 and p4 which are perpendicular to the lineString
  // Add the distance as the current position moves away from the lineString
  const p3 = destination(p2, ddistance, orthogonalBearing);
  const p4 = destination(p1, ddistance, orthogonalBearing);
github ngageoint / geopackage-js / test / lib / features / user / testFeatureDao.js View on Github external
if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'Polygon') {
          if (booleanPointInPolygon(centerPoint, geometry)) {
            if (closestDistance != 0) {
              closest = row;
              closestDistance = 0;
            }
          } else {
            var line = polygonToLine(geometry);
            var distance = pointToLineDistance(centerPoint, line);
            if (distance < closestDistance) {
              closest = row;
              closestDistance = distance;
            }
          }
        }
      }
      closest.values.name.should.be.equal('point');
      foundFeatures.should.be.deep.equal(['box1', 'box2', 'line', 'point']);
    });
github ngageoint / geopackage-js / test / lib / features / user / testFeatureDao.js View on Github external
for (var row of iterator) {
        foundFeatures.push(row);
        var geometry = row.geometry;

        if (geometry.type == 'Point') {
          var distance = pointDistance(centerPoint, geometry);
          if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'LineString') {
          var distance = pointToLineDistance(centerPoint, geometry);
          if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'Polygon') {
          if (booleanPointInPolygon(centerPoint, geometry)) {
            if (closestDistance != 0) {
              closest = row;
              closestDistance = 0;
            }
          } else {
            var line = polygonToLine(geometry);
            var distance = pointToLineDistance(centerPoint, line);
github ngageoint / geopackage-js / test / lib / features / user / testFeatureDao.js View on Github external
for (var row of iterator) {
        foundFeatures.push(row.values.name);
        var geometry = row.getGeometry().toGeoJSON();

        if (geometry.type == 'Point') {
          var distance = pointDistance(centerPoint, geometry);
          if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'LineString') {
          var distance = pointToLineDistance(centerPoint, geometry);
          if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'Polygon') {
          if (booleanPointInPolygon(centerPoint, geometry)) {
            if (closestDistance != 0) {
              closest = row;
              closestDistance = 0;
            }
          } else {
            var line = polygonToLine(geometry);
            var distance = pointToLineDistance(centerPoint, line);
github Turfjs / turf / packages / turf-nearest-point-to-line / index.ts View on Github external
featureEach(pts, (point) => {
        const d = pointToLineDistance(point, line, { units });
        if (d < dist) {
            dist = d;
            pt = point;
        }
    });
    /**

@turf/point-to-line-distance

turf point-to-line-distance module

MIT
Latest version published 3 months ago

Package Health Score

94 / 100
Full package analysis

Popular @turf/point-to-line-distance functions