@loaders.gl/gis 4.0.0-alpha.23 → 4.0.0-alpha.25

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.
Files changed (41) hide show
  1. package/dist/es5/index.js +0 -6
  2. package/dist/es5/index.js.map +1 -1
  3. package/dist/es5/lib/binary-to-geojson.js +23 -57
  4. package/dist/es5/lib/binary-to-geojson.js.map +1 -1
  5. package/dist/es5/lib/flat-geojson-to-binary.js +1 -1
  6. package/dist/es5/lib/flat-geojson-to-binary.js.map +1 -1
  7. package/dist/es5/lib/geojson-to-binary.js.map +1 -1
  8. package/dist/es5/lib/transform.js.map +1 -1
  9. package/dist/esm/index.js +1 -1
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/lib/binary-to-geojson.js +0 -25
  12. package/dist/esm/lib/binary-to-geojson.js.map +1 -1
  13. package/dist/esm/lib/flat-geojson-to-binary.js +1 -1
  14. package/dist/esm/lib/flat-geojson-to-binary.js.map +1 -1
  15. package/dist/esm/lib/geojson-to-binary.js.map +1 -1
  16. package/dist/esm/lib/transform.js.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/lib/binary-to-geojson.d.ts +2 -4
  20. package/dist/lib/binary-to-geojson.d.ts.map +1 -1
  21. package/dist/lib/flat-geojson-to-binary.d.ts +2 -2
  22. package/dist/lib/flat-geojson-to-binary.d.ts.map +1 -1
  23. package/dist/lib/geojson-to-binary.d.ts +2 -2
  24. package/dist/lib/geojson-to-binary.d.ts.map +1 -1
  25. package/dist/lib/transform.d.ts +2 -2
  26. package/dist/lib/transform.d.ts.map +1 -1
  27. package/package.json +4 -4
  28. package/src/index.ts +1 -1
  29. package/src/lib/binary-to-geojson.ts +25 -43
  30. package/src/lib/flat-geojson-to-binary.ts +6 -6
  31. package/src/lib/geojson-to-binary.ts +2 -2
  32. package/src/lib/transform.ts +3 -3
  33. package/dist/bundle.js +0 -5
  34. package/dist/index.js +0 -18
  35. package/dist/lib/binary-to-geojson.js +0 -233
  36. package/dist/lib/extract-geometry-info.js +0 -96
  37. package/dist/lib/flat-geojson-to-binary-types.js +0 -2
  38. package/dist/lib/flat-geojson-to-binary.js +0 -385
  39. package/dist/lib/geojson-to-binary.js +0 -25
  40. package/dist/lib/geojson-to-flat-geojson.js +0 -128
  41. package/dist/lib/transform.js +0 -59
