index.cjs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
  2. var _booleanwithin = require('@turf/boolean-within');
  3. var _distance = require('@turf/distance');
  4. var _helpers = require('@turf/helpers');
  5. function pointGrid(bbox, cellSide, options = {}) {
  6. if (options.mask && !options.units) options.units = "kilometers";
  7. var results = [];
  8. var west = bbox[0];
  9. var south = bbox[1];
  10. var east = bbox[2];
  11. var north = bbox[3];
  12. var xFraction = cellSide / _distance.distance.call(void 0, [west, south], [east, south], options);
  13. var cellWidth = xFraction * (east - west);
  14. var yFraction = cellSide / _distance.distance.call(void 0, [west, south], [west, north], options);
  15. var cellHeight = yFraction * (north - south);
  16. var bboxWidth = east - west;
  17. var bboxHeight = north - south;
  18. var columns = Math.floor(bboxWidth / cellWidth);
  19. var rows = Math.floor(bboxHeight / cellHeight);
  20. var deltaX = (bboxWidth - columns * cellWidth) / 2;
  21. var deltaY = (bboxHeight - rows * cellHeight) / 2;
  22. var currentX = west + deltaX;
  23. while (currentX <= east) {
  24. var currentY = south + deltaY;
  25. while (currentY <= north) {
  26. var cellPt = _helpers.point.call(void 0, [currentX, currentY], options.properties);
  27. if (options.mask) {
  28. if (_booleanwithin.booleanWithin.call(void 0, cellPt, options.mask)) results.push(cellPt);
  29. } else {
  30. results.push(cellPt);
  31. }
  32. currentY += cellHeight;
  33. }
  34. currentX += cellWidth;
  35. }
  36. return _helpers.featureCollection.call(void 0, results);
  37. }
  38. var turf_point_grid_default = pointGrid;
  39. exports.default = turf_point_grid_default; exports.pointGrid = pointGrid;
  40. //# sourceMappingURL=index.cjs.map