index.cjs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
  2. var _booleanintersects = require('@turf/boolean-intersects');
  3. var _helpers = require('@turf/helpers');
  4. function rectangleGrid(bbox, cellWidth, cellHeight, options = {}) {
  5. const results = [];
  6. const west = bbox[0];
  7. const south = bbox[1];
  8. const east = bbox[2];
  9. const north = bbox[3];
  10. const bboxWidth = east - west;
  11. const cellWidthDeg = _helpers.convertLength.call(void 0, cellWidth, options.units, "degrees");
  12. const bboxHeight = north - south;
  13. const cellHeightDeg = _helpers.convertLength.call(void 0, cellHeight, options.units, "degrees");
  14. const columns = Math.floor(Math.abs(bboxWidth) / cellWidthDeg);
  15. const rows = Math.floor(Math.abs(bboxHeight) / cellHeightDeg);
  16. const deltaX = (bboxWidth - columns * cellWidthDeg) / 2;
  17. const deltaY = (bboxHeight - rows * cellHeightDeg) / 2;
  18. let currentX = west + deltaX;
  19. for (let column = 0; column < columns; column++) {
  20. let currentY = south + deltaY;
  21. for (let row = 0; row < rows; row++) {
  22. const cellPoly = _helpers.polygon.call(void 0,
  23. [
  24. [
  25. [currentX, currentY],
  26. [currentX, currentY + cellHeightDeg],
  27. [currentX + cellWidthDeg, currentY + cellHeightDeg],
  28. [currentX + cellWidthDeg, currentY],
  29. [currentX, currentY]
  30. ]
  31. ],
  32. options.properties
  33. );
  34. if (options.mask) {
  35. if (_booleanintersects.booleanIntersects.call(void 0, options.mask, cellPoly)) {
  36. results.push(cellPoly);
  37. }
  38. } else {
  39. results.push(cellPoly);
  40. }
  41. currentY += cellHeightDeg;
  42. }
  43. currentX += cellWidthDeg;
  44. }
  45. return _helpers.featureCollection.call(void 0, results);
  46. }
  47. var turf_rectangle_grid_default = rectangleGrid;
  48. exports.default = turf_rectangle_grid_default; exports.rectangleGrid = rectangleGrid;
  49. //# sourceMappingURL=index.cjs.map