@loaders.gl/gis 3.1.0-alpha.3 → 3.1.0-beta.2
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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +48 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/binary-to-geojson.js +284 -0
- package/dist/es5/lib/binary-to-geojson.js.map +1 -0
- package/dist/es5/lib/geojson-to-binary.js +417 -0
- package/dist/es5/lib/geojson-to-binary.js.map +1 -0
- package/dist/es5/lib/transform.js +58 -0
- package/dist/es5/lib/transform.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/binary-to-geojson.js +274 -0
- package/dist/esm/lib/binary-to-geojson.js.map +1 -0
- package/dist/esm/lib/geojson-to-binary.js +407 -0
- package/dist/esm/lib/geojson-to-binary.js.map +1 -0
- package/dist/esm/lib/transform.js +50 -0
- package/dist/esm/lib/transform.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -4
- package/dist/lib/binary-to-geojson.d.ts +21 -0
- package/dist/lib/binary-to-geojson.d.ts.map +1 -0
- package/dist/lib/binary-to-geojson.js +201 -242
- package/dist/lib/geojson-to-binary.d.ts +39 -0
- package/dist/lib/geojson-to-binary.d.ts.map +1 -0
- package/dist/lib/geojson-to-binary.js +324 -369
- package/dist/lib/transform.d.ts +19 -0
- package/dist/lib/transform.d.ts.map +1 -0
- package/dist/lib/transform.js +51 -42
- package/package.json +7 -7
- package/dist/bundle.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/binary-to-geojson.js.map +0 -1
- package/dist/lib/geojson-to-binary.js.map +0 -1
- package/dist/lib/transform.js.map +0 -1
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
|
package/dist/bundle.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "geojsonToBinary", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _geojsonToBinary.geojsonToBinary;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "binaryToGeojson", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _binaryToGeojson.binaryToGeojson;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "binaryToGeoJson", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _binaryToGeojson.binaryToGeoJson;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "binaryToGeometry", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _binaryToGeojson.binaryToGeometry;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "transformBinaryCoords", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _transform.transformBinaryCoords;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "transformGeoJsonCoords", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _transform.transformGeoJsonCoords;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
var _geojsonToBinary = require("./lib/geojson-to-binary");
|
|
44
|
+
|
|
45
|
+
var _binaryToGeojson = require("./lib/binary-to-geojson");
|
|
46
|
+
|
|
47
|
+
var _transform = require("./lib/transform");
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA","sourcesContent":["// Types from `@loaders.gl/schema`\n\n// Functions\nexport {geojsonToBinary} from './lib/geojson-to-binary';\nexport {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"file":"index.js"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.binaryToGeojson = binaryToGeojson;
|
|
7
|
+
exports.binaryToGeoJson = binaryToGeoJson;
|
|
8
|
+
exports.binaryToGeometry = binaryToGeometry;
|
|
9
|
+
|
|
10
|
+
function binaryToGeojson(data, options) {
|
|
11
|
+
const globalFeatureId = options === null || options === void 0 ? void 0 : options.globalFeatureId;
|
|
12
|
+
|
|
13
|
+
if (globalFeatureId !== undefined) {
|
|
14
|
+
return getSingleFeature(data, globalFeatureId);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return parseFeatures(data, options === null || options === void 0 ? void 0 : options.type);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function binaryToGeoJson(data, type, format = 'feature') {
|
|
21
|
+
switch (format) {
|
|
22
|
+
case 'feature':
|
|
23
|
+
return parseFeatures(data, type);
|
|
24
|
+
|
|
25
|
+
case 'geometry':
|
|
26
|
+
return binaryToGeometry(data);
|
|
27
|
+
|
|
28
|
+
default:
|
|
29
|
+
throw new Error(format);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getSingleFeature(data, globalFeatureId) {
|
|
34
|
+
const dataArray = normalizeInput(data);
|
|
35
|
+
|
|
36
|
+
for (const data of dataArray) {
|
|
37
|
+
let lastIndex = 0;
|
|
38
|
+
let lastValue = data.featureIds.value[0];
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < data.featureIds.value.length; i++) {
|
|
41
|
+
const currValue = data.featureIds.value[i];
|
|
42
|
+
|
|
43
|
+
if (currValue === lastValue) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {
|
|
48
|
+
return parseFeature(data, lastIndex, i);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
lastIndex = i;
|
|
52
|
+
lastValue = currValue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {
|
|
56
|
+
return parseFeature(data, lastIndex, data.featureIds.value.length);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
throw new Error("featureId:".concat(globalFeatureId, " not found"));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function parseFeatures(data, type) {
|
|
64
|
+
const dataArray = normalizeInput(data, type);
|
|
65
|
+
return parseFeatureCollection(dataArray);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function binaryToGeometry(data, startIndex, endIndex) {
|
|
69
|
+
switch (data.type) {
|
|
70
|
+
case 'Point':
|
|
71
|
+
return pointToGeoJson(data, startIndex, endIndex);
|
|
72
|
+
|
|
73
|
+
case 'LineString':
|
|
74
|
+
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
75
|
+
|
|
76
|
+
case 'Polygon':
|
|
77
|
+
return polygonToGeoJson(data, startIndex, endIndex);
|
|
78
|
+
|
|
79
|
+
default:
|
|
80
|
+
const unexpectedInput = data;
|
|
81
|
+
throw new Error("Unsupported geometry type: ".concat(unexpectedInput === null || unexpectedInput === void 0 ? void 0 : unexpectedInput.type));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function normalizeInput(data, type) {
|
|
86
|
+
const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons);
|
|
87
|
+
|
|
88
|
+
if (!isHeterogeneousType) {
|
|
89
|
+
data.type = type || parseType(data);
|
|
90
|
+
return [data];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const features = [];
|
|
94
|
+
|
|
95
|
+
if (data.points) {
|
|
96
|
+
data.points.type = 'Point';
|
|
97
|
+
features.push(data.points);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (data.lines) {
|
|
101
|
+
data.lines.type = 'LineString';
|
|
102
|
+
features.push(data.lines);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (data.polygons) {
|
|
106
|
+
data.polygons.type = 'Polygon';
|
|
107
|
+
features.push(data.polygons);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return features;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function parseFeatureCollection(dataArray) {
|
|
114
|
+
const features = [];
|
|
115
|
+
|
|
116
|
+
for (const data of dataArray) {
|
|
117
|
+
if (data.featureIds.value.length === 0) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let lastIndex = 0;
|
|
122
|
+
let lastValue = data.featureIds.value[0];
|
|
123
|
+
|
|
124
|
+
for (let i = 0; i < data.featureIds.value.length; i++) {
|
|
125
|
+
const currValue = data.featureIds.value[i];
|
|
126
|
+
|
|
127
|
+
if (currValue === lastValue) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
features.push(parseFeature(data, lastIndex, i));
|
|
132
|
+
lastIndex = i;
|
|
133
|
+
lastValue = currValue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
features.push(parseFeature(data, lastIndex, data.featureIds.value.length));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return features;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function parseFeature(data, startIndex, endIndex) {
|
|
143
|
+
const geometry = binaryToGeometry(data, startIndex, endIndex);
|
|
144
|
+
const properties = parseProperties(data, startIndex, endIndex);
|
|
145
|
+
const fields = parseFields(data, startIndex, endIndex);
|
|
146
|
+
return {
|
|
147
|
+
type: 'Feature',
|
|
148
|
+
geometry,
|
|
149
|
+
properties,
|
|
150
|
+
...fields
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function parseFields(data, startIndex = 0, endIndex) {
|
|
155
|
+
return data.fields && data.fields[data.featureIds.value[startIndex]];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function parseProperties(data, startIndex = 0, endIndex) {
|
|
159
|
+
const properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);
|
|
160
|
+
|
|
161
|
+
for (const key in data.numericProps) {
|
|
162
|
+
properties[key] = data.numericProps[key].value[startIndex];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return properties;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
169
|
+
const {
|
|
170
|
+
positions
|
|
171
|
+
} = data;
|
|
172
|
+
const polygonIndices = data.polygonIndices.value.filter(x => x >= startIndex && x <= endIndex);
|
|
173
|
+
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(x => x >= startIndex && x <= endIndex);
|
|
174
|
+
const multi = polygonIndices.length > 2;
|
|
175
|
+
|
|
176
|
+
if (!multi) {
|
|
177
|
+
const coordinates = [];
|
|
178
|
+
|
|
179
|
+
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
180
|
+
const startRingIndex = primitivePolygonIndices[i];
|
|
181
|
+
const endRingIndex = primitivePolygonIndices[i + 1];
|
|
182
|
+
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
183
|
+
coordinates.push(ringCoordinates);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
type: 'Polygon',
|
|
188
|
+
coordinates
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const coordinates = [];
|
|
193
|
+
|
|
194
|
+
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
195
|
+
const startPolygonIndex = polygonIndices[i];
|
|
196
|
+
const endPolygonIndex = polygonIndices[i + 1];
|
|
197
|
+
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
198
|
+
coordinates.push(polygonCoordinates);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
type: 'MultiPolygon',
|
|
203
|
+
coordinates
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
208
|
+
const {
|
|
209
|
+
positions
|
|
210
|
+
} = data;
|
|
211
|
+
const pathIndices = data.pathIndices.value.filter(x => x >= startIndex && x <= endIndex);
|
|
212
|
+
const multi = pathIndices.length > 2;
|
|
213
|
+
|
|
214
|
+
if (!multi) {
|
|
215
|
+
const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
216
|
+
return {
|
|
217
|
+
type: 'LineString',
|
|
218
|
+
coordinates
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const coordinates = [];
|
|
223
|
+
|
|
224
|
+
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
225
|
+
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
226
|
+
coordinates.push(ringCoordinates);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
type: 'MultiLineString',
|
|
231
|
+
coordinates
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function pointToGeoJson(data, startIndex, endIndex) {
|
|
236
|
+
const {
|
|
237
|
+
positions
|
|
238
|
+
} = data;
|
|
239
|
+
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
240
|
+
const multi = coordinates.length > 1;
|
|
241
|
+
|
|
242
|
+
if (multi) {
|
|
243
|
+
return {
|
|
244
|
+
type: 'MultiPoint',
|
|
245
|
+
coordinates
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
type: 'Point',
|
|
251
|
+
coordinates: coordinates[0]
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function ringToGeoJson(positions, startIndex, endIndex) {
|
|
256
|
+
startIndex = startIndex || 0;
|
|
257
|
+
endIndex = endIndex || positions.value.length / positions.size;
|
|
258
|
+
const ringCoordinates = [];
|
|
259
|
+
|
|
260
|
+
for (let j = startIndex; j < endIndex; j++) {
|
|
261
|
+
const coord = Array();
|
|
262
|
+
|
|
263
|
+
for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
264
|
+
coord.push(Number(positions.value[k]));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
ringCoordinates.push(coord);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return ringCoordinates;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function parseType(data) {
|
|
274
|
+
if (data.pathIndices) {
|
|
275
|
+
return 'LineString';
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (data.polygonIndices) {
|
|
279
|
+
return 'Polygon';
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return 'Point';
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=binary-to-geojson.js.map
|
|
@@ -0,0 +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,QAAMC,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,SAASC,eAAT,CACL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AiCI,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"}
|