turf.pointGrid
What is turf.pointGrid?
turf.pointGrid returns a rectangular grid of Point features at a fixed spacing across a bounding box. It is the standard input for interpolation and contouring pipelines.
turf.pointGrid(bbox, cellSide, options?) → FeatureCollection<Point>Options include:
units— units forcellSide(default'kilometers')mask— aPolygonorMultiPolygon; cells outside the mask are droppedproperties— properties attached to every point
When would you use turf.pointGrid?
Use turf.pointGrid to generate the regular grid of sample locations required by turf.isolines, turf.isobands, and turf.interpolate. It is also useful when you need deterministic, evenly spaced sample points for Monte Carlo tests, tiling analysis, or grid-based dot maps.
When combined with a mask, pointGrid becomes a simple way to sample within an irregular study area — for example generating equally spaced air-quality sample locations only inside a city boundary.
1const bbox = [-122.6, 37.6, -122.3, 37.9];
2const grid = turf.pointGrid(bbox, 0.5, { units: 'kilometers' });FAQs
How do I install Turf.js to use this function?
Install npm install @turf/point-grid and import import { pointGrid } from '@turf/point-grid', or use turf.pointGrid from @turf/turf.
Is the grid aligned to the bbox or its centre?
The grid starts at the bbox's lower-left corner and walks east and north in cellSide steps. If the bbox width is not a whole multiple of cellSide, the rightmost and topmost columns are slightly inside the bbox.
Are cells equally spaced in metres or in degrees?
pointGrid converts cellSide from units to degrees internally, so spacing is in degrees of longitude at the grid's latitude. Over large north–south extents the actual distance between rows varies — fine for visualisation, but verify if you need uniform ground distance.
How do I build a masked grid efficiently?
Pass the mask via options.mask. Turf internally tests each cell's point against the mask before returning, which is significantly faster than post-filtering the grid with turf.pointsWithinPolygon.