@loaders.gl/gis 3.4.14 → 3.4.15

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,167 +1,90 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.extractGeometryInfo = extractGeometryInfo;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
10
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
12
7
  function extractGeometryInfo(features) {
13
- var pointPositionsCount = 0;
14
- var pointFeaturesCount = 0;
15
- var linePositionsCount = 0;
16
- var linePathsCount = 0;
17
- var lineFeaturesCount = 0;
18
- var polygonPositionsCount = 0;
19
- var polygonObjectsCount = 0;
20
- var polygonRingsCount = 0;
21
- var polygonFeaturesCount = 0;
22
- var coordLengths = new Set();
23
- var _iterator = _createForOfIteratorHelper(features),
24
- _step;
25
- try {
26
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
27
- var feature = _step.value;
28
- var geometry = feature.geometry;
29
- switch (geometry.type) {
30
- case 'Point':
31
- pointFeaturesCount++;
32
- pointPositionsCount++;
33
- coordLengths.add(geometry.coordinates.length);
34
- break;
35
- case 'MultiPoint':
36
- pointFeaturesCount++;
37
- pointPositionsCount += geometry.coordinates.length;
38
- var _iterator2 = _createForOfIteratorHelper(geometry.coordinates),
39
- _step2;
40
- try {
41
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
42
- var point = _step2.value;
43
- coordLengths.add(point.length);
44
- }
45
- } catch (err) {
46
- _iterator2.e(err);
47
- } finally {
48
- _iterator2.f();
49
- }
50
- break;
51
- case 'LineString':
52
- lineFeaturesCount++;
53
- linePositionsCount += geometry.coordinates.length;
8
+ let pointPositionsCount = 0;
9
+ let pointFeaturesCount = 0;
10
+ let linePositionsCount = 0;
11
+ let linePathsCount = 0;
12
+ let lineFeaturesCount = 0;
13
+ let polygonPositionsCount = 0;
14
+ let polygonObjectsCount = 0;
15
+ let polygonRingsCount = 0;
16
+ let polygonFeaturesCount = 0;
17
+ const coordLengths = new Set();
18
+ for (const feature of features) {
19
+ const geometry = feature.geometry;
20
+ switch (geometry.type) {
21
+ case 'Point':
22
+ pointFeaturesCount++;
23
+ pointPositionsCount++;
24
+ coordLengths.add(geometry.coordinates.length);
25
+ break;
26
+ case 'MultiPoint':
27
+ pointFeaturesCount++;
28
+ pointPositionsCount += geometry.coordinates.length;
29
+ for (const point of geometry.coordinates) {
30
+ coordLengths.add(point.length);
31
+ }
32
+ break;
33
+ case 'LineString':
34
+ lineFeaturesCount++;
35
+ linePositionsCount += geometry.coordinates.length;
36
+ linePathsCount++;
37
+ for (const coord of geometry.coordinates) {
38
+ coordLengths.add(coord.length);
39
+ }
40
+ break;
41
+ case 'MultiLineString':
42
+ lineFeaturesCount++;
43
+ for (const line of geometry.coordinates) {
44
+ linePositionsCount += line.length;
54
45
  linePathsCount++;
55
- var _iterator3 = _createForOfIteratorHelper(geometry.coordinates),
56
- _step3;
57
- try {
58
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
59
- var coord = _step3.value;
60
- coordLengths.add(coord.length);
61
- }
62
- } catch (err) {
63
- _iterator3.e(err);
64
- } finally {
65
- _iterator3.f();
66
- }
67
- break;
68
- case 'MultiLineString':
69
- lineFeaturesCount++;
70
- var _iterator4 = _createForOfIteratorHelper(geometry.coordinates),
71
- _step4;
72
- try {
73
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
74
- var line = _step4.value;
75
- linePositionsCount += line.length;
76
- linePathsCount++;
77
- var _iterator5 = _createForOfIteratorHelper(line),
78
- _step5;
79
- try {
80
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
81
- var _coord = _step5.value;
82
- coordLengths.add(_coord.length);
83
- }
84
- } catch (err) {
85
- _iterator5.e(err);
86
- } finally {
87
- _iterator5.f();
88
- }
89
- }
90
- } catch (err) {
91
- _iterator4.e(err);
92
- } finally {
93
- _iterator4.f();
46
+ for (const coord of line) {
47
+ coordLengths.add(coord.length);
94
48
  }
95
- break;
96
- case 'Polygon':
97
- polygonFeaturesCount++;
49
+ }
50
+ break;
51
+ case 'Polygon':
52
+ polygonFeaturesCount++;
53
+ polygonObjectsCount++;
54
+ polygonRingsCount += geometry.coordinates.length;
55
+ const flattened = geometry.coordinates.flat();
56
+ polygonPositionsCount += flattened.length;
57
+ for (const coord of flattened) {
58
+ coordLengths.add(coord.length);
59
+ }
60
+ break;
61
+ case 'MultiPolygon':
62
+ polygonFeaturesCount++;
63
+ for (const polygon of geometry.coordinates) {
98
64
  polygonObjectsCount++;
99
- polygonRingsCount += geometry.coordinates.length;
100
- var flattened = geometry.coordinates.flat();
65
+ polygonRingsCount += polygon.length;
66
+ const flattened = polygon.flat();
101
67
  polygonPositionsCount += flattened.length;
102
- var _iterator6 = _createForOfIteratorHelper(flattened),
103
- _step6;
104
- try {
105
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
106
- var _coord2 = _step6.value;
107
- coordLengths.add(_coord2.length);
108
- }
109
- } catch (err) {
110
- _iterator6.e(err);
111
- } finally {
112
- _iterator6.f();
113
- }
114
- break;
115
- case 'MultiPolygon':
116
- polygonFeaturesCount++;
117
- var _iterator7 = _createForOfIteratorHelper(geometry.coordinates),
118
- _step7;
119
- try {
120
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
121
- var polygon = _step7.value;
122
- polygonObjectsCount++;
123
- polygonRingsCount += polygon.length;
124
- var _flattened = polygon.flat();
125
- polygonPositionsCount += _flattened.length;
126
- var _iterator8 = _createForOfIteratorHelper(_flattened),
127
- _step8;
128
- try {
129
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
130
- var _coord3 = _step8.value;
131
- coordLengths.add(_coord3.length);
132
- }
133
- } catch (err) {
134
- _iterator8.e(err);
135
- } finally {
136
- _iterator8.f();
137
- }
138
- }
139
- } catch (err) {
140
- _iterator7.e(err);
141
- } finally {
142
- _iterator7.f();
68
+ for (const coord of flattened) {
69
+ coordLengths.add(coord.length);
143
70
  }
144
- break;
145
- default:
146
- throw new Error("Unsupported geometry type: ".concat(geometry.type));
147
- }
71
+ }
72
+ break;
73
+ default:
74
+ throw new Error("Unsupported geometry type: ".concat(geometry.type));
148
75
  }
