Package Exports
- square-sample-grid
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (square-sample-grid) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
squareGrid
creates a square grid from an arbitrary polygon. the grid can cover, or be inclusive of, the polygon.
based on @turf/square-grid but for use with arbitrary polygons in the viewport coordinate system, not just bounding boxes in the Cartesian coordinate system. For a square grid useful for geo applications, go to Turf.




Parameters
-coordSystem string either canvas or cartesian depending on whether the polygon is in viewport coordinate system coordinate space (e.g. top-left is 0,0) (e.g. for use with canvas or SVGs), or cartesian space (e.g. standard x,y graph stuff) (optional, default cartesian).
noClip[boolean] iftrue, does not remove sample grid units to fit completely within given polygon (optional, defaultfalse)
note on coordSystem:
![]() |
![]() |
|---|---|
| cartesian | viewport/canvas |
usage
npm install square-sample-gridusage
var grid = require('square-sample-grid');
var polygon = [ [20, 20],[60, 20],[80, 40],[10, 40] ];
var cellSize = 20;
var coordSystem = 'canvas';
var noClip = false;
var sampleGrid = grid(polygon, cellSize, coordSystem, noClip);
// [
// [[60, 40],[60, 20],[40, 20],[40, 40]],
// [[40, 40],[40, 20],[20, 20],[20, 40]]
// ]
To Do:
- tests for internal functions
- makeBbox
- [] distance
- [] calculateIntersections
- performance improvements for complex polygons
- make build/browserify step for client-side

