Create n number of random points inside a polygon with TurfJS!
npm install random-points-on-polygon
Params
number
: Integer - the number of random points generatedpolygon
: Feature<(Polygon|MutiPolygon)> - boundary within points are createdproperties
: Object [properties={}] - properties object assigned to each random point featurefc
: Boolean [fc=false] - Default returns an array of point features. Whentrue
, returns a feature collection of points
Returns
points
: Default Array Feature<(Point)> - whenfc
is set totrue
it returns a FeatureCollection<(Points)>
var randomPointsOnPolygon = require('random-points-on-polygon');
var turf = require('turf');
var numberOfPoints = 100;
var polygon = turf.random('polygon').features[0];
var points = randomPointsOnPolygon(numberOfPoints, polygon);
// points Array
// [
// {
// "type": "Feature",
// "geometry": {
// "type": "Point",
// "coordinates": [
// 104.92817194987191,
// 72.68912038906443
// ]
// },
// "properties": {}
// },
// {
// "type": "Feature",
// "geometry": {
// "type": "Point",
// "coordinates": [
// 104.8246191221799,
// 72.02970325707525
// ]
// }
// },
// ...
// ]
##Contact
Andy B