index.d.ts 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. import { FeatureCollection, Point, Properties } from "@turf/helpers";
  2. export declare type KmeansProps = Properties & {
  3. cluster?: number;
  4. centroid?: [number, number];
  5. };
  6. /**
  7. * Takes a set of {@link Point|points} and partition them into clusters using the k-mean .
  8. * It uses the [k-means algorithm](https://en.wikipedia.org/wiki/K-means_clustering)
  9. *
  10. * @name clustersKmeans
  11. * @param {FeatureCollection<Point>} points to be clustered
  12. * @param {Object} [options={}] Optional parameters
  13. * @param {number} [options.numberOfClusters=Math.sqrt(numberOfPoints/2)] numberOfClusters that will be generated
  14. * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
  15. * @returns {FeatureCollection<Point>} Clustered Points with an additional two properties associated to each Feature:
  16. * - {number} cluster - the associated clusterId
  17. * - {[number, number]} centroid - Centroid of the cluster [Longitude, Latitude]
  18. * @example
  19. * // create random points with random z-values in their properties
  20. * var points = turf.randomPoint(100, {bbox: [0, 30, 20, 50]});
  21. * var options = {numberOfClusters: 7};
  22. * var clustered = turf.clustersKmeans(points, options);
  23. *
  24. * //addToMap
  25. * var addToMap = [clustered];
  26. */
  27. declare function clustersKmeans(points: FeatureCollection<Point>, options?: {
  28. numberOfClusters?: number;
  29. mutate?: boolean;
  30. }): FeatureCollection<Point, KmeansProps>;
  31. export default clustersKmeans;