index.d.cts 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { Feature, Polygon, FeatureCollection, GeoJsonProperties } from 'geojson';
  2. import { Units, AreaUnits } from '@turf/helpers';
  3. /**
  4. * Nearest neighbour statistics.
  5. *
  6. * @typedef {object} NearestNeighborStatistics
  7. * @property {(Units & AreaUnits)} units
  8. * @property {string} arealUnits
  9. * @property {number} observedMeanDistance
  10. * @property {number} expectedMeanDistance
  11. * @property {number} numberOfPoints
  12. * @property {number} zScore
  13. */
  14. interface NearestNeighborStatistics {
  15. units: Units & AreaUnits;
  16. arealUnits: string;
  17. observedMeanDistance: number;
  18. expectedMeanDistance: number;
  19. numberOfPoints: number;
  20. zScore: number;
  21. }
  22. /**
  23. * Nearest neighbour study area polygon feature.
  24. *
  25. * @typedef {object} NearestNeighborStudyArea
  26. * @extends Feature<Polygon>
  27. * @property {GeoJsonProperties} properties
  28. * @property {NearestNeighborStatistics} properties.nearestNeighborAnalysis
  29. */
  30. interface NearestNeighborStudyArea extends Feature<Polygon> {
  31. properties: {
  32. nearestNeighborAnalysis: NearestNeighborStatistics;
  33. [key: string]: any;
  34. };
  35. }
  36. /**
  37. * Nearest Neighbor Analysis calculates an index based the average distances
  38. * between points in the dataset, thereby providing inference as to whether the
  39. * data is clustered, dispersed, or randomly distributed within the study area.
  40. *
  41. * It returns a {@link Feature}<{@link Polygon}> of the study area, with the results of
  42. * the analysis attached as part of of the `nearestNeighborAnalysis` property
  43. * of the study area's `properties`. The attached
  44. * [_z_-score](https://en.wikipedia.org/wiki/Standard_score) indicates how many
  45. * standard deviations above or below the expected mean distance the data's
  46. * observed mean distance is. The more negative, the more clustered. The more
  47. * positive, the more evenly dispersed. A _z_-score between -2 and 2 indicates
  48. * a seemingly random distribution. That is, within _p_ of less than 0.05, the
  49. * distribution appears statistically significantly neither clustered nor
  50. * dispersed.
  51. *
  52. * **Remarks**
  53. *
  54. * - Though the analysis will work on any {@link FeatureCollection} type, it
  55. * works best with {@link Point} collections.
  56. *
  57. * - This analysis is _very_ sensitive to the study area provided.
  58. * If no {@link Feature}<{@link Polygon}> is passed as the study area, the function draws a box
  59. * around the data, which may distort the findings. This analysis works best
  60. * with a bounded area of interest within with the data is either clustered,
  61. * dispersed, or randomly distributed. For example, a city's subway stops may
  62. * look extremely clustered if the study area is an entire state. On the other
  63. * hand, they may look rather evenly dispersed if the study area is limited to
  64. * the city's downtown.
  65. *
  66. * **Bibliography**
  67. *
  68. * Philip J. Clark and Francis C. Evans, “Distance to Nearest Neighbor as a
  69. * Measure of Spatial Relationships in Populations,” _Ecology_ 35, no. 4
  70. * (1954): 445–453, doi:[10.2307/1931034](http://doi.org/10.2307/1931034).
  71. *
  72. * @function
  73. * @param {FeatureCollection<any>} dataset FeatureCollection (pref. of points) to study
  74. * @param {Object} [options={}] Optional parameters
  75. * @param {Feature<Polygon>} [options.studyArea] polygon representing the study area
  76. * @param {Units & AreaUnits} [options.units='kilometers'] unit of measurement for distances and, squared, area.
  77. * @param {GeoJsonProperties} [options.properties={}] properties
  78. * @returns {NearestNeighborStudyArea} A polygon of the study area or an approximation of one.
  79. * @example
  80. * var bbox = [-65, 40, -63, 42];
  81. * var dataset = turf.randomPoint(100, { bbox: bbox });
  82. * var nearestNeighborStudyArea = turf.nearestNeighborAnalysis(dataset);
  83. *
  84. * //addToMap
  85. * var addToMap = [dataset, nearestNeighborStudyArea];
  86. */
  87. declare function nearestNeighborAnalysis(dataset: FeatureCollection<any>, options?: {
  88. studyArea?: Feature<Polygon>;
  89. units?: Units & AreaUnits;
  90. properties?: GeoJsonProperties;
  91. }): NearestNeighborStudyArea;
  92. export { type NearestNeighborStatistics, type NearestNeighborStudyArea, nearestNeighborAnalysis as default, nearestNeighborAnalysis };