index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // index.ts
  2. import { feature, featureCollection } from "@turf/helpers";
  3. import { featureEach } from "@turf/meta";
  4. function combine(fc) {
  5. var groups = {
  6. MultiPoint: {
  7. coordinates: [],
  8. properties: []
  9. },
  10. MultiLineString: {
  11. coordinates: [],
  12. properties: []
  13. },
  14. MultiPolygon: {
  15. coordinates: [],
  16. properties: []
  17. }
  18. };
  19. featureEach(fc, (feature2) => {
  20. var _a;
  21. switch ((_a = feature2.geometry) == null ? void 0 : _a.type) {
  22. case "Point":
  23. groups.MultiPoint.coordinates.push(feature2.geometry.coordinates);
  24. groups.MultiPoint.properties.push(feature2.properties);
  25. break;
  26. case "MultiPoint":
  27. groups.MultiPoint.coordinates.push(...feature2.geometry.coordinates);
  28. groups.MultiPoint.properties.push(feature2.properties);
  29. break;
  30. case "LineString":
  31. groups.MultiLineString.coordinates.push(feature2.geometry.coordinates);
  32. groups.MultiLineString.properties.push(feature2.properties);
  33. break;
  34. case "MultiLineString":
  35. groups.MultiLineString.coordinates.push(
  36. ...feature2.geometry.coordinates
  37. );
  38. groups.MultiLineString.properties.push(feature2.properties);
  39. break;
  40. case "Polygon":
  41. groups.MultiPolygon.coordinates.push(feature2.geometry.coordinates);
  42. groups.MultiPolygon.properties.push(feature2.properties);
  43. break;
  44. case "MultiPolygon":
  45. groups.MultiPolygon.coordinates.push(...feature2.geometry.coordinates);
  46. groups.MultiPolygon.properties.push(feature2.properties);
  47. break;
  48. default:
  49. break;
  50. }
  51. });
  52. return featureCollection(
  53. Object.keys(groups).filter(function(key) {
  54. return groups[key].coordinates.length;
  55. }).sort().map(function(key) {
  56. var geometry = { type: key, coordinates: groups[key].coordinates };
  57. var properties = { collectedProperties: groups[key].properties };
  58. return feature(geometry, properties);
  59. })
  60. );
  61. }
  62. var turf_combine_default = combine;
  63. export {
  64. combine,
  65. turf_combine_default as default
  66. };
  67. //# sourceMappingURL=index.js.map