index.cjs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// index.ts
  2. var _bbox = require('@turf/bbox');
  3. var _booleanpointinpolygon = require('@turf/boolean-point-in-polygon');
  4. // lib/rbush-export.ts
  5. var _rbush = require('rbush'); var _rbush2 = _interopRequireDefault(_rbush);
  6. var rbush = _rbush2.default;
  7. // index.ts
  8. function collect(polygons, points, inProperty, outProperty) {
  9. var rtree = new rbush(6);
  10. var treeItems = points.features.map(function(item) {
  11. var _a;
  12. return {
  13. minX: item.geometry.coordinates[0],
  14. minY: item.geometry.coordinates[1],
  15. maxX: item.geometry.coordinates[0],
  16. maxY: item.geometry.coordinates[1],
  17. property: (_a = item.properties) == null ? void 0 : _a[inProperty]
  18. };
  19. });
  20. rtree.load(treeItems);
  21. polygons.features.forEach(function(poly) {
  22. if (!poly.properties) {
  23. poly.properties = {};
  24. }
  25. var bbox = _bbox.bbox.call(void 0, poly);
  26. var potentialPoints = rtree.search({
  27. minX: bbox[0],
  28. minY: bbox[1],
  29. maxX: bbox[2],
  30. maxY: bbox[3]
  31. });
  32. var values = [];
  33. potentialPoints.forEach(function(pt) {
  34. if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, [pt.minX, pt.minY], poly)) {
  35. values.push(pt.property);
  36. }
  37. });
  38. poly.properties[outProperty] = values;
  39. });
  40. return polygons;
  41. }
  42. var turf_collect_default = collect;
  43. exports.collect = collect; exports.default = turf_collect_default;
  44. //# sourceMappingURL=index.cjs.map