@seasketch/geoprocessing
Version:
Geoprocessing and reporting framework for SeaSketch 2.0
24 lines • 915 B
JavaScript
import { randomPolygon, featureReduce, featureCollection } from "@turf/turf";
/**
* Generates random polygons within provided bounds. numPolygons defaults to 300, max_radial_length to 0.5
* Wrapper around @turf/random - https://turfjs.org/docs/#randomPolygon
*/
export const genRandomPolygons = (config) => {
const { numPolygons = 300, bounds, max_radial_length = 0.25 } = config;
const randPolys = randomPolygon(numPolygons, {
bbox: bounds,
max_radial_length,
});
const proppedPolys = featureReduce(randPolys, (previousValue, currentFeature, featureIndex) => {
return previousValue.concat({
...currentFeature,
id: featureIndex + 1,
properties: {
id: featureIndex + 1,
},
});
}, []);
const fc = featureCollection(proppedPolys);
return fc;
};
//# sourceMappingURL=genRandomPolygons.js.map