@@ -1,385 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TEST_EXPORTS = exports.flatGeojsonToBinary = void 0;
4
- /* eslint-disable indent */
5
- const polygon_1 = require("@math.gl/polygon");
6
- /**
7
- * Convert binary features to flat binary arrays. Similar to
8
- * `geojsonToBinary` helper function, except that it expects
9
- * a binary representation of the feature data, which enables
10
- * 2X-3X speed increase in parse speed, compared to using
11
- * geoJSON. See `binary-vector-tile/VectorTileFeature` for
12
- * data format detais
13
- *
14
- * @param features
15
- * @param geometryInfo
16
- * @param options
17
- * @returns filled arrays
18
- */
19
- function flatGeojsonToBinary(features, geometryInfo, options) {
20
- const propArrayTypes = extractNumericPropTypes(features);
21
- const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
22
- return fillArrays(features, {
23
- propArrayTypes,
24
- ...geometryInfo
25
- }, {
26
- numericPropKeys: (options && options.numericPropKeys) || numericPropKeys,
27
- PositionDataType: options ? options.PositionDataType : Float32Array,
28
- triangulate: options ? options.triangulate : true
29
- });
30
- }
31
- exports.flatGeojsonToBinary = flatGeojsonToBinary;
32
- exports.TEST_EXPORTS = {
33
- extractNumericPropTypes
34
- };
35
- /**
36
- * Extracts properties that are always numeric
37
- *
38
- * @param features
39
- * @returns object with numeric types
40
- */
41
- function extractNumericPropTypes(features) {
42
- const propArrayTypes = {};
43
- for (const feature of features) {
44
- if (feature.properties) {
45
- for (const key in feature.properties) {
46
- // If property has not been seen before, or if property has been numeric
47
- // in all previous features, check if numeric in this feature
48
- // If not numeric, Array is stored to prevent rechecking in the future
49
- // Additionally, detects if 64 bit precision is required
50
- const val = feature.properties[key];
51
- propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
52
- }
53
- }
54
- }
55
- return propArrayTypes;
56
- }
57
- /**
58
- * Fills coordinates into pre-allocated typed arrays
59
- *
60
- * @param features
61
- * @param geometryInfo
62
- * @param options
63
- * @returns an accessor object with value and size keys
64
- */
65
- // eslint-disable-next-line complexity, max-statements
66
- function fillArrays(features, geometryInfo, options) {
67
- const { pointPositionsCount, pointFeaturesCount, linePositionsCount, linePathsCount, lineFeaturesCount, polygonPositionsCount, polygonObjectsCount, polygonRingsCount, polygonFeaturesCount, propArrayTypes, coordLength } = geometryInfo;
68
- const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
69
- const hasGlobalId = features[0] && 'id' in features[0];
70
- const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
71
- const points = {
72
- type: 'Point',
73
- positions: new PositionDataType(pointPositionsCount * coordLength),
74
- globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
75
- featureIds: pointFeaturesCount > 65535
76
- ? new Uint32Array(pointPositionsCount)
77
- : new Uint16Array(pointPositionsCount),
78
- numericProps: {},
79
- properties: [],
80
- fields: []
81
- };
82
- const lines = {
83
- type: 'LineString',
84
- pathIndices: linePositionsCount > 65535
85
- ? new Uint32Array(linePathsCount + 1)
86
- : new Uint16Array(linePathsCount + 1),
87
- positions: new PositionDataType(linePositionsCount * coordLength),
88
- globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
89
- featureIds: lineFeaturesCount > 65535
90
- ? new Uint32Array(linePositionsCount)
91
- : new Uint16Array(linePositionsCount),
92
- numericProps: {},
93
- properties: [],
94
- fields: []
95
- };
96
- const polygons = {
97
- type: 'Polygon',
98
- polygonIndices: polygonPositionsCount > 65535
99
- ? new Uint32Array(polygonObjectsCount + 1)
100
- : new Uint16Array(polygonObjectsCount + 1),
101
- primitivePolygonIndices: polygonPositionsCount > 65535
102
- ? new Uint32Array(polygonRingsCount + 1)
103
- : new Uint16Array(polygonRingsCount + 1),
104
- positions: new PositionDataType(polygonPositionsCount * coordLength),
105
- globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
106
- featureIds: polygonFeaturesCount > 65535
107
- ? new Uint32Array(polygonPositionsCount)
108
- : new Uint16Array(polygonPositionsCount),
109
- numericProps: {},
110
- properties: [],
111
- fields: []
112
- };
113
- if (triangulate) {
114
- polygons.triangles = [];
115
- }
116
- // Instantiate numeric properties arrays; one value per vertex
117
- for (const object of [points, lines, polygons]) {
118
- for (const propName of numericPropKeys) {
119
- // If property has been numeric in all previous features in which the property existed, check
120
- // if numeric in this feature
121
- const T = propArrayTypes[propName];
122
- object.numericProps[propName] = new T(object.positions.length / coordLength);
123
- }
124
- }
125
- // Set last element of path/polygon indices as positions length
126
- lines.pathIndices[linePathsCount] = linePositionsCount;
127
- polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
128
- polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
129
- const indexMap = {
130
- pointPosition: 0,
131
- pointFeature: 0,
132
- linePosition: 0,
133
- linePath: 0,
134
- lineFeature: 0,
135
- polygonPosition: 0,
136
- polygonObject: 0,
137
- polygonRing: 0,
138
- polygonFeature: 0,
139
- feature: 0
140
- };
141
- for (const feature of features) {
142
- const geometry = feature.geometry;
143
- const properties = feature.properties || {};
144
- switch (geometry.type) {
145
- case 'Point':
146
- handlePoint(geometry, points, indexMap, coordLength, properties);
147
- points.properties.push(keepStringProperties(properties, numericPropKeys));
148
- if (hasGlobalId) {
149
- points.fields.push({ id: feature.id });
150
- }
151
- indexMap.pointFeature++;
152
- break;
153
- case 'LineString':
154
- handleLineString(geometry, lines, indexMap, coordLength, properties);
155
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
156
- if (hasGlobalId) {
157
- lines.fields.push({ id: feature.id });
158
- }
159
- indexMap.lineFeature++;
160
- break;
161
- case 'Polygon':
162
- handlePolygon(geometry, polygons, indexMap, coordLength, properties);
163
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
164
- if (hasGlobalId) {
165
- polygons.fields.push({ id: feature.id });
166
- }
167
- indexMap.polygonFeature++;
168
- break;
169
- default:
170
- throw new Error('Invalid geometry type');
171
- }
172
- indexMap.feature++;
173
- }
174
- // Wrap each array in an accessor object with value and size keys
175
- return makeAccessorObjects(points, lines, polygons, coordLength);
176
- }
177
- /**
178
- * Fills (Multi)Point coordinates into points object of arrays
179
- *
180
- * @param geometry
181
- * @param points
182
- * @param indexMap
183
- * @param coordLength
184
- * @param properties
185
- */
186
- function handlePoint(geometry, points, indexMap, coordLength, properties) {
187
- points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
188
- const nPositions = geometry.data.length / coordLength;
189
- fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
190
- points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
191
- points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
192
- indexMap.pointPosition += nPositions;
193
- }
194
- /**
195
- * Fills (Multi)LineString coordinates into lines object of arrays
196
- *
197
- * @param geometry
198
- * @param lines
199
- * @param indexMap
200
- * @param coordLength
201
- * @param properties
202
- */
203
- function handleLineString(geometry, lines, indexMap, coordLength, properties) {
204
- lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
205
- const nPositions = geometry.data.length / coordLength;
206
- fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
207
- lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
208
- lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
209
- for (let i = 0, il = geometry.indices.length; i < il; ++i) {
210
- // Extract range of data we are working with, defined by start
211
- // and end indices (these index into the geometry.data array)
212
- const start = geometry.indices[i];
213
- const end = i === il - 1
214
- ? geometry.data.length // last line, so read to end of data
215
- : geometry.indices[i + 1]; // start index for next line
216
- lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
217
- indexMap.linePosition += (end - start) / coordLength;
218
- }
219
- }
220
- /**
221
- * Fills (Multi)Polygon coordinates into polygons object of arrays
222
- *
223
- * @param geometry
224
- * @param polygons
225
- * @param indexMap
226
- * @param coordLength
227
- * @param properties
228
- */
229
- function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
230
- polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
231
- const nPositions = geometry.data.length / coordLength;
232
- fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
233
- polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
234
- polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
235
- // Unlike Point & LineString geometry.indices is a 2D array
236
- for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
237
- const startPosition = indexMap.polygonPosition;
238
- polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
239
- const areas = geometry.areas[l];
240
- const indices = geometry.indices[l];
241
- const nextIndices = geometry.indices[l + 1];
242
- for (let i = 0, il = indices.length; i < il; ++i) {
243
- const start = indices[i];
244
- const end = i === il - 1
245
- ? // last line, so either read to:
246
- nextIndices === undefined
247
- ? geometry.data.length // end of data (no next indices)
248
- : nextIndices[0] // start of first line in nextIndices
249
- : indices[i + 1]; // start index for next line
250
- polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
251
- indexMap.polygonPosition += (end - start) / coordLength;
252
- }
253
- const endPosition = indexMap.polygonPosition;
254
- triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
255
- }
256
- }
257
- /**
258
- * Triangulate polygon using earcut
259
- *
260
- * @param polygons
261
- * @param areas
262
- * @param indices
263
- * @param param3
264
- */
265
- function triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength }) {
266
- if (!polygons.triangles) {
267
- return;
268
- }
269
- const start = startPosition * coordLength;
270
- const end = endPosition * coordLength;
271
- // Extract positions and holes for just this polygon
272
- const polygonPositions = polygons.positions.subarray(start, end);
273
- // Holes are referenced relative to outer polygon
274
- const offset = indices[0];
275
- const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
276
- // Compute triangulation
277
- // @ts-expect-error TODO can earcut handle binary arrays? Add tests?
278
- const triangles = (0, polygon_1.earcut)(polygonPositions, holes, coordLength, areas);
279
- // Indices returned by triangulation are relative to start
280
- // of polygon, so we need to offset
281
- for (let t = 0, tl = triangles.length; t < tl; ++t) {
282
- polygons.triangles.push(startPosition + triangles[t]);
283
- }
284
- }
285
- /**
286
- * Wraps an object containing array into accessors
287
- *
288
- * @param obj
289
- * @param size
290
- */
291
- function wrapProps(obj, size) {
292
- const returnObj = {};
293
- for (const key in obj) {
294
- returnObj[key] = { value: obj[key], size };
295
- }
296
- return returnObj;
297
- }
298
- /**
299
- * Wrap each array in an accessor object with value and size keys
300
- *
301
- * @param points
302
- * @param lines
303
- * @param polygons
304
- * @param coordLength
305
- * @returns object
306
- */
307
- function makeAccessorObjects(points, lines, polygons, coordLength) {
308
- const binaryFeatures = {
309
- points: {
310
- ...points,
311
- positions: { value: points.positions, size: coordLength },
312
- globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
313
- featureIds: { value: points.featureIds, size: 1 },
314
- numericProps: wrapProps(points.numericProps, 1)
315
- },
316
- lines: {
317
- ...lines,
318
- positions: { value: lines.positions, size: coordLength },
319
- pathIndices: { value: lines.pathIndices, size: 1 },
320
- globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
321
- featureIds: { value: lines.featureIds, size: 1 },
322
- numericProps: wrapProps(lines.numericProps, 1)
323
- },
324
- polygons: {
325
- ...polygons,
326
- positions: { value: polygons.positions, size: coordLength },
327
- polygonIndices: { value: polygons.polygonIndices, size: 1 },
328
- primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
329
- globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
330
- featureIds: { value: polygons.featureIds, size: 1 },
331
- numericProps: wrapProps(polygons.numericProps, 1)
332
- }
333
- };
334
- if (polygons.triangles) {
335
- binaryFeatures.polygons.triangles = { value: new Uint32Array(polygons.triangles), size: 1 };
336
- }
337
- return binaryFeatures;
338
- }
339
- /**
340
- * Add numeric properties to object
341
- *
342
- * @param object
343
- * @param properties
344
- * @param index
345
- * @param length
346
- */
347
- function fillNumericProperties(object, properties, index, length) {
348
- for (const numericPropName in object.numericProps) {
349
- if (numericPropName in properties) {
350
- const value = properties[numericPropName];
351
- object.numericProps[numericPropName].fill(value, index, index + length);
352
- }
353
- }
354
- }
355
- /**
356
- * Keep string properties in object
357
- *
358
- * @param properties
359
- * @param numericKeys
360
- * @returns object
361
- */
362
- function keepStringProperties(properties, numericKeys) {
363
- const props = {};
364
- for (const key in properties) {
365
- if (!numericKeys.includes(key)) {
366
- props[key] = properties[key];
367
- }
368
- }
369
- return props;
370
- }
371
- /**
372
- *
373
- * Deduce correct array constructor to use for a given value
374
- *
375
- * @param x value to test
376
- * @param constructor previous constructor deduced
377
- * @returns PropArrayConstructor
378
- */
379
- function deduceArrayType(x, constructor) {
380
- if (constructor === Array || !Number.isFinite(x)) {
381
- return Array;
382
- }
383
- // If this or previous value required 64bits use Float64Array
384
- return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
385
- }
@@ -1,25 +0,0 @@
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, triangulate: 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
- triangulate: options.triangulate
23
- });
24
- }
25
- exports.geojsonToBinary = geojsonToBinary;
@@ -1,128 +0,0 @@
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
- }
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformGeoJsonCoords = exports.transformBinaryCoords = void 0;
4
- /**
5
- * Apply transformation to every coordinate of binary features
6
- * @param binaryFeatures binary features
7
- * @param transformCoordinate Function to call on each coordinate
8
- * @return Transformed binary features
9
- */
10
- function transformBinaryCoords(binaryFeatures, transformCoordinate) {
11
- if (binaryFeatures.points) {
12
- transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);
13
- }
14
- if (binaryFeatures.lines) {
15
- transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);
16
- }
17
- if (binaryFeatures.polygons) {
18
- transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);
19
- }
20
- return binaryFeatures;
21
- }
22
- exports.transformBinaryCoords = transformBinaryCoords;
23
- /** Transform one binary geometry */
24
- function transformBinaryGeometryPositions(binaryGeometry, fn) {
25
- const { positions } = binaryGeometry;
26
- for (let i = 0; i < positions.value.length; i += positions.size) {
27
- // @ts-ignore inclusion of bigint causes problems
28
- const coord = Array.from(positions.value.subarray(i, i + positions.size));
29
- const transformedCoord = fn(coord);
30
- // @ts-ignore typescript typing for .set seems to require bigint?
31
- positions.value.set(transformedCoord, i);
32
- }
33
- }
34
- /**
35
- * Apply transformation to every coordinate of GeoJSON features
36
- *
37
- * @param features Array of GeoJSON features
38
- * @param fn Function to call on each coordinate
39
- * @return Transformed GeoJSON features
40
- */
41
- function transformGeoJsonCoords(features, fn) {
42
- for (const feature of features) {
43
- // @ts-ignore
44
- feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);
45
- }
46
- return features;
47
- }
48
- exports.transformGeoJsonCoords = transformGeoJsonCoords;
49
- function coordMap(array, fn) {
50
- if (isCoord(array)) {
51
- return fn(array);
52
- }
53
- return array.map((item) => {
54
- return coordMap(item, fn);
55
- });
56
- }
57
- function isCoord(array) {
58
- return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);
59
- }