square-sample-grid
v0.1.0
Published
creates a square sampling grid that fits within a given polygon
Downloads
5
Maintainers
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-grid
usage
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
- [x] makeBbox
- [] distance
- [] calculateIntersections
- performance improvements for complex polygons
- make build/browserify step for client-side