dgeoutils 2.4.6 → 2.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __generator = (this && this.__generator) || function (thisArg, body) {
2
13
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
3
14
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
@@ -952,11 +963,96 @@ var DPolygon = (function () {
952
963
  }
953
964
  return this;
954
965
  };
955
- DPolygon.parse = function (a) {
956
- return new DPolygon(a.map(function (r) { return DPoint.parse(r); }));
966
+ DPolygon.toGeoJSONFeatureCollection = function (polygons, format) {
967
+ if (format === void 0) { format = 'xyz'; }
968
+ return {
969
+ type: 'FeatureCollection',
970
+ features: polygons.map(function (polygon) { return polygon.toGeoJSONFeature(format); })
971
+ };
957
972
  };
958
- DPolygon.prototype.toArrayOfCoords = function () {
959
- return this.mapArray(function (r) { return r.toCoords(); });
973
+ DPolygon.parse = function (a, format) {
974
+ if (format === void 0) { format = 'xyz'; }
975
+ if (a.type) {
976
+ switch (a.type) {
977
+ case 'FeatureCollection':
978
+ return a.features.reduce(function (ak, f) {
979
+ var t = DPolygon.parse(f, format);
980
+ if (Array.isArray(t)) {
981
+ ak.push.apply(ak, __spreadArray([], __read(t), false));
982
+ }
983
+ else {
984
+ ak.push(t);
985
+ }
986
+ return ak;
987
+ }, []);
988
+ case 'Feature': {
989
+ var t = DPolygon.parse(a.geometry, format);
990
+ t.properties = __assign(__assign({}, a.properties), { id: a.id });
991
+ return t;
992
+ }
993
+ case 'LineString':
994
+ case 'MultiPoint':
995
+ return new DPolygon(a.coordinates.map(function (c) { return DPoint.parse(c, format); }));
996
+ case 'Polygon':
997
+ return a.coordinates.reduce(function (ak, line, index) {
998
+ if (index === 0) {
999
+ ak.points = line.map(function (c) { return DPoint.parse(c, format); });
1000
+ }
1001
+ else {
1002
+ ak.holes.push(new DPolygon(line.map(function (c) { return DPoint.parse(c, format); })));
1003
+ }
1004
+ return ak;
1005
+ }, new DPolygon());
1006
+ case 'MultiLineString':
1007
+ return a.coordinates.reduce(function (ak, line) {
1008
+ ak.push(new DPolygon(line.map(function (c) { return DPoint.parse(c, format); })));
1009
+ return ak;
1010
+ }, []);
1011
+ case 'MultiPolygon':
1012
+ return a.coordinates.reduce(function (ak, coordinates) {
1013
+ ak.push(DPolygon.parse({
1014
+ type: 'Polygon',
1015
+ coordinates: coordinates
1016
+ }, format));
1017
+ return ak;
1018
+ }, []);
1019
+ case 'GeometryCollection':
1020
+ return a.geometries.reduce(function (ak, line) {
1021
+ ak.push(DPolygon.parse(line, format));
1022
+ return ak;
1023
+ }, []);
1024
+ default:
1025
+ }
1026
+ }
1027
+ return new DPolygon(a
1028
+ .map(function (r) { return DPoint.parse(r, format); }));
1029
+ };
1030
+ DPolygon.prototype.toArrayOfCoords = function (format) {
1031
+ if (format === void 0) { format = 'xyz'; }
1032
+ return this.mapArray(function (r) { return r.toCoords(format); });
1033
+ };
1034
+ DPolygon.prototype.toGeoJSONFeature = function (format) {
1035
+ if (format === void 0) { format = 'xyz'; }
1036
+ return {
1037
+ type: 'Feature',
1038
+ properties: __assign({}, this.properties),
1039
+ geometry: this.toGeoJSON(format)
1040
+ };
1041
+ };
1042
+ DPolygon.prototype.toGeoJSON = function (format) {
1043
+ if (format === void 0) { format = 'xyz'; }
1044
+ if (this.closed) {
1045
+ return {
1046
+ type: 'Polygon',
1047
+ coordinates: __spreadArray([
1048
+ this.toArrayOfCoords(format)
1049
+ ], __read(this.holes.map(function (h) { return h.toArrayOfCoords(format); })), false)
1050
+ };
1051
+ }
1052
+ return {
1053
+ type: 'LineString',
1054
+ coordinates: this.toArrayOfCoords(format)
1055
+ };
960
1056
  };
961
1057
  DPolygon.prototype.divideToPieces = function (piecesCount, withAltitude) {
962
1058
  var e_13, _a;