index.d.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import { FeatureCollection } from "@turf/helpers";
  2. /**
  3. * Get Cluster
  4. *
  5. * @name getCluster
  6. * @param {FeatureCollection} geojson GeoJSON Features
  7. * @param {*} filter Filter used on GeoJSON properties to get Cluster
  8. * @returns {FeatureCollection} Single Cluster filtered by GeoJSON Properties
  9. * @example
  10. * var geojson = turf.featureCollection([
  11. * turf.point([0, 0], {'marker-symbol': 'circle'}),
  12. * turf.point([2, 4], {'marker-symbol': 'star'}),
  13. * turf.point([3, 6], {'marker-symbol': 'star'}),
  14. * turf.point([5, 1], {'marker-symbol': 'square'}),
  15. * turf.point([4, 2], {'marker-symbol': 'circle'})
  16. * ]);
  17. *
  18. * // Create a cluster using K-Means (adds `cluster` to GeoJSON properties)
  19. * var clustered = turf.clustersKmeans(geojson);
  20. *
  21. * // Retrieve first cluster (0)
  22. * var cluster = turf.getCluster(clustered, {cluster: 0});
  23. * //= cluster
  24. *
  25. * // Retrieve cluster based on custom properties
  26. * turf.getCluster(clustered, {'marker-symbol': 'circle'}).length;
  27. * //= 2
  28. * turf.getCluster(clustered, {'marker-symbol': 'square'}).length;
  29. * //= 1
  30. */
  31. export declare function getCluster<G extends any, P = any>(geojson: FeatureCollection<G, P>, filter: any): FeatureCollection<G, P>;
  32. /**
  33. * Callback for clusterEach
  34. *
  35. * @callback clusterEachCallback
  36. * @param {FeatureCollection} [cluster] The current cluster being processed.
  37. * @param {*} [clusterValue] Value used to create cluster being processed.
  38. * @param {number} [currentIndex] The index of the current element being processed in the array.Starts at index 0
  39. * @returns {void}
  40. */
  41. /**
  42. * clusterEach
  43. *
  44. * @name clusterEach
  45. * @param {FeatureCollection} geojson GeoJSON Features
  46. * @param {string|number} property GeoJSON property key/value used to create clusters
  47. * @param {Function} callback a method that takes (cluster, clusterValue, currentIndex)
  48. * @returns {void}
  49. * @example
  50. * var geojson = turf.featureCollection([
  51. * turf.point([0, 0]),
  52. * turf.point([2, 4]),
  53. * turf.point([3, 6]),
  54. * turf.point([5, 1]),
  55. * turf.point([4, 2])
  56. * ]);
  57. *
  58. * // Create a cluster using K-Means (adds `cluster` to GeoJSON properties)
  59. * var clustered = turf.clustersKmeans(geojson);
  60. *
  61. * // Iterate over each cluster
  62. * turf.clusterEach(clustered, 'cluster', function (cluster, clusterValue, currentIndex) {
  63. * //= cluster
  64. * //= clusterValue
  65. * //= currentIndex
  66. * })
  67. *
  68. * // Calculate the total number of clusters
  69. * var total = 0
  70. * turf.clusterEach(clustered, 'cluster', function () {
  71. * total++;
  72. * });
  73. *
  74. * // Create an Array of all the values retrieved from the 'cluster' property
  75. * var values = []
  76. * turf.clusterEach(clustered, 'cluster', function (cluster, clusterValue) {
  77. * values.push(clusterValue);
  78. * });
  79. */
  80. export declare function clusterEach<G = any, P = any>(geojson: FeatureCollection<G, P>, property: number | string, callback: (cluster?: FeatureCollection<G, P>, clusterValue?: any, currentIndex?: number) => void): void;
  81. /**
  82. * Callback for clusterReduce
  83. *
  84. * The first time the callback function is called, the values provided as arguments depend
  85. * on whether the reduce method has an initialValue argument.
  86. *
  87. * If an initialValue is provided to the reduce method:
  88. * - The previousValue argument is initialValue.
  89. * - The currentValue argument is the value of the first element present in the array.
  90. *
  91. * If an initialValue is not provided:
  92. * - The previousValue argument is the value of the first element present in the array.
  93. * - The currentValue argument is the value of the second element present in the array.
  94. *
  95. * @callback clusterReduceCallback
  96. * @param {*} [previousValue] The accumulated value previously returned in the last invocation
  97. * of the callback, or initialValue, if supplied.
  98. * @param {FeatureCollection} [cluster] The current cluster being processed.
  99. * @param {*} [clusterValue] Value used to create cluster being processed.
  100. * @param {number} [currentIndex] The index of the current element being processed in the
  101. * array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
  102. */
  103. /**
  104. * Reduce clusters in GeoJSON Features, similar to Array.reduce()
  105. *
  106. * @name clusterReduce
  107. * @param {FeatureCollection} geojson GeoJSON Features
  108. * @param {string|number} property GeoJSON property key/value used to create clusters
  109. * @param {Function} callback a method that takes (previousValue, cluster, clusterValue, currentIndex)
  110. * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
  111. * @returns {*} The value that results from the reduction.
  112. * @example
  113. * var geojson = turf.featureCollection([
  114. * turf.point([0, 0]),
  115. * turf.point([2, 4]),
  116. * turf.point([3, 6]),
  117. * turf.point([5, 1]),
  118. * turf.point([4, 2])
  119. * ]);
  120. *
  121. * // Create a cluster using K-Means (adds `cluster` to GeoJSON properties)
  122. * var clustered = turf.clustersKmeans(geojson);
  123. *
  124. * // Iterate over each cluster and perform a calculation
  125. * var initialValue = 0
  126. * turf.clusterReduce(clustered, 'cluster', function (previousValue, cluster, clusterValue, currentIndex) {
  127. * //=previousValue
  128. * //=cluster
  129. * //=clusterValue
  130. * //=currentIndex
  131. * return previousValue++;
  132. * }, initialValue);
  133. *
  134. * // Calculate the total number of clusters
  135. * var total = turf.clusterReduce(clustered, 'cluster', function (previousValue) {
  136. * return previousValue++;
  137. * }, 0);
  138. *
  139. * // Create an Array of all the values retrieved from the 'cluster' property
  140. * var values = turf.clusterReduce(clustered, 'cluster', function (previousValue, cluster, clusterValue) {
  141. * return previousValue.concat(clusterValue);
  142. * }, []);
  143. */
  144. export declare function clusterReduce<G = any, P = any>(geojson: FeatureCollection<G, P>, property: number | string, callback: (previousValue?: any, cluster?: FeatureCollection<G, P>, clusterValue?: any, currentIndex?: number) => void, initialValue?: any): void;
  145. /**
  146. * Create Bins
  147. *
  148. * @private
  149. * @param {FeatureCollection} geojson GeoJSON Features
  150. * @param {string|number} property Property values are used to create bins
  151. * @returns {Object} bins with Feature IDs
  152. * @example
  153. * var geojson = turf.featureCollection([
  154. * turf.point([0, 0], {cluster: 0, foo: 'null'}),
  155. * turf.point([2, 4], {cluster: 1, foo: 'bar'}),
  156. * turf.point([5, 1], {0: 'foo'}),
  157. * turf.point([3, 6], {cluster: 1}),
  158. * ]);
  159. * createBins(geojson, 'cluster');
  160. * //= { '0': [ 0 ], '1': [ 1, 3 ] }
  161. */
  162. export declare function createBins(geojson: FeatureCollection<any>, property: string | number): Record<string, number[]>;
  163. /**
  164. * Apply Filter
  165. *
  166. * @private
  167. * @param {*} properties Properties
  168. * @param {*} filter Filter
  169. * @returns {boolean} applied Filter to properties
  170. */
  171. export declare function applyFilter(properties: any, filter: any): boolean;
  172. /**
  173. * Properties contains filter (does not apply deepEqual operations)
  174. *
  175. * @private
  176. * @param {*} properties Properties
  177. * @param {Object} filter Filter
  178. * @returns {boolean} does filter equal Properties
  179. * @example
  180. * propertiesContainsFilter({foo: 'bar', cluster: 0}, {cluster: 0})
  181. * //= true
  182. * propertiesContainsFilter({foo: 'bar', cluster: 0}, {cluster: 1})
  183. * //= false
  184. */
  185. export declare function propertiesContainsFilter(properties: any, filter: any): boolean;
  186. /**
  187. * Filter Properties
  188. *
  189. * @private
  190. * @param {*} properties Properties
  191. * @param {Array<string>} keys Used to filter Properties
  192. * @returns {*} filtered Properties
  193. * @example
  194. * filterProperties({foo: 'bar', cluster: 0}, ['cluster'])
  195. * //= {cluster: 0}
  196. */
  197. export declare function filterProperties(properties: Record<string, any>, keys: string[]): any;