index.cjs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
  2. var _booleanpointinpolygon = require('@turf/boolean-point-in-polygon');
  3. var _helpers = require('@turf/helpers');
  4. var _meta = require('@turf/meta');
  5. function pointsWithinPolygon(points, polygons) {
  6. const results = [];
  7. _meta.featureEach.call(void 0, points, function(point) {
  8. let contained = false;
  9. if (point.geometry.type === "Point") {
  10. _meta.geomEach.call(void 0, polygons, function(polygon) {
  11. if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, point, polygon)) {
  12. contained = true;
  13. }
  14. });
  15. if (contained) {
  16. results.push(point);
  17. }
  18. } else if (point.geometry.type === "MultiPoint") {
  19. var pointsWithin = [];
  20. _meta.geomEach.call(void 0, polygons, function(polygon) {
  21. _meta.coordEach.call(void 0, point, function(pointCoord) {
  22. if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, pointCoord, polygon)) {
  23. contained = true;
  24. pointsWithin.push(pointCoord);
  25. }
  26. });
  27. });
  28. if (contained) {
  29. results.push(
  30. _helpers.multiPoint.call(void 0, pointsWithin, point.properties)
  31. );
  32. }
  33. } else {
  34. throw new Error("Input geometry must be a Point or MultiPoint");
  35. }
  36. });
  37. return _helpers.featureCollection.call(void 0, results);
  38. }
  39. var turf_points_within_polygon_default = pointsWithinPolygon;
  40. exports.default = turf_points_within_polygon_default; exports.pointsWithinPolygon = pointsWithinPolygon;
  41. //# sourceMappingURL=index.cjs.map