149
- } catch (err) {
150
- _iterator.e(err);
151
- } finally {
152
- _iterator.f();
153
76
  }
154
77
  return {
155
- coordLength: coordLengths.size > 0 ? Math.max.apply(Math, (0, _toConsumableArray2.default)(coordLengths)) : 2,
156
- pointPositionsCount: pointPositionsCount,
157
- pointFeaturesCount: pointFeaturesCount,
158
- linePositionsCount: linePositionsCount,
159
- linePathsCount: linePathsCount,
160
- lineFeaturesCount: lineFeaturesCount,
161
- polygonPositionsCount: polygonPositionsCount,
162
- polygonObjectsCount: polygonObjectsCount,
163
- polygonRingsCount: polygonRingsCount,
164
- polygonFeaturesCount: polygonFeaturesCount
78
+ coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
79
+ pointPositionsCount,
80
+ pointFeaturesCount,
81
+ linePositionsCount,
82
+ linePathsCount,
83
+ lineFeaturesCount,
84
+ polygonPositionsCount,
85
+ polygonObjectsCount,
86
+ polygonRingsCount,
87
+ polygonFeaturesCount
165
88
  };
166
89
  }
167
90
  //# sourceMappingURL=extract-geometry-info.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract-geometry-info.js","names":["extractGeometryInfo","features","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLengths","Set","_iterator","_createForOfIteratorHelper","_step","s","n","done","feature","value","geometry","type","add","coordinates","length","_iterator2","_step2","point","err","e","f","_iterator3","_step3","coord","_iterator4","_step4","line","_iterator5","_step5","flattened","flat","_iterator6","_step6","_iterator7","_step7","polygon","_iterator8","_step8","Error","concat","coordLength","size","Math","max","apply","_toConsumableArray2","default"],"sources":["../../../src/lib/extract-geometry-info.ts"],"sourcesContent":["import {Feature, GeojsonGeometryInfo} from '@loaders.gl/schema';\n\n/**\n * Initial scan over GeoJSON features\n * Counts number of coordinates of each geometry type and\n * keeps track of the max coordinate dimensions\n */\n// eslint-disable-next-line complexity, max-statements\nexport function extractGeometryInfo(features: Feature[]): GeojsonGeometryInfo {\n // Counts the number of _positions_, so [x, y, z] counts as one\n let pointPositionsCount = 0;\n let pointFeaturesCount = 0;\n let linePositionsCount = 0;\n let linePathsCount = 0;\n let lineFeaturesCount = 0;\n let polygonPositionsCount = 0;\n let polygonObjectsCount = 0;\n let polygonRingsCount = 0;\n let polygonFeaturesCount = 0;\n const coordLengths = new Set<number>();\n\n for (const feature of features) {\n const geometry = feature.geometry;\n switch (geometry.type) {\n case 'Point':\n pointFeaturesCount++;\n pointPositionsCount++;\n coordLengths.add(geometry.coordinates.length);\n break;\n case 'MultiPoint':\n pointFeaturesCount++;\n pointPositionsCount += geometry.coordinates.length;\n for (const point of geometry.coordinates) {\n coordLengths.add(point.length);\n }\n break;\n case 'LineString':\n lineFeaturesCount++;\n linePositionsCount += geometry.coordinates.length;\n linePathsCount++;\n\n for (const coord of geometry.coordinates) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiLineString':\n lineFeaturesCount++;\n for (const line of geometry.coordinates) {\n linePositionsCount += line.length;\n linePathsCount++;\n\n // eslint-disable-next-line max-depth\n for (const coord of line) {\n coordLengths.add(coord.length);\n }\n }\n break;\n case 'Polygon':\n polygonFeaturesCount++;\n polygonObjectsCount++;\n polygonRingsCount += geometry.coordinates.length;\n const flattened = geometry.coordinates.flat();\n polygonPositionsCount += flattened.length;\n\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiPolygon':\n polygonFeaturesCount++;\n for (const polygon of geometry.coordinates) {\n polygonObjectsCount++;\n polygonRingsCount += polygon.length;\n const flattened = polygon.flat();\n polygonPositionsCount += flattened.length;\n\n // eslint-disable-next-line max-depth\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n }\n break;\n default:\n throw new Error(`Unsupported geometry type: ${geometry.type}`);\n }\n }\n\n return {\n coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,\n\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n };\n}\n"],"mappings":";;;;;;;;;;;AAQO,SAASA,mBAAmBA,CAACC,QAAmB,EAAuB;EAE5E,IAAIC,mBAAmB,GAAG,CAAC;EAC3B,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,MAAAgC,MAAA,GAAAD,UAAA,CAAA9B,CAAA,IAAAC,IAAA,GAA+B;kBAAA,IAApBgB,OAAK,GAAAc,MAAA,CAAA5B,KAAA;kBACdT,YAAY,CAACY,GAAG,CAACW,OAAK,CAACT,MAAM,CAAC;gBAChC;cAAC,SAAAI,GAAA;gBAAAkB,UAAA,CAAAjB,CAAA,CAAAD,GAAA;cAAA;gBAAAkB,UAAA,CAAAhB,CAAA;cAAA;YACH;UAAC,SAAAF,GAAA;YAAAe,UAAA,CAAAd,CAAA,CAAAD,GAAA;UAAA;YAAAe,UAAA,CAAAb,CAAA;UAAA;UACD;QACF;UACE,MAAM,IAAIkB,KAAK,+BAAAC,MAAA,CAA+B7B,QAAQ,CAACC,IAAI,CAAE,CAAC;MAClE;IACF;EAAC,SAAAO,GAAA;IAAAhB,SAAA,CAAAiB,CAAA,CAAAD,GAAA;EAAA;IAAAhB,SAAA,CAAAkB,CAAA;EAAA;EAED,OAAO;IACLoB,WAAW,EAAExC,YAAY,CAACyC,IAAI,GAAG,CAAC,GAAGC,IAAI,CAACC,GAAG,CAAAC,KAAA,CAARF,IAAI,MAAAG,mBAAA,CAAAC,OAAA,EAAQ9C,YAAY,EAAC,GAAG,CAAC;IAElET,mBAAmB,EAAnBA,mBAAmB;IACnBC,kBAAkB,EAAlBA,kBAAkB;IAClBC,kBAAkB,EAAlBA,kBAAkB;IAClBC,cAAc,EAAdA,cAAc;IACdC,iBAAiB,EAAjBA,iBAAiB;IACjBC,qBAAqB,EAArBA,qBAAqB;IACrBC,mBAAmB,EAAnBA,mBAAmB;IACnBC,iBAAiB,EAAjBA,iBAAiB;IACjBC,oBAAoB,EAApBA;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"extract-geometry-info.js","names":["extractGeometryInfo","features","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLengths","Set","feature","geometry","type","add","coordinates","length","point","coord","line","flattened","flat","polygon","Error","concat","coordLength","size","Math","max"],"sources":["../../../src/lib/extract-geometry-info.ts"],"sourcesContent":["import {Feature, GeojsonGeometryInfo} from '@loaders.gl/schema';\n\n/**\n * Initial scan over GeoJSON features\n * Counts number of coordinates of each geometry type and\n * keeps track of the max coordinate dimensions\n */\n// eslint-disable-next-line complexity, max-statements\nexport function extractGeometryInfo(features: Feature[]): GeojsonGeometryInfo {\n // Counts the number of _positions_, so [x, y, z] counts as one\n let pointPositionsCount = 0;\n let pointFeaturesCount = 0;\n let linePositionsCount = 0;\n let linePathsCount = 0;\n let lineFeaturesCount = 0;\n let polygonPositionsCount = 0;\n let polygonObjectsCount = 0;\n let polygonRingsCount = 0;\n let polygonFeaturesCount = 0;\n const coordLengths = new Set<number>();\n\n for (const feature of features) {\n const geometry = feature.geometry;\n switch (geometry.type) {\n case 'Point':\n pointFeaturesCount++;\n pointPositionsCount++;\n coordLengths.add(geometry.coordinates.length);\n break;\n case 'MultiPoint':\n pointFeaturesCount++;\n pointPositionsCount += geometry.coordinates.length;\n for (const point of geometry.coordinates) {\n coordLengths.add(point.length);\n }\n break;\n case 'LineString':\n lineFeaturesCount++;\n linePositionsCount += geometry.coordinates.length;\n linePathsCount++;\n\n for (const coord of geometry.coordinates) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiLineString':\n lineFeaturesCount++;\n for (const line of geometry.coordinates) {\n linePositionsCount += line.length;\n linePathsCount++;\n\n // eslint-disable-next-line max-depth\n for (const coord of line) {\n coordLengths.add(coord.length);\n }\n }\n break;\n case 'Polygon':\n polygonFeaturesCount++;\n polygonObjectsCount++;\n polygonRingsCount += geometry.coordinates.length;\n const flattened = geometry.coordinates.flat();\n polygonPositionsCount += flattened.length;\n\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiPolygon':\n polygonFeaturesCount++;\n for (const polygon of geometry.coordinates) {\n polygonObjectsCount++;\n polygonRingsCount += polygon.length;\n const flattened = polygon.flat();\n polygonPositionsCount += flattened.length;\n\n // eslint-disable-next-line max-depth\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n }\n break;\n default:\n throw new Error(`Unsupported geometry type: ${geometry.type}`);\n }\n }\n\n return {\n coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,\n\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n };\n}\n"],"mappings":";;;;;;AAQO,SAASA,mBAAmBA,CAACC,QAAmB,EAAuB;EAE5E,IAAIC,mBAAmB,GAAG,CAAC;EAC3B,IAAIC,kBAAkB,GAAG,CAAC;EAC1B,IAAIC,kBAAkB,GAAG,CAAC;EAC1B,IAAIC,cAAc,GAAG,CAAC;EACtB,IAAIC,iBAAiB,GAAG,CAAC;EACzB,IAAIC,qBAAqB,GAAG,CAAC;EAC7B,IAAIC,mBAAmB,GAAG,CAAC;EAC3B,IAAIC,iBAAiB,GAAG,CAAC;EACzB,IAAIC,oBAAoB,GAAG,CAAC;EAC5B,MAAMC,YAAY,GAAG,IAAIC,GAAG,CAAS,CAAC;EAEtC,KAAK,MAAMC,OAAO,IAAIZ,QAAQ,EAAE;IAC9B,MAAMa,QAAQ,GAAGD,OAAO,CAACC,QAAQ;IACjC,QAAQA,QAAQ,CAACC,IAAI;MACnB,KAAK,OAAO;QACVZ,kBAAkB,EAAE;QACpBD,mBAAmB,EAAE;QACrBS,YAAY,CAACK,GAAG,CAACF,QAAQ,CAACG,WAAW,CAACC,MAAM,CAAC;QAC7C;MACF,KAAK,YAAY;QACff,kBAAkB,EAAE;QACpBD,mBAAmB,IAAIY,QAAQ,CAACG,WAAW,CAACC,MAAM;QAClD,KAAK,MAAMC,KAAK,IAAIL,QAAQ,CAACG,WAAW,EAAE;UACxCN,YAAY,CAACK,GAAG,CAACG,KAAK,CAACD,MAAM,CAAC;QAChC;QACA;MACF,KAAK,Y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