index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // index.ts
  2. import { bbox as turfbbox } from "@turf/bbox";
  3. import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon";
  4. // lib/rbush-export.ts
  5. import lib from "rbush";
  6. var rbush = lib;
  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 = turfbbox(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([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. export {
  44. collect,
  45. turf_collect_default as default
  46. };
  47. //# sourceMappingURL=index.js.map