index.cjs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
  2. var _helpers = require('@turf/helpers');
  3. var _invariant = require('@turf/invariant');
  4. function polygonToLine(poly, options = {}) {
  5. const geom = _invariant.getGeom.call(void 0, poly);
  6. if (!options.properties && poly.type === "Feature") {
  7. options.properties = poly.properties;
  8. }
  9. switch (geom.type) {
  10. case "Polygon":
  11. return singlePolygonToLine(geom, options);
  12. case "MultiPolygon":
  13. return multiPolygonToLine(geom, options);
  14. default:
  15. throw new Error("invalid poly");
  16. }
  17. }
  18. function singlePolygonToLine(poly, options = {}) {
  19. const geom = _invariant.getGeom.call(void 0, poly);
  20. const coords = geom.coordinates;
  21. const properties = options.properties ? options.properties : poly.type === "Feature" ? poly.properties : {};
  22. return coordsToLine(coords, properties);
  23. }
  24. function multiPolygonToLine(multiPoly, options = {}) {
  25. const geom = _invariant.getGeom.call(void 0, multiPoly);
  26. const coords = geom.coordinates;
  27. const properties = options.properties ? options.properties : multiPoly.type === "Feature" ? multiPoly.properties : {};
  28. const lines = [];
  29. coords.forEach((coord) => {
  30. lines.push(coordsToLine(coord, properties));
  31. });
  32. return _helpers.featureCollection.call(void 0, lines);
  33. }
  34. function coordsToLine(coords, properties) {
  35. if (coords.length > 1) {
  36. return _helpers.multiLineString.call(void 0, coords, properties);
  37. }
  38. return _helpers.lineString.call(void 0, coords[0], properties);
  39. }
  40. var turf_polygon_to_line_default = polygonToLine;
  41. exports.coordsToLine = coordsToLine; exports.default = turf_polygon_to_line_default; exports.multiPolygonToLine = multiPolygonToLine; exports.polygonToLine = polygonToLine; exports.singlePolygonToLine = singlePolygonToLine;
  42. //# sourceMappingURL=index.cjs.map