@loaders.gl/gis 3.3.0-alpha.4 → 3.3.0-alpha.6
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.
- package/dist/es5/bundle.js +0 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +12 -17
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/binary-to-geojson.js +5 -62
- package/dist/es5/lib/binary-to-geojson.js.map +1 -1
- package/dist/es5/lib/extract-geometry-info.js +8 -43
- package/dist/es5/lib/extract-geometry-info.js.map +1 -1
- package/dist/es5/lib/flat-geojson-to-binary-types.js.map +1 -1
- package/dist/es5/lib/flat-geojson-to-binary.js +30 -59
- package/dist/es5/lib/flat-geojson-to-binary.js.map +1 -1
- package/dist/es5/lib/geojson-to-binary.js +0 -4
- package/dist/es5/lib/geojson-to-binary.js.map +1 -1
- package/dist/es5/lib/geojson-to-flat-geojson.js +4 -30
- package/dist/es5/lib/geojson-to-flat-geojson.js.map +1 -1
- package/dist/es5/lib/transform.js +1 -15
- package/dist/es5/lib/transform.js.map +1 -1
- package/dist/esm/bundle.js +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/binary-to-geojson.js +17 -49
- package/dist/esm/lib/binary-to-geojson.js.map +1 -1
- package/dist/esm/lib/extract-geometry-info.js +1 -19
- package/dist/esm/lib/extract-geometry-info.js.map +1 -1
- package/dist/esm/lib/flat-geojson-to-binary-types.js.map +1 -1
- package/dist/esm/lib/flat-geojson-to-binary.js +21 -30
- package/dist/esm/lib/flat-geojson-to-binary.js.map +1 -1
- package/dist/esm/lib/geojson-to-binary.js +5 -3
- package/dist/esm/lib/geojson-to-binary.js.map +1 -1
- package/dist/esm/lib/geojson-to-flat-geojson.js +7 -19
- package/dist/esm/lib/geojson-to-flat-geojson.js.map +1 -1
- package/dist/esm/lib/transform.js +1 -8
- package/dist/esm/lib/transform.js.map +1 -1
- package/dist/lib/flat-geojson-to-binary.js +1 -0
- package/package.json +4 -4
- package/src/lib/flat-geojson-to-binary.ts +1 -0
package/dist/es5/bundle.js
CHANGED
package/dist/es5/bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"bundle.js","names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"sources":["../../src/bundle.ts"],"sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"mappings":";;AACA,IAAMA,aAAa,GAAGC,OAAO,CAAC,SAAS,CAAC;AACxCC,UAAU,CAACC,OAAO,GAAGD,UAAU,CAACC,OAAO,IAAI,CAAC,CAAC;AAC7CC,MAAM,CAACC,OAAO,GAAGC,MAAM,CAACC,MAAM,CAACL,UAAU,CAACC,OAAO,EAAEH,aAAa,CAAC"}
|
package/dist/es5/index.js
CHANGED
|
@@ -3,40 +3,40 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "binaryToGeoJson", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function get() {
|
|
9
|
-
return
|
|
9
|
+
return _binaryToGeojson.binaryToGeoJson;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "binaryToGeojson", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function get() {
|
|
15
|
-
return
|
|
15
|
+
return _binaryToGeojson.binaryToGeojson;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "binaryToGeometry", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function get() {
|
|
21
|
-
return
|
|
21
|
+
return _binaryToGeojson.binaryToGeometry;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "flatGeojsonToBinary", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function get() {
|
|
27
|
-
return
|
|
27
|
+
return _flatGeojsonToBinary.flatGeojsonToBinary;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(exports, "
|
|
30
|
+
Object.defineProperty(exports, "geojsonToBinary", {
|
|
31
31
|
enumerable: true,
|
|
32
32
|
get: function get() {
|
|
33
|
-
return
|
|
33
|
+
return _geojsonToBinary.geojsonToBinary;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
Object.defineProperty(exports, "
|
|
36
|
+
Object.defineProperty(exports, "geojsonToFlatGeojson", {
|
|
37
37
|
enumerable: true,
|
|
38
38
|
get: function get() {
|
|
39
|
-
return
|
|
39
|
+
return _geojsonToFlatGeojson.geojsonToFlatGeojson;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
Object.defineProperty(exports, "transformBinaryCoords", {
|
|
@@ -51,14 +51,9 @@ Object.defineProperty(exports, "transformGeoJsonCoords", {
|
|
|
51
51
|
return _transform.transformGeoJsonCoords;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
-
|
|
55
54
|
var _flatGeojsonToBinary = require("./lib/flat-geojson-to-binary");
|
|
56
|
-
|
|
57
55
|
var _geojsonToBinary = require("./lib/geojson-to-binary");
|
|
58
|
-
|
|
59
56
|
var _geojsonToFlatGeojson = require("./lib/geojson-to-flat-geojson");
|
|
60
|
-
|
|
61
57
|
var _binaryToGeojson = require("./lib/binary-to-geojson");
|
|
62
|
-
|
|
63
58
|
var _transform = require("./lib/transform");
|
|
64
59
|
//# sourceMappingURL=index.js.map
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["// Types from `@loaders.gl/schema`\n\n// Functions\nexport {flatGeojsonToBinary} from './lib/flat-geojson-to-binary';\nexport {geojsonToBinary} from './lib/geojson-to-binary';\nexport {geojsonToFlatGeojson} from './lib/geojson-to-flat-geojson';\nexport {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,46 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.binaryToGeojson = binaryToGeojson;
|
|
9
7
|
exports.binaryToGeoJson = binaryToGeoJson;
|
|
8
|
+
exports.binaryToGeojson = binaryToGeojson;
|
|
10
9
|
exports.binaryToGeometry = binaryToGeometry;
|
|
11
|
-
|
|
12
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
17
|
-
|
|
11
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
18
13
|
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; } } }; }
|
|
19
|
-
|
|
20
14
|
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); }
|
|
21
|
-
|
|
22
15
|
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; }
|
|
23
16
|
|
|
24
17
|
function binaryToGeojson(data, options) {
|
|
25
18
|
var globalFeatureId = options === null || options === void 0 ? void 0 : options.globalFeatureId;
|
|
26
|
-
|
|
27
19
|
if (globalFeatureId !== undefined) {
|
|
28
20
|
return getSingleFeature(data, globalFeatureId);
|
|
29
21
|
}
|
|
30
|
-
|
|
31
22
|
return parseFeatures(data, options === null || options === void 0 ? void 0 : options.type);
|
|
32
23
|
}
|
|
33
24
|
|
|
34
25
|
function binaryToGeoJson(data, type) {
|
|
35
26
|
var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'feature';
|
|
36
|
-
|
|
37
27
|
switch (format) {
|
|
38
28
|
case 'feature':
|
|
39
29
|
return parseFeatures(data, type);
|
|
40
|
-
|
|
41
30
|
case 'geometry':
|
|
42
31
|
return binaryToGeometry(data);
|
|
43
|
-
|
|
44
32
|
default:
|
|
45
33
|
throw new Error(format);
|
|
46
34
|
}
|
|
@@ -48,10 +36,8 @@ function binaryToGeoJson(data, type) {
|
|
|
48
36
|
|
|
49
37
|
function getSingleFeature(data, globalFeatureId) {
|
|
50
38
|
var dataArray = normalizeInput(data);
|
|
51
|
-
|
|
52
39
|
var _iterator = _createForOfIteratorHelper(dataArray),
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
_step;
|
|
55
41
|
try {
|
|
56
42
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
57
43
|
var _data = _step.value;
|
|
@@ -60,19 +46,15 @@ function getSingleFeature(data, globalFeatureId) {
|
|
|
60
46
|
|
|
61
47
|
for (var i = 0; i < _data.featureIds.value.length; i++) {
|
|
62
48
|
var currValue = _data.featureIds.value[i];
|
|
63
|
-
|
|
64
49
|
if (currValue === lastValue) {
|
|
65
50
|
continue;
|
|
66
51
|
}
|
|
67
|
-
|
|
68
52
|
if (globalFeatureId === _data.globalFeatureIds.value[lastIndex]) {
|
|
69
53
|
return parseFeature(_data, lastIndex, i);
|
|
70
54
|
}
|
|
71
|
-
|
|
72
55
|
lastIndex = i;
|
|
73
56
|
lastValue = currValue;
|
|
74
57
|
}
|
|
75
|
-
|
|
76
58
|
if (globalFeatureId === _data.globalFeatureIds.value[lastIndex]) {
|
|
77
59
|
return parseFeature(_data, lastIndex, _data.featureIds.value.length);
|
|
78
60
|
}
|
|
@@ -82,10 +64,8 @@ function getSingleFeature(data, globalFeatureId) {
|
|
|
82
64
|
} finally {
|
|
83
65
|
_iterator.f();
|
|
84
66
|
}
|
|
85
|
-
|
|
86
67
|
throw new Error("featureId:".concat(globalFeatureId, " not found"));
|
|
87
68
|
}
|
|
88
|
-
|
|
89
69
|
function parseFeatures(data, type) {
|
|
90
70
|
var dataArray = normalizeInput(data, type);
|
|
91
71
|
return parseFeatureCollection(dataArray);
|
|
@@ -95,71 +75,55 @@ function binaryToGeometry(data, startIndex, endIndex) {
|
|
|
95
75
|
switch (data.type) {
|
|
96
76
|
case 'Point':
|
|
97
77
|
return pointToGeoJson(data, startIndex, endIndex);
|
|
98
|
-
|
|
99
78
|
case 'LineString':
|
|
100
79
|
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
101
|
-
|
|
102
80
|
case 'Polygon':
|
|
103
81
|
return polygonToGeoJson(data, startIndex, endIndex);
|
|
104
|
-
|
|
105
82
|
default:
|
|
106
83
|
var unexpectedInput = data;
|
|
107
84
|
throw new Error("Unsupported geometry type: ".concat(unexpectedInput === null || unexpectedInput === void 0 ? void 0 : unexpectedInput.type));
|
|
108
85
|
}
|
|
109
86
|
}
|
|
110
|
-
|
|
111
87
|
function normalizeInput(data, type) {
|
|
112
88
|
var isHeterogeneousType = Boolean(data.points || data.lines || data.polygons);
|
|
113
|
-
|
|
114
89
|
if (!isHeterogeneousType) {
|
|
115
90
|
data.type = type || parseType(data);
|
|
116
91
|
return [data];
|
|
117
92
|
}
|
|
118
|
-
|
|
119
93
|
var features = [];
|
|
120
|
-
|
|
121
94
|
if (data.points) {
|
|
122
95
|
data.points.type = 'Point';
|
|
123
96
|
features.push(data.points);
|
|
124
97
|
}
|
|
125
|
-
|
|
126
98
|
if (data.lines) {
|
|
127
99
|
data.lines.type = 'LineString';
|
|
128
100
|
features.push(data.lines);
|
|
129
101
|
}
|
|
130
|
-
|
|
131
102
|
if (data.polygons) {
|
|
132
103
|
data.polygons.type = 'Polygon';
|
|
133
104
|
features.push(data.polygons);
|
|
134
105
|
}
|
|
135
|
-
|
|
136
106
|
return features;
|
|
137
107
|
}
|
|
138
108
|
|
|
139
109
|
function parseFeatureCollection(dataArray) {
|
|
140
110
|
var features = [];
|
|
141
|
-
|
|
142
111
|
var _iterator2 = _createForOfIteratorHelper(dataArray),
|
|
143
|
-
|
|
144
|
-
|
|
112
|
+
_step2;
|
|
145
113
|
try {
|
|
146
114
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
147
115
|
var data = _step2.value;
|
|
148
|
-
|
|
149
116
|
if (data.featureIds.value.length === 0) {
|
|
150
117
|
continue;
|
|
151
118
|
}
|
|
152
|
-
|
|
153
119
|
var lastIndex = 0;
|
|
154
120
|
var lastValue = data.featureIds.value[0];
|
|
155
121
|
|
|
156
122
|
for (var i = 0; i < data.featureIds.value.length; i++) {
|
|
157
123
|
var currValue = data.featureIds.value[i];
|
|
158
|
-
|
|
159
124
|
if (currValue === lastValue) {
|
|
160
125
|
continue;
|
|
161
126
|
}
|
|
162
|
-
|
|
163
127
|
features.push(parseFeature(data, lastIndex, i));
|
|
164
128
|
lastIndex = i;
|
|
165
129
|
lastValue = currValue;
|
|
@@ -172,7 +136,6 @@ function parseFeatureCollection(dataArray) {
|
|
|
172
136
|
} finally {
|
|
173
137
|
_iterator2.f();
|
|
174
138
|
}
|
|
175
|
-
|
|
176
139
|
return features;
|
|
177
140
|
}
|
|
178
141
|
|
|
@@ -197,11 +160,9 @@ function parseProperties(data) {
|
|
|
197
160
|
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
198
161
|
var endIndex = arguments.length > 2 ? arguments[2] : undefined;
|
|
199
162
|
var properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);
|
|
200
|
-
|
|
201
163
|
for (var key in data.numericProps) {
|
|
202
164
|
properties[key] = data.numericProps[key].value[startIndex];
|
|
203
165
|
}
|
|
204
|
-
|
|
205
166
|
return properties;
|
|
206
167
|
}
|
|
207
168
|
|
|
@@ -219,15 +180,12 @@ function polygonToGeoJson(data) {
|
|
|
219
180
|
|
|
220
181
|
if (!multi) {
|
|
221
182
|
var _coordinates = [];
|
|
222
|
-
|
|
223
183
|
for (var i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
224
184
|
var startRingIndex = primitivePolygonIndices[i];
|
|
225
185
|
var endRingIndex = primitivePolygonIndices[i + 1];
|
|
226
186
|
var ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
227
|
-
|
|
228
187
|
_coordinates.push(ringCoordinates);
|
|
229
188
|
}
|
|
230
|
-
|
|
231
189
|
return {
|
|
232
190
|
type: 'Polygon',
|
|
233
191
|
coordinates: _coordinates
|
|
@@ -235,14 +193,12 @@ function polygonToGeoJson(data) {
|
|
|
235
193
|
}
|
|
236
194
|
|
|
237
195
|
var coordinates = [];
|
|
238
|
-
|
|
239
196
|
for (var _i = 0; _i < polygonIndices.length - 1; _i++) {
|
|
240
197
|
var startPolygonIndex = polygonIndices[_i];
|
|
241
198
|
var endPolygonIndex = polygonIndices[_i + 1];
|
|
242
199
|
var polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
243
200
|
coordinates.push(polygonCoordinates);
|
|
244
201
|
}
|
|
245
|
-
|
|
246
202
|
return {
|
|
247
203
|
type: 'MultiPolygon',
|
|
248
204
|
coordinates: coordinates
|
|
@@ -257,23 +213,18 @@ function lineStringToGeoJson(data) {
|
|
|
257
213
|
return x >= startIndex && x <= endIndex;
|
|
258
214
|
});
|
|
259
215
|
var multi = pathIndices.length > 2;
|
|
260
|
-
|
|
261
216
|
if (!multi) {
|
|
262
217
|
var _coordinates2 = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
263
|
-
|
|
264
218
|
return {
|
|
265
219
|
type: 'LineString',
|
|
266
220
|
coordinates: _coordinates2
|
|
267
221
|
};
|
|
268
222
|
}
|
|
269
|
-
|
|
270
223
|
var coordinates = [];
|
|
271
|
-
|
|
272
224
|
for (var i = 0; i < pathIndices.length - 1; i++) {
|
|
273
225
|
var ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
274
226
|
coordinates.push(ringCoordinates);
|
|
275
227
|
}
|
|
276
|
-
|
|
277
228
|
return {
|
|
278
229
|
type: 'MultiLineString',
|
|
279
230
|
coordinates: coordinates
|
|
@@ -284,14 +235,12 @@ function pointToGeoJson(data, startIndex, endIndex) {
|
|
|
284
235
|
var positions = data.positions;
|
|
285
236
|
var coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
286
237
|
var multi = coordinates.length > 1;
|
|
287
|
-
|
|
288
238
|
if (multi) {
|
|
289
239
|
return {
|
|
290
240
|
type: 'MultiPoint',
|
|
291
241
|
coordinates: coordinates
|
|
292
242
|
};
|
|
293
243
|
}
|
|
294
|
-
|
|
295
244
|
return {
|
|
296
245
|
type: 'Point',
|
|
297
246
|
coordinates: coordinates[0]
|
|
@@ -302,17 +251,13 @@ function ringToGeoJson(positions, startIndex, endIndex) {
|
|
|
302
251
|
startIndex = startIndex || 0;
|
|
303
252
|
endIndex = endIndex || positions.value.length / positions.size;
|
|
304
253
|
var ringCoordinates = [];
|
|
305
|
-
|
|
306
254
|
for (var j = startIndex; j < endIndex; j++) {
|
|
307
255
|
var coord = Array();
|
|
308
|
-
|
|
309
256
|
for (var k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
310
257
|
coord.push(Number(positions.value[k]));
|
|
311
258
|
}
|
|
312
|
-
|
|
313
259
|
ringCoordinates.push(coord);
|
|
314
260
|
}
|
|
315
|
-
|
|
316
261
|
return ringCoordinates;
|
|
317
262
|
}
|
|
318
263
|
|
|
@@ -320,11 +265,9 @@ function parseType(data) {
|
|
|
320
265
|
if (data.pathIndices) {
|
|
321
266
|
return 'LineString';
|
|
322
267
|
}
|
|
323
|
-
|
|
324
268
|
if (data.polygonIndices) {
|
|
325
269
|
return 'Polygon';
|
|
326
270
|
}
|
|
327
|
-
|
|
328
271
|
return 'Point';
|
|
329
272
|
}
|
|
330
273
|
//# sourceMappingURL=binary-to-geojson.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/binary-to-geojson.ts"],"names":["binaryToGeojson","data","options","globalFeatureId","undefined","getSingleFeature","parseFeatures","type","binaryToGeoJson","format","binaryToGeometry","Error","dataArray","normalizeInput","lastIndex","lastValue","featureIds","value","i","length","currValue","globalFeatureIds","parseFeature","parseFeatureCollection","startIndex","endIndex","pointToGeoJson","lineStringToGeoJson","polygonToGeoJson","unexpectedInput","isHeterogeneousType","Boolean","points","lines","polygons","parseType","features","push","geometry","properties","parseProperties","fields","parseFields","Object","assign","key","numericProps","Infinity","positions","polygonIndices","filter","x","primitivePolygonIndices","multi","coordinates","startRingIndex","endRingIndex","ringCoordinates","ringToGeoJson","startPolygonIndex","endPolygonIndex","polygonCoordinates","pathIndices","size","j","coord","Array","k","Number"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmCO,SAASA,eAAT,CACLC,IADK,EAELC,OAFK,EAGgB;AACrB,MAAMC,eAAe,GAAGD,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEC,eAAjC;;AACA,MAAIA,eAAe,KAAKC,SAAxB,EAAmC;AACjC,WAAOC,gBAAgB,CAACJ,IAAD,EAAOE,eAAP,CAAvB;AACD;;AACD,SAAOG,aAAa,CAACL,IAAD,EAAOC,OAAP,aAAOA,OAAP,uBAAOA,OAAO,CAAEK,IAAhB,CAApB;AACD;;AAGM,SA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AA3B;AACAC,EAAAA,QAAQ,GAAGA,QAAQ,IAAIuB,SAAS,CAAC/B,KAAV,CAAgBE,MAAhB,GAAyB6B,SAAS,CAACe,IAA1D;AAEA,MAAMN,eAA2B,GAAG,EAApC;;AACA,OAAK,IAAIO,CAAC,GAAGxC,UAAb,EAAyBwC,CAAC,GAAGvC,QAA7B,EAAuCuC,CAAC,EAAxC,EAA4C;AAC1C,QAAMC,KAAK,GAAGC,KAAK,EAAnB;;AACA,SAAK,IAAIC,CAAC,GAAGH,CAAC,GAAGhB,SAAS,CAACe,IAA3B,EAAiCI,CAAC,GAAG,CAACH,CAAC,GAAG,CAAL,IAAUhB,SAAS,CAACe,IAAzD,EAA+DI,CAAC,EAAhE,EAAoE;AAClEF,MAAAA,KAAK,CAAC5B,IAAN,CAAW+B,MAAM,CAACpB,SAAS,CAAC/B,KAAV,CAAgBkD,CAAhB,CAAD,CAAjB;AACD;;AACDV,IAAAA,eAAe,CAACpB,IAAhB,CAAqB4B,KAArB;AACD;;AACD,SAAOR,eAAP;AACD;;AAGD,SAAStB,SAAT,CAAmBlC,IAAnB,EAAyB;AACvB,MAAIA,IAAI,CAAC6D,WAAT,EAAsB;AACpB,WAAO,YAAP;AACD;;AAED,MAAI7D,IAAI,CAACgD,cAAT,EAAyB;AACvB,WAAO,SAAP;AACD;;AAED,SAAO,OAAP;AACD","sourcesContent":["import type {\n BinaryGeometry,\n BinaryFeatures,\n BinaryGeometryType,\n BinaryPointFeatures,\n BinaryLineFeatures,\n BinaryPolygonFeatures,\n BinaryAttribute\n} from '@loaders.gl/schema';\nimport type {Feature, Geometry, Position, GeoJsonProperties} from '@loaders.gl/schema';\nimport type {\n Point,\n MultiPoint,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon\n} from '@loaders.gl/schema';\n\n// Note:L We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.\n// type FeatureGeometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;\n\ntype BinaryToGeoJsonOptions = {\n type?: BinaryGeometryType;\n globalFeatureId?: number;\n};\n\n/**\n * Convert binary geometry representation to GeoJSON\n * @param data geometry data in binary representation\n * @param options\n * @param options.type Input data type: Point, LineString, or Polygon\n * @param options.featureId Global feature id. If specified, only a single feature is extracted\n * @return GeoJSON objects\n */\nexport function binaryToGeojson(\n data: BinaryFeatures,\n options?: BinaryToGeoJsonOptions\n): Feature[] | Feature {\n const globalFeatureId = options?.globalFeatureId;\n if (globalFeatureId !== undefined) {\n return getSingleFeature(data, globalFeatureId);\n }\n return parseFeatures(data, options?.type);\n}\n\n/** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead */\nexport function binaryToGeoJson(\n data: BinaryGeometry | BinaryFeatures,\n type?: BinaryGeometryType,\n format: 'feature' | 'geometry' = 'feature'\n): Geometry | Feature[] {\n switch (format) {\n case 'feature':\n return parseFeatures(data as BinaryFeatures, type);\n case 'geometry':\n return binaryToGeometry(data as BinaryGeometry);\n default:\n throw new Error(format);\n }\n}\n\n/**\n * Return a single feature from a binary geometry representation as GeoJSON\n * @param data geometry data in binary representation\n * @return GeoJSON feature\n */\nfunction getSingleFeature(data: BinaryFeatures, globalFeatureId: number): Feature {\n const dataArray = normalizeInput(data);\n for (const data of dataArray) {\n let lastIndex = 0;\n let lastValue = data.featureIds.value[0];\n\n // Scan through data until we find matching feature\n for (let i = 0; i < data.featureIds.value.length; i++) {\n const currValue = data.featureIds.value[i];\n if (currValue === lastValue) {\n // eslint-disable-next-line no-continue\n continue;\n }\n if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {\n return parseFeature(data, lastIndex, i);\n }\n lastIndex = i;\n lastValue = currValue;\n }\n\n if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {\n return parseFeature(data, lastIndex, data.featureIds.value.length);\n }\n }\n\n throw new Error(`featureId:${globalFeatureId} not found`);\n}\n\nfunction parseFeatures(data: BinaryFeatures, type?: BinaryGeometryType): Feature[] {\n const dataArray = normalizeInput(data, type);\n return parseFeatureCollection(dataArray);\n}\n\n/** Parse input binary data and return a valid GeoJSON geometry object */\nexport function binaryToGeometry(\n data: BinaryGeometry,\n startIndex?: number,\n endIndex?: number\n): Geometry {\n switch (data.type) {\n case 'Point':\n return pointToGeoJson(data, startIndex, endIndex);\n case 'LineString':\n return lineStringToGeoJson(data, startIndex, endIndex);\n case 'Polygon':\n return polygonToGeoJson(data, startIndex, endIndex);\n default:\n const unexpectedInput: never = data;\n throw new Error(`Unsupported geometry type: ${(unexpectedInput as any)?.type}`);\n }\n}\n\ntype BinaryFeature = BinaryPointFeatures | BinaryLineFeatures | BinaryPolygonFeatures;\ntype BinaryFeaturesArray = BinaryFeature[];\n\n// Normalize features\n// Return an array of data objects, each of which have a type key\nfunction normalizeInput(data: BinaryFeatures, type?: BinaryGeometryType): BinaryFeaturesArray {\n const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons);\n\n if (!isHeterogeneousType) {\n // @ts-expect-error This is a legacy check which allowed `data` to be an instance of the values\n // here. Aka the new data.points, data.lines, or data.polygons.\n data.type = type || parseType(data);\n return [data] as BinaryFeaturesArray;\n }\n\n const features: BinaryFeaturesArray = [];\n if (data.points) {\n data.points.type = 'Point';\n features.push(data.points);\n }\n if (data.lines) {\n data.lines.type = 'LineString';\n features.push(data.lines);\n }\n if (data.polygons) {\n data.polygons.type = 'Polygon';\n features.push(data.polygons);\n }\n\n return features;\n}\n\n/** Parse input binary data and return an array of GeoJSON Features */\nfunction parseFeatureCollection(dataArray): Feature[] {\n const features: Feature[] = [];\n for (const data of dataArray) {\n if (data.featureIds.value.length === 0) {\n // eslint-disable-next-line no-continue\n continue;\n }\n let lastIndex = 0;\n let lastValue = data.featureIds.value[0];\n\n // Need to deduce start, end indices of each feature\n for (let i = 0; i < data.featureIds.value.length; i++) {\n const currValue = data.featureIds.value[i];\n if (currValue === lastValue) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n features.push(parseFeature(data, lastIndex, i));\n lastIndex = i;\n lastValue = currValue;\n }\n\n // Last feature\n features.push(parseFeature(data, lastIndex, data.featureIds.value.length));\n }\n return features;\n}\n\n/** Parse input binary data and return a single GeoJSON Feature */\nfunction parseFeature(data, startIndex?: number, endIndex?: number): Feature {\n const geometry = binaryToGeometry(data, startIndex, endIndex);\n const properties = parseProperties(data, startIndex, endIndex);\n const fields = parseFields(data, startIndex, endIndex);\n return {type: 'Feature', geometry, properties, ...fields};\n}\n\n/** Parse input binary data and return an object of fields */\nfunction parseFields(data, startIndex: number = 0, endIndex?: number): GeoJsonProperties {\n return data.fields && data.fields[data.featureIds.value[startIndex]];\n}\n\n/** Parse input binary data and return an object of properties */\nfunction parseProperties(data, startIndex: number = 0, endIndex?: number): GeoJsonProperties {\n const properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);\n for (const key in data.numericProps) {\n properties[key] = data.numericProps[key].value[startIndex];\n }\n return properties;\n}\n\n/** Parse binary data of type Polygon */\nfunction polygonToGeoJson(\n data,\n startIndex: number = -Infinity,\n endIndex: number = Infinity\n): Polygon | MultiPolygon {\n const {positions} = data;\n const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);\n const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(\n (x) => x >= startIndex && x <= endIndex\n );\n const multi = polygonIndices.length > 2;\n\n // Polygon\n if (!multi) {\n const coordinates: Position[][] = [];\n for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {\n const startRingIndex = primitivePolygonIndices[i];\n const endRingIndex = primitivePolygonIndices[i + 1];\n const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);\n coordinates.push(ringCoordinates);\n }\n\n return {type: 'Polygon', coordinates};\n }\n\n // MultiPolygon\n const coordinates: Position[][][] = [];\n for (let i = 0; i < polygonIndices.length - 1; i++) {\n const startPolygonIndex = polygonIndices[i];\n const endPolygonIndex = polygonIndices[i + 1];\n const polygonCoordinates = polygonToGeoJson(\n data,\n startPolygonIndex,\n endPolygonIndex\n ).coordinates;\n coordinates.push(polygonCoordinates as Position[][]);\n }\n\n return {type: 'MultiPolygon', coordinates};\n}\n\n/** Parse binary data of type LineString */\nfunction lineStringToGeoJson(\n data,\n startIndex: number = -Infinity,\n endIndex: number = Infinity\n): LineString | MultiLineString {\n const {positions} = data;\n const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);\n const multi = pathIndices.length > 2;\n\n if (!multi) {\n const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);\n return {type: 'LineString', coordinates};\n }\n\n const coordinates: Position[][] = [];\n for (let i = 0; i < pathIndices.length - 1; i++) {\n const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);\n coordinates.push(ringCoordinates);\n }\n\n return {type: 'MultiLineString', coordinates};\n}\n\n/** Parse binary data of type Point */\nfunction pointToGeoJson(data, startIndex, endIndex): Point | MultiPoint {\n const {positions} = data;\n const coordinates = ringToGeoJson(positions, startIndex, endIndex);\n const multi = coordinates.length > 1;\n\n if (multi) {\n return {type: 'MultiPoint', coordinates};\n }\n\n return {type: 'Point', coordinates: coordinates[0]};\n}\n\n/**\n * Parse a linear ring of positions to a GeoJSON linear ring\n *\n * @param positions Positions TypedArray\n * @param startIndex Start index to include in ring\n * @param endIndex End index to include in ring\n * @returns GeoJSON ring\n */\nfunction ringToGeoJson(\n positions: BinaryAttribute,\n startIndex?: number,\n endIndex?: number\n): Position[] {\n startIndex = startIndex || 0;\n endIndex = endIndex || positions.value.length / positions.size;\n\n const ringCoordinates: Position[] = [];\n for (let j = startIndex; j < endIndex; j++) {\n const coord = Array<number>();\n for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {\n coord.push(Number(positions.value[k]));\n }\n ringCoordinates.push(coord);\n }\n return ringCoordinates;\n}\n\n// Deduce geometry type of data object\nfunction parseType(data) {\n if (data.pathIndices) {\n return 'LineString';\n }\n\n if (data.polygonIndices) {\n return 'Polygon';\n }\n\n return 'Point';\n}\n"],"file":"binary-to-geojson.js"}
|
|
1
|
+
{"version":3,"file":"binary-to-geojson.js","names":["binaryToGeojson","data","options","globalFeatureId","undefined","getSingleFeature","parseFeatures","type","binaryToGeoJson","format","binaryToGeometry","Error","dataArray","normalizeInput","lastIndex","lastValue","featureIds","value","i","length","currValue","globalFeatureIds","parseFeature","parseFeatureCollection","startIndex","endIndex","pointToGeoJson","lineStringToGeoJson","polygonToGeoJson","unexpectedInput","isHeterogeneousType","Boolean","points","lines","polygons","parseType","features","push","geometry","properties","parseProperties","fields","parseFields","Object","assign","key","numericProps","Infinity","positions","polygonIndices","filter","x","primitivePolygonIndices","multi","coordinates","startRingIndex","endRingIndex","ringCoordinates","ringToGeoJson","startPolygonIndex","endPolygonIndex","polygonCoordinates","pathIndices","size","j","coord","Array","k","Number"],"sources":["../../../src/lib/binary-to-geojson.ts"],"sourcesContent":["import type {\n BinaryGeometry,\n BinaryFeatures,\n BinaryGeometryType,\n BinaryPointFeatures,\n BinaryLineFeatures,\n BinaryPolygonFeatures,\n BinaryAttribute\n} from '@loaders.gl/schema';\nimport type {Feature, Geometry, Position, GeoJsonProperties} from '@loaders.gl/schema';\nimport type {\n Point,\n MultiPoint,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon\n} from '@loaders.gl/schema';\n\n// Note:L We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.\n// type FeatureGeometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;\n\ntype BinaryToGeoJsonOptions = {\n type?: BinaryGeometryType;\n globalFeatureId?: number;\n};\n\n/**\n * Convert binary geometry representation to GeoJSON\n * @param data geometry data in binary representation\n * @param options\n * @param options.type Input data type: Point, LineString, or Polygon\n * @param options.featureId Global feature id. If specified, only a single feature is extracted\n * @return GeoJSON objects\n */\nexport function binaryToGeojson(\n data: BinaryFeatures,\n options?: BinaryToGeoJsonOptions\n): Feature[] | Feature {\n const globalFeatureId = options?.globalFeatureId;\n if (globalFeatureId !== undefined) {\n return getSingleFeature(data, globalFeatureId);\n }\n return parseFeatures(data, options?.type);\n}\n\n/** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead */\nexport function binaryToGeoJson(\n data: BinaryGeometry | BinaryFeatures,\n type?: BinaryGeometryType,\n format: 'feature' | 'geometry' = 'feature'\n): Geometry | Feature[] {\n switch (format) {\n case 'feature':\n return parseFeatures(data as BinaryFeatures, type);\n case 'geometry':\n return binaryToGeometry(data as BinaryGeometry);\n default:\n throw new Error(format);\n }\n}\n\n/**\n * Return a single feature from a binary geometry representation as GeoJSON\n * @param data geometry data in binary representation\n * @return GeoJSON feature\n */\nfunction getSingleFeature(data: BinaryFeatures, globalFeatureId: number): Feature {\n const dataArray = normalizeInput(data);\n for (const data of dataArray) {\n let lastIndex = 0;\n let lastValue = data.featureIds.value[0];\n\n // Scan through data until we find matching feature\n for (let i = 0; i < data.featureIds.value.length; i++) {\n const currValue = data.featureIds.value[i];\n if (currValue === lastValue) {\n // eslint-disable-next-line no-continue\n continue;\n }\n if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {\n return parseFeature(data, lastIndex, i);\n }\n lastIndex = i;\n lastValue = currValue;\n }\n\n if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {\n return parseFeature(data, lastIndex, data.featureIds.value.length);\n }\n }\n\n throw new Error(`featureId:${globalFeatureId} not found`);\n}\n\nfunction parseFeatures(data: BinaryFeatures, type?: BinaryGeometryType): Feature[] {\n const dataArray = normalizeInput(data, type);\n return parseFeatureCollection(dataArray);\n}\n\n/** Parse input binary data and return a valid GeoJSON geometry object */\nexport function binaryToGeometry(\n data: BinaryGeometry,\n startIndex?: number,\n endIndex?: number\n): Geometry {\n switch (data.type) {\n case 'Point':\n return pointToGeoJson(data, startIndex, endIndex);\n case 'LineString':\n return lineStringToGeoJson(data, startIndex, endIndex);\n case 'Polygon':\n return polygonToGeoJson(data, startIndex, endIndex);\n default:\n const unexpectedInput: never = data;\n throw new Error(`Unsupported geometry type: ${(unexpectedInput as any)?.type}`);\n }\n}\n\ntype BinaryFeature = BinaryPointFeatures | BinaryLineFeatures | BinaryPolygonFeatures;\ntype BinaryFeaturesArray = BinaryFeature[];\n\n// Normalize features\n// Return an array of data objects, each of which have a type key\nfunction normalizeInput(data: BinaryFeatures, type?: BinaryGeometryType): BinaryFeaturesArray {\n const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons);\n\n if (!isHeterogeneousType) {\n // @ts-expect-error This is a legacy check which allowed `data` to be an instance of the values\n // here. Aka the new data.points, data.lines, or data.polygons.\n data.type = type || parseType(data);\n return [data] as BinaryFeaturesArray;\n }\n\n const features: BinaryFeaturesArray = [];\n if (data.points) {\n data.points.type = 'Point';\n features.push(data.points);\n }\n if (data.lines) {\n data.lines.type = 'LineString';\n features.push(data.lines);\n }\n if (data.polygons) {\n data.polygons.type = 'Polygon';\n features.push(data.polygons);\n }\n\n return features;\n}\n\n/** Parse input binary data and return an array of GeoJSON Features */\nfunction parseFeatureCollection(dataArray): Feature[] {\n const features: Feature[] = [];\n for (const data of dataArray) {\n if (data.featureIds.value.length === 0) {\n // eslint-disable-next-line no-continue\n continue;\n }\n let lastIndex = 0;\n let lastValue = data.featureIds.value[0];\n\n // Need to deduce start, end indices of each feature\n for (let i = 0; i < data.featureIds.value.length; i++) {\n const currValue = data.featureIds.value[i];\n if (currValue === lastValue) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n features.push(parseFeature(data, lastIndex, i));\n lastIndex = i;\n lastValue = currValue;\n }\n\n // Last feature\n features.push(parseFeature(data, lastIndex, data.featureIds.value.length));\n }\n return features;\n}\n\n/** Parse input binary data and return a single GeoJSON Feature */\nfunction parseFeature(data, startIndex?: number, endIndex?: number): Feature {\n const geometry = binaryToGeometry(data, startIndex, endIndex);\n const properties = parseProperties(data, startIndex, endIndex);\n const fields = parseFields(data, startIndex, endIndex);\n return {type: 'Feature', geometry, properties, ...fields};\n}\n\n/** Parse input binary data and return an object of fields */\nfunction parseFields(data, startIndex: number = 0, endIndex?: number): GeoJsonProperties {\n return data.fields && data.fields[data.featureIds.value[startIndex]];\n}\n\n/** Parse input binary data and return an object of properties */\nfunction parseProperties(data, startIndex: number = 0, endIndex?: number): GeoJsonProperties {\n const properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);\n for (const key in data.numericProps) {\n properties[key] = data.numericProps[key].value[startIndex];\n }\n return properties;\n}\n\n/** Parse binary data of type Polygon */\nfunction polygonToGeoJson(\n data,\n startIndex: number = -Infinity,\n endIndex: number = Infinity\n): Polygon | MultiPolygon {\n const {positions} = data;\n const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);\n const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(\n (x) => x >= startIndex && x <= endIndex\n );\n const multi = polygonIndices.length > 2;\n\n // Polygon\n if (!multi) {\n const coordinates: Position[][] = [];\n for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {\n const startRingIndex = primitivePolygonIndices[i];\n const endRingIndex = primitivePolygonIndices[i + 1];\n const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);\n coordinates.push(ringCoordinates);\n }\n\n return {type: 'Polygon', coordinates};\n }\n\n // MultiPolygon\n const coordinates: Position[][][] = [];\n for (let i = 0; i < polygonIndices.length - 1; i++) {\n const startPolygonIndex = polygonIndices[i];\n const endPolygonIndex = polygonIndices[i + 1];\n const polygonCoordinates = polygonToGeoJson(\n data,\n startPolygonIndex,\n endPolygonIndex\n ).coordinates;\n coordinates.push(polygonCoordinates as Position[][]);\n }\n\n return {type: 'MultiPolygon', coordinates};\n}\n\n/** Parse binary data of type LineString */\nfunction lineStringToGeoJson(\n data,\n startIndex: number = -Infinity,\n endIndex: number = Infinity\n): LineString | MultiLineString {\n const {positions} = data;\n const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);\n const multi = pathIndices.length > 2;\n\n if (!multi) {\n const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);\n return {type: 'LineString', coordinates};\n }\n\n const coordinates: Position[][] = [];\n for (let i = 0; i < pathIndices.length - 1; i++) {\n const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);\n coordinates.push(ringCoordinates);\n }\n\n return {type: 'MultiLineString', coordinates};\n}\n\n/** Parse binary data of type Point */\nfunction pointToGeoJson(data, startIndex, endIndex): Point | MultiPoint {\n const {positions} = data;\n const coordinates = ringToGeoJson(positions, startIndex, endIndex);\n const multi = coordinates.length > 1;\n\n if (multi) {\n return {type: 'MultiPoint', coordinates};\n }\n\n return {type: 'Point', coordinates: coordinates[0]};\n}\n\n/**\n * Parse a linear ring of positions to a GeoJSON linear ring\n *\n * @param positions Positions TypedArray\n * @param startIndex Start index to include in ring\n * @param endIndex End index to include in ring\n * @returns GeoJSON ring\n */\nfunction ringToGeoJson(\n positions: BinaryAttribute,\n startIndex?: number,\n endIndex?: number\n): Position[] {\n startIndex = startIndex || 0;\n endIndex = endIndex || positions.value.length / positions.size;\n\n const ringCoordinates: Position[] = [];\n for (let j = startIndex; j < endIndex; j++) {\n const coord = Array<number>();\n for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {\n coord.push(Number(positions.value[k]));\n }\n ringCoordinates.push(coord);\n }\n return ringCoordinates;\n}\n\n// Deduce geometry type of data object\nfunction parseType(data) {\n if (data.pathIndices) {\n return 'LineString';\n }\n\n if (data.polygonIndices) {\n return 'Polygon';\n }\n\n return 'Point';\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmCO,SAASA,eAAe,CAC7BC,IAAoB,EACpBC,OAAgC,EACX;EACrB,IAAMC,eAAe,GAAGD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,eAAe;EAChD,IAAIA,eAAe,KAAKC,SAAS,EAAE;IACjC,OAAOC,gBAAgB,CAACJ,IAAI,EAAEE,eAAe,CAAC;EAChD;EACA,OAAOG,aAAa,CAACL,IAAI,EAAEC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEK,IAAI,CAAC;AAC3C;;AAGO,SAASC,eAAe,CAC7BP,IAAqC,EACr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AC,CAAC,CAAC;IACxC;IACAV,eAAe,CAACpB,IAAI,CAAC4B,KAAK,CAAC;EAC7B;EACA,OAAOR,eAAe;AACxB;;AAGA,SAAStB,SAAS,CAAClC,IAAI,EAAE;EACvB,IAAIA,IAAI,CAAC6D,WAAW,EAAE;IACpB,OAAO,YAAY;EACrB;EAEA,IAAI7D,IAAI,CAACgD,cAAc,EAAE;IACvB,OAAO,SAAS;EAClB;EAEA,OAAO,OAAO;AAChB"}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.extractGeometryInfo = extractGeometryInfo;
|
|
9
|
-
|
|
10
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
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; } } }; }
|
|
13
|
-
|
|
14
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); }
|
|
15
|
-
|
|
16
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; }
|
|
17
|
-
|
|
18
12
|
function extractGeometryInfo(features) {
|
|
19
13
|
var pointPositionsCount = 0;
|
|
20
14
|
var pointFeaturesCount = 0;
|
|
@@ -26,29 +20,23 @@ function extractGeometryInfo(features) {
|
|
|
26
20
|
var polygonRingsCount = 0;
|
|
27
21
|
var polygonFeaturesCount = 0;
|
|
28
22
|
var coordLengths = new Set();
|
|
29
|
-
|
|
30
23
|
var _iterator = _createForOfIteratorHelper(features),
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
_step;
|
|
33
25
|
try {
|
|
34
26
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
35
27
|
var feature = _step.value;
|
|
36
28
|
var geometry = feature.geometry;
|
|
37
|
-
|
|
38
29
|
switch (geometry.type) {
|
|
39
30
|
case 'Point':
|
|
40
31
|
pointFeaturesCount++;
|
|
41
32
|
pointPositionsCount++;
|
|
42
33
|
coordLengths.add(geometry.coordinates.length);
|
|
43
34
|
break;
|
|
44
|
-
|
|
45
35
|
case 'MultiPoint':
|
|
46
36
|
pointFeaturesCount++;
|
|
47
37
|
pointPositionsCount += geometry.coordinates.length;
|
|
48
|
-
|
|
49
38
|
var _iterator2 = _createForOfIteratorHelper(geometry.coordinates),
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
_step2;
|
|
52
40
|
try {
|
|
53
41
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
54
42
|
var point = _step2.value;
|
|
@@ -59,17 +47,13 @@ function extractGeometryInfo(features) {
|
|
|
59
47
|
} finally {
|
|
60
48
|
_iterator2.f();
|
|
61
49
|
}
|
|
62
|
-
|
|
63
50
|
break;
|
|
64
|
-
|
|
65
51
|
case 'LineString':
|
|
66
52
|
lineFeaturesCount++;
|
|
67
53
|
linePositionsCount += geometry.coordinates.length;
|
|
68
54
|
linePathsCount++;
|
|
69
|
-
|
|
70
55
|
var _iterator3 = _createForOfIteratorHelper(geometry.coordinates),
|
|
71
|
-
|
|
72
|
-
|
|
56
|
+
_step3;
|
|
73
57
|
try {
|
|
74
58
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
75
59
|
var coord = _step3.value;
|
|
@@ -80,15 +64,11 @@ function extractGeometryInfo(features) {
|
|
|
80
64
|
} finally {
|
|
81
65
|
_iterator3.f();
|
|
82
66
|
}
|
|
83
|
-
|
|
84
67
|
break;
|
|
85
|
-
|
|
86
68
|
case 'MultiLineString':
|
|
87
69
|
lineFeaturesCount++;
|
|
88
|
-
|
|
89
70
|
var _iterator4 = _createForOfIteratorHelper(geometry.coordinates),
|
|
90
|
-
|
|
91
|
-
|
|
71
|
+
_step4;
|
|
92
72
|
try {
|
|
93
73
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
94
74
|
var line = _step4.value;
|
|
@@ -96,8 +76,7 @@ function extractGeometryInfo(features) {
|
|
|
96
76
|
linePathsCount++;
|
|
97
77
|
|
|
98
78
|
var _iterator5 = _createForOfIteratorHelper(line),
|
|
99
|
-
|
|
100
|
-
|
|
79
|
+
_step5;
|
|
101
80
|
try {
|
|
102
81
|
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
103
82
|
var _coord = _step5.value;
|
|
@@ -114,19 +93,15 @@ function extractGeometryInfo(features) {
|
|
|
114
93
|
} finally {
|
|
115
94
|
_iterator4.f();
|
|
116
95
|
}
|
|
117
|
-
|
|
118
96
|
break;
|
|
119
|
-
|
|
120
97
|
case 'Polygon':
|
|
121
98
|
polygonFeaturesCount++;
|
|
122
99
|
polygonObjectsCount++;
|
|
123
100
|
polygonRingsCount += geometry.coordinates.length;
|
|
124
101
|
var flattened = geometry.coordinates.flat();
|
|
125
102
|
polygonPositionsCount += flattened.length;
|
|
126
|
-
|
|
127
103
|
var _iterator6 = _createForOfIteratorHelper(flattened),
|
|
128
|
-
|
|
129
|
-
|
|
104
|
+
_step6;
|
|
130
105
|
try {
|
|
131
106
|
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
132
107
|
var _coord2 = _step6.value;
|
|
@@ -137,28 +112,21 @@ function extractGeometryInfo(features) {
|
|
|
137
112
|
} finally {
|
|
138
113
|
_iterator6.f();
|
|
139
114
|
}
|
|
140
|
-
|
|
141
115
|
break;
|
|
142
|
-
|
|
143
116
|
case 'MultiPolygon':
|
|
144
117
|
polygonFeaturesCount++;
|
|
145
|
-
|
|
146
118
|
var _iterator7 = _createForOfIteratorHelper(geometry.coordinates),
|
|
147
|
-
|
|
148
|
-
|
|
119
|
+
_step7;
|
|
149
120
|
try {
|
|
150
121
|
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
151
122
|
var polygon = _step7.value;
|
|
152
123
|
polygonObjectsCount++;
|
|
153
124
|
polygonRingsCount += polygon.length;
|
|
154
|
-
|
|
155
125
|
var _flattened = polygon.flat();
|
|
156
|
-
|
|
157
126
|
polygonPositionsCount += _flattened.length;
|
|
158
127
|
|
|
159
128
|
var _iterator8 = _createForOfIteratorHelper(_flattened),
|
|
160
|
-
|
|
161
|
-
|
|
129
|
+
_step8;
|
|
162
130
|
try {
|
|
163
131
|
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
164
132
|
var _coord3 = _step8.value;
|
|
@@ -175,9 +143,7 @@ function extractGeometryInfo(features) {
|
|
|
175
143
|
} finally {
|
|
176
144
|
_iterator7.f();
|
|
177
145
|
}
|
|
178
|
-
|
|
179
146
|
break;
|
|
180
|
-
|
|
181
147
|
default:
|
|
182
148
|
throw new Error("Unsupported geometry type: ".concat(geometry.type));
|
|
183
149
|
}
|
|
@@ -187,7 +153,6 @@ function extractGeometryInfo(features) {
|
|
|
187
153
|
} finally {
|
|
188
154
|
_iterator.f();
|
|
189
155
|
}
|
|
190
|
-
|
|
191
156
|
return {
|
|
192
157
|
coordLength: coordLengths.size > 0 ? Math.max.apply(Math, (0, _toConsumableArray2.default)(coordLengths)) : 2,
|
|
193
158
|
pointPositionsCount: pointPositionsCount,
|