{"name":"@turf/clusters","version":"7.2.0","keywords":["turf","geojson","cluster","clusters","clustering"],"author":"Turf Authors","license":"MIT","_id":"@turf/clusters@7.2.0","maintainers":[{"name":"rowanwins","email":"rowanwins@yahoo.com.au"},{"name":"tmcw","email":"tom@macwright.com"},{"name":"morganherlocker","email":"morgan.herlocker@gmail.com"},{"name":"tcql","email":"tim.channell@gmail.com"},{"name":"mdfedderly","email":"mdfedderly@mdfedderly.com"},{"name":"twelch","email":"tim.j.welch@gmail.com"},{"name":"jamesmilneruk","email":"jamesmilner22@hotmail.com"},{"name":"morgan.herlocker","email":"morganherlocker@gmail.com"},{"name":"smallsaucepan","email":"james@smallsaucepan.com"}],"contributors":["Denis Carriere <@DenisCarriere>"],"homepage":"https://github.com/Turfjs/turf","bugs":{"url":"https://github.com/Turfjs/turf/issues"},"dist":{"shasum":"9302a02e76080d6650509f5fab262ca494a9a8d2","tarball":"http://registry-npm.ywwl.com/@turf/clusters/download/@turf/clusters-7.2.0.tgz","fileCount":9,"integrity":"sha512-sKOrIKHHtXAuTKNm2USnEct+6/MrgyzMW42deZ2YG2RRKWGaaxHMFU2Yw71Yk4DqStOqTIBQpIOdrRuSOwbuQw==","signatures":[{"sig":"MEYCIQCjD0eKBvFAoXZYooKlNE/R4dIqeuRTddrROPe7VeAkugIhALquvmLl1BX8tEOjJnFxvp2850G1zqCd8oO6PBQDu1jq","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":61821,"size":9560,"noattachment":false,"key":"/@turf/clusters/-/@turf/clusters-7.2.0.tgz"},"main":"dist/cjs/index.cjs","type":"module","types":"dist/esm/index.d.ts","module":"dist/esm/index.js","exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/cjs/index.d.cts","default":"./dist/cjs/index.cjs"}},"./package.json":"./package.json"},"funding":"https://opencollective.com/turf","gitHead":"7b0f0374c4668cd569f8904c71e2ae7d941be867","scripts":{"docs":"tsx ../../scripts/generate-readmes.ts","test":"npm-run-all --npm-path npm test:*","bench":"tsx bench.ts","build":"tsup --config ../../tsup.config.ts","test:tape":"tsx test.ts","test:types":"tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"},"_npmUser":{"name":"mdfedderly","email":"mdfedderly@mdfedderly.com"},"repository":{"url":"git://github.com/Turfjs/turf.git","type":"git"},"_npmVersion":"lerna/8.1.9/node@v18.20.5+x64 (linux)","description":"turf clusters module","directories":{},"sideEffects":false,"_nodeVersion":"18.20.5","dependencies":{"tslib":"^2.8.1","@turf/meta":"^7.2.0","@turf/helpers":"^7.2.0","@types/geojson":"^7946.0.10"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tape":"^5.9.0","tsup":"^8.3.5","benchmark":"^2.1.4","typescript":"^5.5.4","@types/tape":"^4.13.4","npm-run-all":"^4.1.5","@types/benchmark":"^2.1.5"},"_npmOperationalInternal":{"tmp":"tmp/clusters_7.2.0_1735448332665_0.9493668462663927","host":"s3://npm-registry-packages-npm-production"},"readme":"# @turf/clusters\n\n<!-- Generated by documentation.js. Update this documentation by updating the source code. -->\n\n## getCluster\n\nGet Cluster\n\n### Parameters\n\n*   `geojson` **[FeatureCollection][1]** GeoJSON Features\n*   `filter` **any** Filter used on GeoJSON properties to get Cluster\n\n### Examples\n\n```javascript\nvar geojson = turf.featureCollection([\n    turf.point([0, 0], {'marker-symbol': 'circle'}),\n    turf.point([2, 4], {'marker-symbol': 'star'}),\n    turf.point([3, 6], {'marker-symbol': 'star'}),\n    turf.point([5, 1], {'marker-symbol': 'square'}),\n    turf.point([4, 2], {'marker-symbol': 'circle'})\n]);\n\n// Create a cluster using K-Means (adds `cluster` to GeoJSON properties)\nvar clustered = turf.clustersKmeans(geojson);\n\n// Retrieve first cluster (0)\nvar cluster = turf.getCluster(clustered, {cluster: 0});\n//= cluster\n\n// Retrieve cluster based on custom properties\nturf.getCluster(clustered, {'marker-symbol': 'circle'}).length;\n//= 2\nturf.getCluster(clustered, {'marker-symbol': 'square'}).length;\n//= 1\n```\n\nReturns **[FeatureCollection][1]** Single Cluster filtered by GeoJSON Properties\n\n## clusterEachCallback\n\nCallback for clusterEach\n\nType: [Function][2]\n\n### Parameters\n\n*   `cluster` **[FeatureCollection][1]?** The current cluster being processed.\n*   `clusterValue` **any?** Value used to create cluster being processed.\n*   `currentIndex` **[number][3]?** The index of the current element being processed in the array.Starts at index 0\n\nReturns **void**&#x20;\n\n## clusterEach\n\nclusterEach\n\n### Parameters\n\n*   `geojson` **[FeatureCollection][1]** GeoJSON Features\n*   `property` **([string][4] | [number][3])** GeoJSON property key/value used to create clusters\n*   `callback` **[clusterEachCallback][5]** a method that takes (cluster, clusterValue, currentIndex)\n\n### Examples\n\n```javascript\nvar geojson = turf.featureCollection([\n    turf.point([0, 0]),\n    turf.point([2, 4]),\n    turf.point([3, 6]),\n    turf.point([5, 1]),\n    turf.point([4, 2])\n]);\n\n// Create a cluster using K-Means (adds `cluster` to GeoJSON properties)\nvar clustered = turf.clustersKmeans(geojson);\n\n// Iterate over each cluster\nturf.clusterEach(clustered, 'cluster', function (cluster, clusterValue, currentIndex) {\n    //= cluster\n    //= clusterValue\n    //= currentIndex\n})\n\n// Calculate the total number of clusters\nvar total = 0\nturf.clusterEach(clustered, 'cluster', function () {\n    total++;\n});\n\n// Create an Array of all the values retrieved from the 'cluster' property\nvar values = []\nturf.clusterEach(clustered, 'cluster', function (cluster, clusterValue) {\n    values.push(clusterValue);\n});\n```\n\nReturns **void**&#x20;\n\n## clusterReduceCallback\n\nCallback for clusterReduce\n\nThe first time the callback function is called, the values provided as arguments depend\non whether the reduce method has an initialValue argument.\n\nIf an initialValue is provided to the reduce method:\n\n*   The previousValue argument is initialValue.\n*   The currentValue argument is the value of the first element present in the array.\n\nIf an initialValue is not provided:\n\n*   The previousValue argument is the value of the first element present in the array.\n*   The currentValue argument is the value of the second element present in the array.\n\nType: [Function][2]\n\n### Parameters\n\n*   `previousValue` **any?** The accumulated value previously returned in the last invocation\n    of the callback, or initialValue, if supplied.\n*   `cluster` **[FeatureCollection][1]?** The current cluster being processed.\n*   `clusterValue` **any?** Value used to create cluster being processed.\n*   `currentIndex` **[number][3]?** The index of the current element being processed in the\n    array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.\n\nReturns **void**&#x20;\n\n## clusterReduce\n\nReduce clusters in GeoJSON Features, similar to Array.reduce()\n\n### Parameters\n\n*   `geojson` **[FeatureCollection][1]** GeoJSON Features\n*   `property` **([string][4] | [number][3])** GeoJSON property key/value used to create clusters\n*   `callback` **[clusterReduceCallback][6]** a method that takes (previousValue, cluster, clusterValue, currentIndex)\n*   `initialValue` **any?** Value to use as the first argument to the first call of the callback.\n\n### Examples\n\n```javascript\nvar geojson = turf.featureCollection([\n    turf.point([0, 0]),\n    turf.point([2, 4]),\n    turf.point([3, 6]),\n    turf.point([5, 1]),\n    turf.point([4, 2])\n]);\n\n// Create a cluster using K-Means (adds `cluster` to GeoJSON properties)\nvar clustered = turf.clustersKmeans(geojson);\n\n// Iterate over each cluster and perform a calculation\nvar initialValue = 0\nturf.clusterReduce(clustered, 'cluster', function (previousValue, cluster, clusterValue, currentIndex) {\n    //=previousValue\n    //=cluster\n    //=clusterValue\n    //=currentIndex\n    return previousValue++;\n}, initialValue);\n\n// Calculate the total number of clusters\nvar total = turf.clusterReduce(clustered, 'cluster', function (previousValue) {\n    return previousValue++;\n}, 0);\n\n// Create an Array of all the values retrieved from the 'cluster' property\nvar values = turf.clusterReduce(clustered, 'cluster', function (previousValue, cluster, clusterValue) {\n    return previousValue.concat(clusterValue);\n}, []);\n```\n\nReturns **any** The value that results from the reduction.\n\n[1]: https://tools.ietf.org/html/rfc7946#section-3.3\n\n[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function\n\n[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number\n\n[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String\n\n[5]: #clustereachcallback\n\n[6]: #clusterreducecallback\n\n<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run \"yarn docs\" from the root of the turf project. -->\n\n---\n\nThis module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.\n\n### Installation\n\nInstall this single module individually:\n\n```sh\n$ npm install @turf/clusters\n```\n\nOr install the all-encompassing @turf/turf module that includes all modules as functions:\n\n```sh\n$ npm install @turf/turf\n```\n","publish_time":1735448332861,"_cnpm_publish_time":1735448332861,"dist-tags":{"latest":"7.4.0","prerelease":"7.1.0-alpha.70"}}