@loaders.gl/gis 4.0.0-alpha.4 → 4.0.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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +59 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/binary-to-geojson.js +255 -0
- package/dist/es5/lib/binary-to-geojson.js.map +1 -0
- package/dist/es5/lib/extract-geometry-info.js +167 -0
- package/dist/es5/lib/extract-geometry-info.js.map +1 -0
- package/dist/es5/lib/flat-geojson-to-binary-types.js +2 -0
- package/dist/es5/lib/flat-geojson-to-binary-types.js.map +1 -0
- package/dist/es5/lib/flat-geojson-to-binary.js +344 -0
- package/dist/es5/lib/flat-geojson-to-binary.js.map +1 -0
- package/dist/es5/lib/geojson-to-binary.js +26 -0
- package/dist/es5/lib/geojson-to-binary.js.map +1 -0
- package/dist/es5/lib/geojson-to-flat-geojson.js +136 -0
- package/dist/es5/lib/geojson-to-flat-geojson.js.map +1 -0
- package/dist/es5/lib/transform.js +57 -0
- package/dist/es5/lib/transform.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/binary-to-geojson.js +223 -0
- package/dist/esm/lib/binary-to-geojson.js.map +1 -0
- package/dist/esm/lib/extract-geometry-info.js +84 -0
- package/dist/esm/lib/extract-geometry-info.js.map +1 -0
- package/dist/esm/lib/flat-geojson-to-binary-types.js +2 -0
- package/dist/esm/lib/flat-geojson-to-binary-types.js.map +1 -0
- package/dist/esm/lib/flat-geojson-to-binary.js +305 -0
- package/dist/esm/lib/flat-geojson-to-binary.js.map +1 -0
- package/dist/esm/lib/geojson-to-binary.js +22 -0
- package/dist/esm/lib/geojson-to-binary.js.map +1 -0
- package/dist/esm/lib/geojson-to-flat-geojson.js +97 -0
- package/dist/esm/lib/geojson-to-flat-geojson.js.map +1 -0
- package/dist/esm/lib/transform.js +40 -0
- package/dist/esm/lib/transform.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -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/extract-geometry-info.d.ts +8 -0
- package/dist/lib/extract-geometry-info.d.ts.map +1 -0
- package/dist/lib/extract-geometry-info.js +96 -0
- package/dist/lib/flat-geojson-to-binary-types.d.ts +58 -0
- package/dist/lib/flat-geojson-to-binary-types.d.ts.map +1 -0
- package/dist/lib/flat-geojson-to-binary-types.js +2 -0
- package/dist/lib/flat-geojson-to-binary.d.ts +37 -0
- package/dist/lib/flat-geojson-to-binary.d.ts.map +1 -0
- package/dist/lib/flat-geojson-to-binary.js +376 -0
- package/dist/lib/geojson-to-binary.d.ts +19 -0
- package/dist/lib/geojson-to-binary.d.ts.map +1 -0
- package/dist/lib/geojson-to-binary.js +24 -407
- package/dist/lib/geojson-to-flat-geojson.d.ts +17 -0
- package/dist/lib/geojson-to-flat-geojson.d.ts.map +1 -0
- package/dist/lib/geojson-to-flat-geojson.js +128 -0
- 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 +8 -7
- package/src/index.ts +2 -0
- package/src/lib/extract-geometry-info.ts +101 -0
- package/src/lib/flat-geojson-to-binary-types.ts +58 -0
- package/src/lib/flat-geojson-to-binary.ts +565 -0
- package/src/lib/geojson-to-binary.ts +24 -450
- package/src/lib/geojson-to-flat-geojson.ts +171 -0
- 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
|
@@ -1,407 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const numericPropKeys = {};
|
|
26
|
-
|
|
27
|
-
for (const feature of features) {
|
|
28
|
-
const geometry = feature.geometry;
|
|
29
|
-
|
|
30
|
-
switch (geometry.type) {
|
|
31
|
-
case 'Point':
|
|
32
|
-
pointFeaturesCount++;
|
|
33
|
-
pointPositionsCount++;
|
|
34
|
-
coordLengths.add(geometry.coordinates.length);
|
|
35
|
-
break;
|
|
36
|
-
|
|
37
|
-
case 'MultiPoint':
|
|
38
|
-
pointFeaturesCount++;
|
|
39
|
-
pointPositionsCount += geometry.coordinates.length;
|
|
40
|
-
|
|
41
|
-
for (const point of geometry.coordinates) {
|
|
42
|
-
coordLengths.add(point.length);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
break;
|
|
46
|
-
|
|
47
|
-
case 'LineString':
|
|
48
|
-
lineFeaturesCount++;
|
|
49
|
-
linePositionsCount += geometry.coordinates.length;
|
|
50
|
-
linePathsCount++;
|
|
51
|
-
|
|
52
|
-
for (const coord of geometry.coordinates) {
|
|
53
|
-
coordLengths.add(coord.length);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
break;
|
|
57
|
-
|
|
58
|
-
case 'MultiLineString':
|
|
59
|
-
lineFeaturesCount++;
|
|
60
|
-
|
|
61
|
-
for (const line of geometry.coordinates) {
|
|
62
|
-
linePositionsCount += line.length;
|
|
63
|
-
linePathsCount++;
|
|
64
|
-
|
|
65
|
-
for (const coord of line) {
|
|
66
|
-
coordLengths.add(coord.length);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
break;
|
|
71
|
-
|
|
72
|
-
case 'Polygon':
|
|
73
|
-
polygonFeaturesCount++;
|
|
74
|
-
polygonObjectsCount++;
|
|
75
|
-
polygonRingsCount += geometry.coordinates.length;
|
|
76
|
-
polygonPositionsCount += flatten(geometry.coordinates).length;
|
|
77
|
-
|
|
78
|
-
for (const coord of flatten(geometry.coordinates)) {
|
|
79
|
-
coordLengths.add(coord.length);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
break;
|
|
83
|
-
|
|
84
|
-
case 'MultiPolygon':
|
|
85
|
-
polygonFeaturesCount++;
|
|
86
|
-
|
|
87
|
-
for (const polygon of geometry.coordinates) {
|
|
88
|
-
polygonObjectsCount++;
|
|
89
|
-
polygonRingsCount += polygon.length;
|
|
90
|
-
polygonPositionsCount += flatten(polygon).length;
|
|
91
|
-
|
|
92
|
-
for (const coord of flatten(polygon)) {
|
|
93
|
-
coordLengths.add(coord.length);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
break;
|
|
98
|
-
|
|
99
|
-
default:
|
|
100
|
-
throw new Error("Unsupported geometry type: ".concat(geometry.type));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (feature.properties) {
|
|
104
|
-
for (const key in feature.properties) {
|
|
105
|
-
const val = feature.properties[key];
|
|
106
|
-
numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === undefined ? isNumeric(val) : numericPropKeys[key];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
113
|
-
pointPositionsCount,
|
|
114
|
-
pointFeaturesCount,
|
|
115
|
-
linePositionsCount,
|
|
116
|
-
linePathsCount,
|
|
117
|
-
lineFeaturesCount,
|
|
118
|
-
polygonPositionsCount,
|
|
119
|
-
polygonObjectsCount,
|
|
120
|
-
polygonRingsCount,
|
|
121
|
-
polygonFeaturesCount,
|
|
122
|
-
numericPropKeys: Object.keys(numericPropKeys).filter(k => numericPropKeys[k])
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function secondPass(features, firstPassData, options) {
|
|
127
|
-
const {
|
|
128
|
-
pointPositionsCount,
|
|
129
|
-
pointFeaturesCount,
|
|
130
|
-
linePositionsCount,
|
|
131
|
-
linePathsCount,
|
|
132
|
-
lineFeaturesCount,
|
|
133
|
-
polygonPositionsCount,
|
|
134
|
-
polygonObjectsCount,
|
|
135
|
-
polygonRingsCount,
|
|
136
|
-
polygonFeaturesCount
|
|
137
|
-
} = firstPassData;
|
|
138
|
-
const {
|
|
139
|
-
coordLength,
|
|
140
|
-
numericPropKeys,
|
|
141
|
-
PositionDataType = Float32Array
|
|
142
|
-
} = options;
|
|
143
|
-
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
144
|
-
const points = {
|
|
145
|
-
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
146
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
147
|
-
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
148
|
-
numericProps: {},
|
|
149
|
-
properties: Array(),
|
|
150
|
-
fields: Array()
|
|
151
|
-
};
|
|
152
|
-
const lines = {
|
|
153
|
-
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
154
|
-
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
155
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
156
|
-
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
157
|
-
numericProps: {},
|
|
158
|
-
properties: Array(),
|
|
159
|
-
fields: Array()
|
|
160
|
-
};
|
|
161
|
-
const polygons = {
|
|
162
|
-
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
163
|
-
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
164
|
-
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
165
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
166
|
-
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
167
|
-
numericProps: {},
|
|
168
|
-
properties: Array(),
|
|
169
|
-
fields: Array()
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
for (const object of [points, lines, polygons]) {
|
|
173
|
-
for (const propName of numericPropKeys || []) {
|
|
174
|
-
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
179
|
-
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
180
|
-
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
181
|
-
const indexMap = {
|
|
182
|
-
pointPosition: 0,
|
|
183
|
-
pointFeature: 0,
|
|
184
|
-
linePosition: 0,
|
|
185
|
-
linePath: 0,
|
|
186
|
-
lineFeature: 0,
|
|
187
|
-
polygonPosition: 0,
|
|
188
|
-
polygonObject: 0,
|
|
189
|
-
polygonRing: 0,
|
|
190
|
-
polygonFeature: 0,
|
|
191
|
-
feature: 0
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
for (const feature of features) {
|
|
195
|
-
const geometry = feature.geometry;
|
|
196
|
-
const properties = feature.properties || {};
|
|
197
|
-
|
|
198
|
-
switch (geometry.type) {
|
|
199
|
-
case 'Point':
|
|
200
|
-
handlePoint(geometry.coordinates, points, indexMap, coordLength, properties);
|
|
201
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
202
|
-
indexMap.pointFeature++;
|
|
203
|
-
break;
|
|
204
|
-
|
|
205
|
-
case 'MultiPoint':
|
|
206
|
-
handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
|
|
207
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
208
|
-
indexMap.pointFeature++;
|
|
209
|
-
break;
|
|
210
|
-
|
|
211
|
-
case 'LineString':
|
|
212
|
-
handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
|
|
213
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
214
|
-
indexMap.lineFeature++;
|
|
215
|
-
break;
|
|
216
|
-
|
|
217
|
-
case 'MultiLineString':
|
|
218
|
-
handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
|
|
219
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
220
|
-
indexMap.lineFeature++;
|
|
221
|
-
break;
|
|
222
|
-
|
|
223
|
-
case 'Polygon':
|
|
224
|
-
handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
225
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
226
|
-
indexMap.polygonFeature++;
|
|
227
|
-
break;
|
|
228
|
-
|
|
229
|
-
case 'MultiPolygon':
|
|
230
|
-
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
231
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
232
|
-
indexMap.polygonFeature++;
|
|
233
|
-
break;
|
|
234
|
-
|
|
235
|
-
default:
|
|
236
|
-
throw new Error('Invalid geometry type');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
indexMap.feature++;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function handlePoint(coords, points, indexMap, coordLength, properties) {
|
|
246
|
-
points.positions.set(coords, indexMap.pointPosition * coordLength);
|
|
247
|
-
points.globalFeatureIds[indexMap.pointPosition] = indexMap.feature;
|
|
248
|
-
points.featureIds[indexMap.pointPosition] = indexMap.pointFeature;
|
|
249
|
-
fillNumericProperties(points, properties, indexMap.pointPosition, 1);
|
|
250
|
-
indexMap.pointPosition++;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function handleMultiPoint(coords, points, indexMap, coordLength, properties) {
|
|
254
|
-
for (const point of coords) {
|
|
255
|
-
handlePoint(point, points, indexMap, coordLength, properties);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function handleLineString(coords, lines, indexMap, coordLength, properties) {
|
|
260
|
-
lines.pathIndices[indexMap.linePath] = indexMap.linePosition;
|
|
261
|
-
indexMap.linePath++;
|
|
262
|
-
fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);
|
|
263
|
-
const nPositions = coords.length;
|
|
264
|
-
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
265
|
-
lines.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.linePosition);
|
|
266
|
-
lines.featureIds.set(new Uint32Array(nPositions).fill(indexMap.lineFeature), indexMap.linePosition);
|
|
267
|
-
indexMap.linePosition += nPositions;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function handleMultiLineString(coords, lines, indexMap, coordLength, properties) {
|
|
271
|
-
for (const line of coords) {
|
|
272
|
-
handleLineString(line, lines, indexMap, coordLength, properties);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function handlePolygon(coords, polygons, indexMap, coordLength, properties) {
|
|
277
|
-
polygons.polygonIndices[indexMap.polygonObject] = indexMap.polygonPosition;
|
|
278
|
-
indexMap.polygonObject++;
|
|
279
|
-
|
|
280
|
-
for (const ring of coords) {
|
|
281
|
-
polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition;
|
|
282
|
-
indexMap.polygonRing++;
|
|
283
|
-
fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength);
|
|
284
|
-
const nPositions = ring.length;
|
|
285
|
-
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
286
|
-
polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition);
|
|
287
|
-
polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition);
|
|
288
|
-
indexMap.polygonPosition += nPositions;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) {
|
|
293
|
-
for (const polygon of coords) {
|
|
294
|
-
handlePolygon(polygon, polygons, indexMap, coordLength, properties);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
299
|
-
const returnObj = {
|
|
300
|
-
points: { ...points,
|
|
301
|
-
positions: {
|
|
302
|
-
value: points.positions,
|
|
303
|
-
size: coordLength
|
|
304
|
-
},
|
|
305
|
-
globalFeatureIds: {
|
|
306
|
-
value: points.globalFeatureIds,
|
|
307
|
-
size: 1
|
|
308
|
-
},
|
|
309
|
-
featureIds: {
|
|
310
|
-
value: points.featureIds,
|
|
311
|
-
size: 1
|
|
312
|
-
},
|
|
313
|
-
type: 'Point'
|
|
314
|
-
},
|
|
315
|
-
lines: { ...lines,
|
|
316
|
-
pathIndices: {
|
|
317
|
-
value: lines.pathIndices,
|
|
318
|
-
size: 1
|
|
319
|
-
},
|
|
320
|
-
positions: {
|
|
321
|
-
value: lines.positions,
|
|
322
|
-
size: coordLength
|
|
323
|
-
},
|
|
324
|
-
globalFeatureIds: {
|
|
325
|
-
value: lines.globalFeatureIds,
|
|
326
|
-
size: 1
|
|
327
|
-
},
|
|
328
|
-
featureIds: {
|
|
329
|
-
value: lines.featureIds,
|
|
330
|
-
size: 1
|
|
331
|
-
},
|
|
332
|
-
type: 'LineString'
|
|
333
|
-
},
|
|
334
|
-
polygons: { ...polygons,
|
|
335
|
-
polygonIndices: {
|
|
336
|
-
value: polygons.polygonIndices,
|
|
337
|
-
size: 1
|
|
338
|
-
},
|
|
339
|
-
primitivePolygonIndices: {
|
|
340
|
-
value: polygons.primitivePolygonIndices,
|
|
341
|
-
size: 1
|
|
342
|
-
},
|
|
343
|
-
positions: {
|
|
344
|
-
value: polygons.positions,
|
|
345
|
-
size: coordLength
|
|
346
|
-
},
|
|
347
|
-
globalFeatureIds: {
|
|
348
|
-
value: polygons.globalFeatureIds,
|
|
349
|
-
size: 1
|
|
350
|
-
},
|
|
351
|
-
featureIds: {
|
|
352
|
-
value: polygons.featureIds,
|
|
353
|
-
size: 1
|
|
354
|
-
},
|
|
355
|
-
type: 'Polygon'
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
for (const geomType in returnObj) {
|
|
360
|
-
for (const numericProp in returnObj[geomType].numericProps) {
|
|
361
|
-
returnObj[geomType].numericProps[numericProp] = {
|
|
362
|
-
value: returnObj[geomType].numericProps[numericProp],
|
|
363
|
-
size: 1
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return returnObj;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
function fillNumericProperties(object, properties, index, length) {
|
|
372
|
-
for (const numericPropName in object.numericProps) {
|
|
373
|
-
if (numericPropName in properties) {
|
|
374
|
-
object.numericProps[numericPropName].set(new Array(length).fill(properties[numericPropName]), index);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function keepStringProperties(properties, numericKeys) {
|
|
380
|
-
const props = {};
|
|
381
|
-
|
|
382
|
-
for (const key in properties) {
|
|
383
|
-
if (!numericKeys.includes(key)) {
|
|
384
|
-
props[key] = properties[key];
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return props;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
function fillCoords(array, coords, startVertex, coordLength) {
|
|
392
|
-
let index = startVertex * coordLength;
|
|
393
|
-
|
|
394
|
-
for (const coord of coords) {
|
|
395
|
-
array.set(coord, index);
|
|
396
|
-
index += coordLength;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function flatten(arrays) {
|
|
401
|
-
return [].concat(...arrays);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
function isNumeric(x) {
|
|
405
|
-
return Number.isFinite(x);
|
|
406
|
-
}
|
|
407
|
-
//# sourceMappingURL=geojson-to-binary.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.geojsonToBinary = void 0;
|
|
4
|
+
const extract_geometry_info_1 = require("./extract-geometry-info");
|
|
5
|
+
const geojson_to_flat_geojson_1 = require("./geojson-to-flat-geojson");
|
|
6
|
+
const flat_geojson_to_binary_1 = require("./flat-geojson-to-binary");
|
|
7
|
+
/**
|
|
8
|
+
* Convert GeoJSON features to flat binary arrays
|
|
9
|
+
*
|
|
10
|
+
* @param features
|
|
11
|
+
* @param options
|
|
12
|
+
* @returns features in binary format, grouped by geometry type
|
|
13
|
+
*/
|
|
14
|
+
function geojsonToBinary(features, options = { fixRingWinding: true }) {
|
|
15
|
+
const geometryInfo = (0, extract_geometry_info_1.extractGeometryInfo)(features);
|
|
16
|
+
const coordLength = geometryInfo.coordLength;
|
|
17
|
+
const { fixRingWinding } = options;
|
|
18
|
+
const flatFeatures = (0, geojson_to_flat_geojson_1.geojsonToFlatGeojson)(features, { coordLength, fixRingWinding });
|
|
19
|
+
return (0, flat_geojson_to_binary_1.flatGeojsonToBinary)(flatFeatures, geometryInfo, {
|
|
20
|
+
numericPropKeys: options.numericPropKeys,
|
|
21
|
+
PositionDataType: options.PositionDataType || Float32Array
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.geojsonToBinary = geojsonToBinary;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Feature, FlatFeature } from '@loaders.gl/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Options for `geojsonToFlatGeojson`
|
|
4
|
+
*/
|
|
5
|
+
export type GeojsonToFlatGeojsonOptions = {
|
|
6
|
+
coordLength: number;
|
|
7
|
+
fixRingWinding: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Convert GeoJSON features to Flat GeoJSON features
|
|
11
|
+
*
|
|
12
|
+
* @param features
|
|
13
|
+
* @param options
|
|
14
|
+
* @returns an Array of Flat GeoJSON features
|
|
15
|
+
*/
|
|
16
|
+
export declare function geojsonToFlatGeojson(features: Feature[], options?: GeojsonToFlatGeojsonOptions): FlatFeature[];
|
|
17
|
+
//# sourceMappingURL=geojson-to-flat-geojson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geojson-to-flat-geojson.d.ts","sourceRoot":"","sources":["../../src/lib/geojson-to-flat-geojson.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAY,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AASF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,2BAAoE,GAC5E,WAAW,EAAE,CAEf"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.geojsonToFlatGeojson = void 0;
|
|
4
|
+
const polygon_1 = require("@math.gl/polygon");
|
|
5
|
+
/**
|
|
6
|
+
* Convert GeoJSON features to Flat GeoJSON features
|
|
7
|
+
*
|
|
8
|
+
* @param features
|
|
9
|
+
* @param options
|
|
10
|
+
* @returns an Array of Flat GeoJSON features
|
|
11
|
+
*/
|
|
12
|
+
function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
|
|
13
|
+
return features.map((feature) => flattenFeature(feature, options));
|
|
14
|
+
}
|
|
15
|
+
exports.geojsonToFlatGeojson = geojsonToFlatGeojson;
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to copy Point values from `coordinates` into `data` & `indices`
|
|
18
|
+
*
|
|
19
|
+
* @param coordinates
|
|
20
|
+
* @param data
|
|
21
|
+
* @param indices
|
|
22
|
+
* @param options
|
|
23
|
+
*/
|
|
24
|
+
function flattenPoint(coordinates, data, indices, options) {
|
|
25
|
+
indices.push(data.length);
|
|
26
|
+
data.push(...coordinates);
|
|
27
|
+
// Pad up to coordLength
|
|
28
|
+
for (let i = coordinates.length; i < options.coordLength; i++) {
|
|
29
|
+
data.push(0);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Helper function to copy LineString values from `coordinates` into `data` & `indices`
|
|
34
|
+
*
|
|
35
|
+
* @param coordinates
|
|
36
|
+
* @param data
|
|
37
|
+
* @param indices
|
|
38
|
+
* @param options
|
|
39
|
+
*/
|
|
40
|
+
function flattenLineString(coordinates, data, indices, options) {
|
|
41
|
+
indices.push(data.length);
|
|
42
|
+
for (const c of coordinates) {
|
|
43
|
+
data.push(...c);
|
|
44
|
+
// Pad up to coordLength
|
|
45
|
+
for (let i = c.length; i < options.coordLength; i++) {
|
|
46
|
+
data.push(0);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Helper function to copy Polygon values from `coordinates` into `data` & `indices` & `areas`
|
|
52
|
+
*
|
|
53
|
+
* @param coordinates
|
|
54
|
+
* @param data
|
|
55
|
+
* @param indices
|
|
56
|
+
* @param areas
|
|
57
|
+
* @param options
|
|
58
|
+
*/
|
|
59
|
+
function flattenPolygon(coordinates, data, indices, areas, options) {
|
|
60
|
+
let count = 0;
|
|
61
|
+
const ringAreas = [];
|
|
62
|
+
const polygons = [];
|
|
63
|
+
for (const lineString of coordinates) {
|
|
64
|
+
const lineString2d = lineString.map((p) => p.slice(0, 2));
|
|
65
|
+
let area = (0, polygon_1.getPolygonSignedArea)(lineString2d.flat());
|
|
66
|
+
const ccw = area < 0;
|
|
67
|
+
// Exterior ring must be CCW and interior rings CW
|
|
68
|
+
if (options.fixRingWinding && ((count === 0 && !ccw) || (count > 0 && ccw))) {
|
|
69
|
+
lineString.reverse();
|
|
70
|
+
area = -area;
|
|
71
|
+
}
|
|
72
|
+
ringAreas.push(area);
|
|
73
|
+
flattenLineString(lineString, data, polygons, options);
|
|
74
|
+
count++;
|
|
75
|
+
}
|
|
76
|
+
if (count > 0) {
|
|
77
|
+
areas.push(ringAreas);
|
|
78
|
+
indices.push(polygons);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Flatten single GeoJSON feature into Flat GeoJSON
|
|
83
|
+
*
|
|
84
|
+
* @param feature
|
|
85
|
+
* @param options
|
|
86
|
+
* @returns A Flat GeoJSON feature
|
|
87
|
+
*/
|
|
88
|
+
function flattenFeature(feature, options) {
|
|
89
|
+
const { geometry } = feature;
|
|
90
|
+
if (geometry.type === 'GeometryCollection') {
|
|
91
|
+
throw new Error('GeometryCollection type not supported');
|
|
92
|
+
}
|
|
93
|
+
const data = [];
|
|
94
|
+
const indices = [];
|
|
95
|
+
let areas;
|
|
96
|
+
let type;
|
|
97
|
+
switch (geometry.type) {
|
|
98
|
+
case 'Point':
|
|
99
|
+
type = 'Point';
|
|
100
|
+
flattenPoint(geometry.coordinates, data, indices, options);
|
|
101
|
+
break;
|
|
102
|
+
case 'MultiPoint':
|
|
103
|
+
type = 'Point';
|
|
104
|
+
geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));
|
|
105
|
+
break;
|
|
106
|
+
case 'LineString':
|
|
107
|
+
type = 'LineString';
|
|
108
|
+
flattenLineString(geometry.coordinates, data, indices, options);
|
|
109
|
+
break;
|
|
110
|
+
case 'MultiLineString':
|
|
111
|
+
type = 'LineString';
|
|
112
|
+
geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));
|
|
113
|
+
break;
|
|
114
|
+
case 'Polygon':
|
|
115
|
+
type = 'Polygon';
|
|
116
|
+
areas = [];
|
|
117
|
+
flattenPolygon(geometry.coordinates, data, indices, areas, options);
|
|
118
|
+
break;
|
|
119
|
+
case 'MultiPolygon':
|
|
120
|
+
type = 'Polygon';
|
|
121
|
+
areas = [];
|
|
122
|
+
geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
throw new Error(`Unknown type: ${type}`);
|
|
126
|
+
}
|
|
127
|
+
return { ...feature, geometry: { type, indices, data, areas } };
|
|
128
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BinaryFeatures } from '@loaders.gl/schema';
|
|
2
|
+
type TransformCoordinate = (coord: number[]) => number[];
|
|
3
|
+
/**
|
|
4
|
+
* Apply transformation to every coordinate of binary features
|
|
5
|
+
* @param binaryFeatures binary features
|
|
6
|
+
* @param transformCoordinate Function to call on each coordinate
|
|
7
|
+
* @return Transformed binary features
|
|
8
|
+
*/
|
|
9
|
+
export declare function transformBinaryCoords(binaryFeatures: BinaryFeatures, transformCoordinate: TransformCoordinate): BinaryFeatures;
|
|
10
|
+
/**
|
|
11
|
+
* Apply transformation to every coordinate of GeoJSON features
|
|
12
|
+
*
|
|
13
|
+
* @param features Array of GeoJSON features
|
|
14
|
+
* @param fn Function to call on each coordinate
|
|
15
|
+
* @return Transformed GeoJSON features
|
|
16
|
+
*/
|
|
17
|
+
export declare function transformGeoJsonCoords(features: object[], fn: (coord: number[]) => number[]): object[];
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/lib/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,EAAiB,MAAM,oBAAoB,CAAC;AAEvE,KAAK,mBAAmB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,cAAc,EAC9B,mBAAmB,EAAE,mBAAmB,GACvC,cAAc,CAWhB;AAcD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAAE,EAClB,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,GAChC,MAAM,EAAE,CAMV"}
|