How to use @turf/clusters-dbscan - 1 common examples

To help you get started, we’ve selected a few @turf/clusters-dbscan 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 conveyal / analysis-ui / lib / utils / get-existing-stops-along-pattern.js View on Github external
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
    const clusteredStops = clustersDbscan(turf.featureCollection(candidateStops), APPROX_MIN_SPACING_KM, {minPoints: 1})

    // in each cluster, find the stop that is closest to the segment
    const closestStopPerCluster = []
    clusteredStops.features.forEach(stop => {
      const cluster = stop.properties.cluster
      if (!closestStopPerCluster[cluster] ||
          stop.properties.dist < closestStopPerCluster[cluster].properties.distance) {
        closestStopPerCluster[cluster] = stop
      }
    })

    // modify the segment if there are stops to add

    if (closestStopPerCluster.length > 0) {
      closestStopPerCluster.sort((a, b) => a.properties.location - b.properties.location)
      const last = closestStopPerCluster.length - 1

@turf/clusters-dbscan

turf clusters-dbscan module

MIT
Latest version published 4 months ago

Package Health Score

94 / 100
Full package analysis

Popular @turf/clusters-dbscan functions