How to use @turf/line-distance - 4 common examples

To help you get started, we’ve selected a few @turf/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 Turfjs / turf / packages / turf-line-chunk / index.js View on Github external
function sliceLineSegments(line, segmentLength, units, callback) {
    var lineLength = lineDistance(line, {units: units});

    // If the line is shorter than the segment length then the orginal line is returned.
    if (lineLength <= segmentLength) return callback(line);

    var numberOfSegments = lineLength / segmentLength;

    // If numberOfSegments is integer, no need to plus 1
    if (!Number.isInteger(numberOfSegments)) {
        numberOfSegments = Math.floor(numberOfSegments) + 1;
    }

    for (var i = 0; i < numberOfSegments; i++) {
        var outline = lineSliceAlong(line, segmentLength * i, segmentLength * (i + 1), {units: units});
        callback(outline, i);
    }
}
github conveyal / analysis-ui / lib / utils / get-existing-stops-along-pattern.js View on Github external
segments.forEach(segment => {
    const line = turf.lineString(segment.geometry.coordinates)
    const segmentLengthKm = lineDistance(line)
    const candidateStops = []
    // iterate through stops, calculating distance from nearby stops to segment
    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]
github conveyal / analysis-ui / lib / components / report / adjust-frequency.js View on Github external
} = entry
    if (sourceTrip == null) return [] // TODO this should not happen but can when a modification is brand-spankin'-new

    const {
      modification,
      feedsById,
      projectTimetables,
      feedScopedStops
    } = this.props
    const feed = feedsById[modification.feed]
    const route = feed.routes.find(r => r.route_id === modification.routes[0])
    const pattern = route.patterns.find(
      p => p.trips.findIndex(t => t.trip_id === sourceTrip) > -1
    )
    const trip = pattern.trips.find(t => t.trip_id === sourceTrip)
    const km = lineDistance(pattern.geometry, 'kilometers')

    // TODO may be off by one, for instance ten-minute service for an hour will usually be 5 trips not 6
    const nTrips = Math.floor((endTime - startTime) / headwaySecs)

    // hide bottom border if we will display phasing info.
    const style = phaseAtStop ? {borderBottom: 0} : {}

    const out = [
      
        
          {name}
        
        
          {trip.direction_id}
github FreemapSlovakia / freemap-v3-react / src / logic / trackViewerLogic.js View on Github external
trackGeojson.features.forEach((feature) => {
      if (feature.geometry.type === 'LineString') {
        const lengthInKm = turfLineDistance(feature);
        const coords = feature.geometry.coordinates;
        const startLonlat = coords[0];
        let startTime;
        let finishTime;
        const times = feature.properties.coordTimes;
        if (times) {
          [startTime] = times;
          finishTime = times[times.length - 1];
        }
        startPoints.push({ lat: startLonlat[1], lon: startLonlat[0], startTime });

        const finishLonLat = coords[coords.length - 1];
        finishPoints.push({
          lat: finishLonLat[1], lon: finishLonLat[0], lengthInKm, finishTime,
        });
      }

@turf/line-distance

turf line-distance module

MIT
Latest version published 7 years ago

Package Health Score

62 / 100
Full package analysis

Popular @turf/line-distance functions