index.d.cts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { GeoJsonProperties, FeatureCollection, Point } from 'geojson';
  2. import { Units } from '@turf/helpers';
  3. /**
  4. * Point classification within the cluster.
  5. *
  6. * @typedef {"core" | "edge" | "noise"} Dbscan
  7. */
  8. type Dbscan = "core" | "edge" | "noise";
  9. /**
  10. * Properties assigned to each clustered point.
  11. *
  12. * @extends GeoJsonProperties
  13. * @typedef {object} DbscanProps
  14. * @property {Dbscan} [dbscan] type of point it has been classified as
  15. * @property {number} [cluster] associated clusterId
  16. */
  17. type DbscanProps = GeoJsonProperties & {
  18. dbscan?: Dbscan;
  19. cluster?: number;
  20. };
  21. /**
  22. * Takes a set of {@link Point|points} and partition them into clusters according to {@link https://en.wikipedia.org/wiki/DBSCAN|DBSCAN's} data clustering algorithm.
  23. *
  24. * @function
  25. * @param {FeatureCollection<Point>} points to be clustered
  26. * @param {number} maxDistance Maximum Distance between any point of the cluster to generate the clusters (kilometers by default, see options)
  27. * @param {Object} [options={}] Optional parameters
  28. * @param {string} [options.units="kilometers"] in which `maxDistance` is expressed, can be degrees, radians, miles, or kilometers
  29. * @param {boolean} [options.mutate=false] Allows GeoJSON input to be mutated
  30. * @param {number} [options.minPoints=3] Minimum number of points to generate a single cluster,
  31. * points which do not meet this requirement will be classified as an 'edge' or 'noise'.
  32. * @returns {FeatureCollection<Point, DbscanProps>} Clustered Points with an additional two properties associated to each Feature:
  33. * - {number} cluster - the associated clusterId
  34. * - {string} dbscan - type of point it has been classified as ('core'|'edge'|'noise')
  35. * @example
  36. * // create random points with random z-values in their properties
  37. * var points = turf.randomPoint(100, {bbox: [0, 30, 20, 50]});
  38. * var maxDistance = 100;
  39. * var clustered = turf.clustersDbscan(points, maxDistance);
  40. *
  41. * //addToMap
  42. * var addToMap = [clustered];
  43. */
  44. declare function clustersDbscan(points: FeatureCollection<Point>, maxDistance: number, options?: {
  45. units?: Units;
  46. minPoints?: number;
  47. mutate?: boolean;
  48. }): FeatureCollection<Point, DbscanProps>;
  49. export { type Dbscan, type DbscanProps, clustersDbscan, clustersDbscan as default };