@turf/clusters-kmeans 7.1.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +2 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +15 -15
package/dist/cjs/index.cjs
CHANGED
|
@@ -5,10 +5,8 @@ var _skmeans = require('skmeans'); var _skmeans2 = _interopRequireDefault(_skmea
|
|
|
5
5
|
function clustersKmeans(points, options = {}) {
|
|
6
6
|
var count = points.features.length;
|
|
7
7
|
options.numberOfClusters = options.numberOfClusters || Math.round(Math.sqrt(count / 2));
|
|
8
|
-
if (options.numberOfClusters > count)
|
|
9
|
-
|
|
10
|
-
if (options.mutate !== true)
|
|
11
|
-
points = _clone.clone.call(void 0, points);
|
|
8
|
+
if (options.numberOfClusters > count) options.numberOfClusters = count;
|
|
9
|
+
if (options.mutate !== true) points = _clone.clone.call(void 0, points);
|
|
12
10
|
var data = _meta.coordAll.call(void 0, points);
|
|
13
11
|
var initialCentroids = data.slice(0, options.numberOfClusters);
|
|
14
12
|
var skmeansResult = _skmeans2.default.call(void 0, data, options.numberOfClusters, initialCentroids);
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-clusters-kmeans/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACCA,oCAAsB;AACtB,kCAAsC;AACtC,oFAAoB;AA4BpB,SAAS,cAAA,CACP,MAAA,EACA,QAAA,EAGI,CAAC,CAAA,EACkC;AAEvC,EAAA,IAAI,MAAA,EAAQ,MAAA,CAAO,QAAA,CAAS,MAAA;AAC5B,EAAA,OAAA,CAAQ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"geojson\";\nimport { clone } from \"@turf/clone\";\nimport { coordAll, featureEach } from \"@turf/meta\";\nimport skmeans from \"skmeans\";\n\ntype KmeansProps = GeoJsonProperties & {\n cluster?: number;\n centroid?: [number, number];\n};\n\n/**\n * Takes a set of {@link Point|points} and partition them into clusters using the k-mean .\n * It uses the [k-means algorithm](https://en.wikipedia.org/wiki/K-means_clustering)\n *\n * @function\n * @param {FeatureCollection<Point>} points to be clustered\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.numberOfClusters=Math.sqrt(numberOfPoints/2)] numberOfClusters that will be generated\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {FeatureCollection<Point>} Clustered Points with an additional two properties associated to each Feature:\n * - {number} cluster - the associated clusterId\n * - {[number, number]} centroid - Centroid of the cluster [Longitude, Latitude]\n * @example\n * // create random points with random z-values in their properties\n * var points = turf.randomPoint(100, {bbox: [0, 30, 20, 50]});\n * var options = {numberOfClusters: 7};\n * var clustered = turf.clustersKmeans(points, options);\n *\n * //addToMap\n * var addToMap = [clustered];\n */\nfunction clustersKmeans(\n points: FeatureCollection<Point>,\n options: {\n numberOfClusters?: number;\n mutate?: boolean;\n } = {}\n): FeatureCollection<Point, KmeansProps> {\n // Default Params\n var count = points.features.length;\n options.numberOfClusters =\n options.numberOfClusters || Math.round(Math.sqrt(count / 2));\n\n // numberOfClusters can't be greater than the number of points\n // fallbacks to count\n if (options.numberOfClusters > count) options.numberOfClusters = count;\n\n // Clone points to prevent any mutations (enabled by default)\n if (options.mutate !== true) points = clone(points);\n\n // collect points coordinates\n var data = coordAll(points);\n\n // create seed to avoid skmeans to drift\n var initialCentroids = data.slice(0, options.numberOfClusters);\n\n // create skmeans clusters\n var skmeansResult = skmeans(data, options.numberOfClusters, initialCentroids);\n\n // store centroids {clusterId: [number, number]}\n var centroids: Record<string, number[]> = {};\n (skmeansResult.centroids as number[][]).forEach(function (\n coord: number[],\n idx: number\n ) {\n centroids[idx] = coord;\n });\n\n // add associated cluster number\n featureEach(points, function (point, index) {\n var clusterId = skmeansResult.idxs[index];\n point.properties!.cluster = clusterId;\n point.properties!.centroid = centroids[clusterId];\n });\n\n return points as FeatureCollection<Point, KmeansProps>;\n}\n\nexport { clustersKmeans, KmeansProps };\nexport default clustersKmeans;\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -8,7 +8,7 @@ type KmeansProps = GeoJsonProperties & {
|
|
|
8
8
|
* Takes a set of {@link Point|points} and partition them into clusters using the k-mean .
|
|
9
9
|
* It uses the [k-means algorithm](https://en.wikipedia.org/wiki/K-means_clustering)
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @function
|
|
12
12
|
* @param {FeatureCollection<Point>} points to be clustered
|
|
13
13
|
* @param {Object} [options={}] Optional parameters
|
|
14
14
|
* @param {number} [options.numberOfClusters=Math.sqrt(numberOfPoints/2)] numberOfClusters that will be generated
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ type KmeansProps = GeoJsonProperties & {
|
|
|
8
8
|
* Takes a set of {@link Point|points} and partition them into clusters using the k-mean .
|
|
9
9
|
* It uses the [k-means algorithm](https://en.wikipedia.org/wiki/K-means_clustering)
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @function
|
|
12
12
|
* @param {FeatureCollection<Point>} points to be clustered
|
|
13
13
|
* @param {Object} [options={}] Optional parameters
|
|
14
14
|
* @param {number} [options.numberOfClusters=Math.sqrt(numberOfPoints/2)] numberOfClusters that will be generated
|
package/dist/esm/index.js
CHANGED
|
@@ -5,10 +5,8 @@ import skmeans from "skmeans";
|
|
|
5
5
|
function clustersKmeans(points, options = {}) {
|
|
6
6
|
var count = points.features.length;
|
|
7
7
|
options.numberOfClusters = options.numberOfClusters || Math.round(Math.sqrt(count / 2));
|
|
8
|
-
if (options.numberOfClusters > count)
|
|
9
|
-
|
|
10
|
-
if (options.mutate !== true)
|
|
11
|
-
points = clone(points);
|
|
8
|
+
if (options.numberOfClusters > count) options.numberOfClusters = count;
|
|
9
|
+
if (options.mutate !== true) points = clone(points);
|
|
12
10
|
var data = coordAll(points);
|
|
13
11
|
var initialCentroids = data.slice(0, options.numberOfClusters);
|
|
14
12
|
var skmeansResult = skmeans(data, options.numberOfClusters, initialCentroids);
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { FeatureCollection, Point, GeoJsonProperties } from \"geojson\";\nimport { clone } from \"@turf/clone\";\nimport { coordAll, featureEach } from \"@turf/meta\";\nimport skmeans from \"skmeans\";\n\ntype KmeansProps = GeoJsonProperties & {\n cluster?: number;\n centroid?: [number, number];\n};\n\n/**\n * Takes a set of {@link Point|points} and partition them into clusters using the k-mean .\n * It uses the [k-means algorithm](https://en.wikipedia.org/wiki/K-means_clustering)\n *\n * @
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { FeatureCollection, Point, GeoJsonProperties } from \"geojson\";\nimport { clone } from \"@turf/clone\";\nimport { coordAll, featureEach } from \"@turf/meta\";\nimport skmeans from \"skmeans\";\n\ntype KmeansProps = GeoJsonProperties & {\n cluster?: number;\n centroid?: [number, number];\n};\n\n/**\n * Takes a set of {@link Point|points} and partition them into clusters using the k-mean .\n * It uses the [k-means algorithm](https://en.wikipedia.org/wiki/K-means_clustering)\n *\n * @function\n * @param {FeatureCollection<Point>} points to be clustered\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.numberOfClusters=Math.sqrt(numberOfPoints/2)] numberOfClusters that will be generated\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {FeatureCollection<Point>} Clustered Points with an additional two properties associated to each Feature:\n * - {number} cluster - the associated clusterId\n * - {[number, number]} centroid - Centroid of the cluster [Longitude, Latitude]\n * @example\n * // create random points with random z-values in their properties\n * var points = turf.randomPoint(100, {bbox: [0, 30, 20, 50]});\n * var options = {numberOfClusters: 7};\n * var clustered = turf.clustersKmeans(points, options);\n *\n * //addToMap\n * var addToMap = [clustered];\n */\nfunction clustersKmeans(\n points: FeatureCollection<Point>,\n options: {\n numberOfClusters?: number;\n mutate?: boolean;\n } = {}\n): FeatureCollection<Point, KmeansProps> {\n // Default Params\n var count = points.features.length;\n options.numberOfClusters =\n options.numberOfClusters || Math.round(Math.sqrt(count / 2));\n\n // numberOfClusters can't be greater than the number of points\n // fallbacks to count\n if (options.numberOfClusters > count) options.numberOfClusters = count;\n\n // Clone points to prevent any mutations (enabled by default)\n if (options.mutate !== true) points = clone(points);\n\n // collect points coordinates\n var data = coordAll(points);\n\n // create seed to avoid skmeans to drift\n var initialCentroids = data.slice(0, options.numberOfClusters);\n\n // create skmeans clusters\n var skmeansResult = skmeans(data, options.numberOfClusters, initialCentroids);\n\n // store centroids {clusterId: [number, number]}\n var centroids: Record<string, number[]> = {};\n (skmeansResult.centroids as number[][]).forEach(function (\n coord: number[],\n idx: number\n ) {\n centroids[idx] = coord;\n });\n\n // add associated cluster number\n featureEach(points, function (point, index) {\n var clusterId = skmeansResult.idxs[index];\n point.properties!.cluster = clusterId;\n point.properties!.centroid = centroids[clusterId];\n });\n\n return points as FeatureCollection<Point, KmeansProps>;\n}\n\nexport { clustersKmeans, KmeansProps };\nexport default clustersKmeans;\n"],"mappings":";AACA,SAAS,aAAa;AACtB,SAAS,UAAU,mBAAmB;AACtC,OAAO,aAAa;AA4BpB,SAAS,eACP,QACA,UAGI,CAAC,GACkC;AAEvC,MAAI,QAAQ,OAAO,SAAS;AAC5B,UAAQ,mBACN,QAAQ,oBAAoB,KAAK,MAAM,KAAK,KAAK,QAAQ,CAAC,CAAC;AAI7D,MAAI,QAAQ,mBAAmB,MAAO,SAAQ,mBAAmB;AAGjE,MAAI,QAAQ,WAAW,KAAM,UAAS,MAAM,MAAM;AAGlD,MAAI,OAAO,SAAS,MAAM;AAG1B,MAAI,mBAAmB,KAAK,MAAM,GAAG,QAAQ,gBAAgB;AAG7D,MAAI,gBAAgB,QAAQ,MAAM,QAAQ,kBAAkB,gBAAgB;AAG5E,MAAI,YAAsC,CAAC;AAC3C,EAAC,cAAc,UAAyB,QAAQ,SAC9C,OACA,KACA;AACA,cAAU,GAAG,IAAI;AAAA,EACnB,CAAC;AAGD,cAAY,QAAQ,SAAU,OAAO,OAAO;AAC1C,QAAI,YAAY,cAAc,KAAK,KAAK;AACxC,UAAM,WAAY,UAAU;AAC5B,UAAM,WAAY,WAAW,UAAU,SAAS;AAAA,EAClD,CAAC;AAED,SAAO;AACT;AAGA,IAAO,+BAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/clusters-kmeans",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "turf clusters-kmeans module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -59,31 +59,31 @@
|
|
|
59
59
|
"test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@turf/centroid": "^7.
|
|
63
|
-
"@turf/clusters": "^7.
|
|
64
|
-
"@turf/random": "^7.
|
|
62
|
+
"@turf/centroid": "^7.2.0",
|
|
63
|
+
"@turf/clusters": "^7.2.0",
|
|
64
|
+
"@turf/random": "^7.2.0",
|
|
65
65
|
"@types/benchmark": "^2.1.5",
|
|
66
66
|
"@types/skmeans": "^0.11.7",
|
|
67
|
-
"@types/tape": "^4.
|
|
67
|
+
"@types/tape": "^4.13.4",
|
|
68
68
|
"benchmark": "^2.1.4",
|
|
69
69
|
"chromatism": "^3.0.0",
|
|
70
70
|
"concaveman": "^1.2.1",
|
|
71
71
|
"load-json-file": "^7.0.1",
|
|
72
72
|
"npm-run-all": "^4.1.5",
|
|
73
|
-
"tape": "^5.
|
|
74
|
-
"tsup": "^8.
|
|
75
|
-
"tsx": "^4.
|
|
76
|
-
"typescript": "^5.
|
|
73
|
+
"tape": "^5.9.0",
|
|
74
|
+
"tsup": "^8.3.5",
|
|
75
|
+
"tsx": "^4.19.2",
|
|
76
|
+
"typescript": "^5.5.4",
|
|
77
77
|
"write-json-file": "^5.0.0"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@turf/clone": "^7.
|
|
81
|
-
"@turf/helpers": "^7.
|
|
82
|
-
"@turf/invariant": "^7.
|
|
83
|
-
"@turf/meta": "^7.
|
|
80
|
+
"@turf/clone": "^7.2.0",
|
|
81
|
+
"@turf/helpers": "^7.2.0",
|
|
82
|
+
"@turf/invariant": "^7.2.0",
|
|
83
|
+
"@turf/meta": "^7.2.0",
|
|
84
84
|
"@types/geojson": "^7946.0.10",
|
|
85
85
|
"skmeans": "0.9.7",
|
|
86
|
-
"tslib": "^2.
|
|
86
|
+
"tslib": "^2.8.1"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
|
|
89
89
|
}
|