Skip to content

notchris/square-grid

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

screen shot 2017-08-08 at 12 18 12 pmscreen shot 2017-08-08 at 12 17 42 pm

screen shot 2017-08-08 at 12 16 15 pmscreen shot 2017-08-08 at 12 16 50 pm

Parameters

  • polygonArray<number> array of vertices in [[x, y],...]

  • cellSize number width of each cell

  • 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] if true, does not remove sample grid units to fit completely within given polygon (optional, default false)

note on coordSystem:

cartesian canvas
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
    • makeBbox
    • [] distance
    • [] calculateIntersections
  • performance improvements for complex polygons
  • make build/browserify step for client-side

About

creates a square sampling grid that fits within a given polygon

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 88.3%
  • HTML 11.7%