turf icon indicating copy to clipboard operation
turf copied to clipboard

Feature request: pointGrid properties as a function

Open davidcalhoun opened this issue 1 year ago • 0 comments

Thank you for this great library! pointGrid is really handy for creating stub data, and it's great to be able to pass properties to each point in the options. Each point however gets the exact same properties:

const extent = [-104.352175, 34.743906, -101.905469, 33.115206];
const distanceBetweenPointsKm = 1;
const grid = pointGrid(extent, distanceBetweenPointsKm, {
        units: 'kilometers',
        properties: { magnitude: getRandomMagnitude() }
});
// output: each point has the same magnitude in properties

In this case every point gets the exact same magnitude value. It would be handier to be able to pass a function to properties so each point can generate a unique magnitude:

// warning - this doesn't currently work!  this is a feature request

const extent = [-104.352175, 34.743906, -101.905469, 33.115206];
const distanceBetweenPointsKm = 1;
const grid = pointGrid(extent, distanceBetweenPointsKm, {
        units: 'kilometers',
        properties: (coords) => ( { magnitude: getRandomMagnitude() } )
});
// output: each point has a different same magnitude in properties

Thank you in advance!

davidcalhoun avatar Jul 08 '22 17:07 davidcalhoun