index.d.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { FeatureCollection, Feature, Point, Position } from "@turf/helpers";
  2. /**
  3. * Takes a {@link FeatureCollection} of points and calculates the median center,
  4. * algorithimically. The median center is understood as the point that is
  5. * requires the least total travel from all other points.
  6. *
  7. * Turfjs has four different functions for calculating the center of a set of
  8. * data. Each is useful depending on circumstance.
  9. *
  10. * `@turf/center` finds the simple center of a dataset, by finding the
  11. * midpoint between the extents of the data. That is, it divides in half the
  12. * farthest east and farthest west point as well as the farthest north and
  13. * farthest south.
  14. *
  15. * `@turf/center-of-mass` imagines that the dataset is a sheet of paper.
  16. * The center of mass is where the sheet would balance on a fingertip.
  17. *
  18. * `@turf/center-mean` takes the averages of all the coordinates and
  19. * produces a value that respects that. Unlike `@turf/center`, it is
  20. * sensitive to clusters and outliers. It lands in the statistical middle of a
  21. * dataset, not the geographical. It can also be weighted, meaning certain
  22. * points are more important than others.
  23. *
  24. * `@turf/center-median` takes the mean center and tries to find, iteratively,
  25. * a new point that requires the least amount of travel from all the points in
  26. * the dataset. It is not as sensitive to outliers as `@turf/center-mean`, but it is
  27. * attracted to clustered data. It, too, can be weighted.
  28. *
  29. * **Bibliography**
  30. *
  31. * Harold W. Kuhn and Robert E. Kuenne, “An Efficient Algorithm for the
  32. * Numerical Solution of the Generalized Weber Problem in Spatial
  33. * Economics,” _Journal of Regional Science_ 4, no. 2 (1962): 21–33,
  34. * doi:{@link https://doi.org/10.1111/j.1467-9787.1962.tb00902.x}.
  35. *
  36. * James E. Burt, Gerald M. Barber, and David L. Rigby, _Elementary
  37. * Statistics for Geographers_, 3rd ed., New York: The Guilford
  38. * Press, 2009, 150–151.
  39. *
  40. * @name centerMedian
  41. * @param {FeatureCollection<any>} features Any GeoJSON Feature Collection
  42. * @param {Object} [options={}] Optional parameters
  43. * @param {string} [options.weight] the property name used to weight the center
  44. * @param {number} [options.tolerance=0.001] the difference in distance between candidate medians at which point the algorighim stops iterating.
  45. * @param {number} [options.counter=10] how many attempts to find the median, should the tolerance be insufficient.
  46. * @returns {Feature<Point>} The median center of the collection
  47. * @example
  48. * var points = turf.points([[0, 0], [1, 0], [0, 1], [5, 8]]);
  49. * var medianCenter = turf.centerMedian(points);
  50. *
  51. * //addToMap
  52. * var addToMap = [points, medianCenter]
  53. */
  54. declare function centerMedian(features: FeatureCollection<any>, options?: {
  55. weight?: string;
  56. tolerance?: number;
  57. counter?: number;
  58. }): Feature<Point, {
  59. medianCandidates: Array<Position>;
  60. [key: string]: any;
  61. }>;
  62. export default centerMedian;