JSPM

square-sample-grid

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q43036F
  • License MIT

creates a square sampling grid that fits within a given polygon

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.

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