| 12345678910111213141516171819202122232425 |
- // index.ts
- import { featureCollection } from "@turf/helpers";
- function sample(fc, num) {
- if (!fc) throw new Error("fc is required");
- if (num === null || num === void 0) throw new Error("num is required");
- if (typeof num !== "number") throw new Error("num must be a number");
- var outFC = featureCollection(getRandomSubarray(fc.features, num));
- return outFC;
- }
- function getRandomSubarray(arr, size) {
- var shuffled = arr.slice(0), i = arr.length, min = i - size, temp, index;
- while (i-- > min) {
- index = Math.floor((i + 1) * Math.random());
- temp = shuffled[index];
- shuffled[index] = shuffled[i];
- shuffled[i] = temp;
- }
- return shuffled.slice(min);
- }
- var turf_sample_default = sample;
- export {
- turf_sample_default as default,
- sample
- };
- //# sourceMappingURL=index.js.map
|