@loaders.gl/flatgeobuf 4.1.0-alpha.6 → 4.1.0-alpha.7

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 (176) hide show
  1. package/dist/LICENSE +9 -0
  2. package/dist/flatgeobuf/3.27.2/LICENSE +29 -0
  3. package/dist/flatgeobuf/3.27.2/README.md +45 -0
  4. package/dist/flatgeobuf/3.27.2/column-meta.d.ts +14 -0
  5. package/dist/flatgeobuf/3.27.2/column-meta.d.ts.map +1 -0
  6. package/dist/flatgeobuf/3.27.2/column-meta.js +2 -0
  7. package/dist/flatgeobuf/3.27.2/column-meta.js.map +1 -0
  8. package/dist/flatgeobuf/3.27.2/config.d.ts +10 -0
  9. package/dist/flatgeobuf/3.27.2/config.d.ts.map +1 -0
  10. package/dist/flatgeobuf/3.27.2/config.js +16 -0
  11. package/dist/flatgeobuf/3.27.2/config.js.map +1 -0
  12. package/dist/flatgeobuf/3.27.2/constants.d.ts +3 -0
  13. package/dist/flatgeobuf/3.27.2/constants.d.ts.map +1 -0
  14. package/dist/flatgeobuf/3.27.2/constants.js +3 -0
  15. package/dist/flatgeobuf/3.27.2/constants.js.map +1 -0
  16. package/dist/flatgeobuf/3.27.2/crs-meta.d.ts +9 -0
  17. package/dist/flatgeobuf/3.27.2/crs-meta.d.ts.map +1 -0
  18. package/dist/flatgeobuf/3.27.2/crs-meta.js +2 -0
  19. package/dist/flatgeobuf/3.27.2/crs-meta.js.map +1 -0
  20. package/dist/flatgeobuf/3.27.2/dumptree.d.ts +2 -0
  21. package/dist/flatgeobuf/3.27.2/dumptree.d.ts.map +1 -0
  22. package/dist/flatgeobuf/3.27.2/dumptree.js +61 -0
  23. package/dist/flatgeobuf/3.27.2/dumptree.js.map +1 -0
  24. package/dist/flatgeobuf/3.27.2/feature.d.ts +2 -0
  25. package/dist/flatgeobuf/3.27.2/feature.d.ts.map +1 -0
  26. package/dist/flatgeobuf/3.27.2/feature.js +3 -0
  27. package/dist/flatgeobuf/3.27.2/feature.js.map +1 -0
  28. package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.d.ts +18 -0
  29. package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.d.ts.map +1 -0
  30. package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.js +19 -0
  31. package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.js.map +1 -0
  32. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.d.ts +39 -0
  33. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.d.ts.map +1 -0
  34. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.js +121 -0
  35. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.js.map +1 -0
  36. package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.d.ts +29 -0
  37. package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.d.ts.map +1 -0
  38. package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.js +79 -0
  39. package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.js.map +1 -0
  40. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.d.ts +29 -0
  41. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.d.ts.map +1 -0
  42. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.js +95 -0
  43. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.js.map +1 -0
  44. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.d.ts +21 -0
  45. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.d.ts.map +1 -0
  46. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.js +22 -0
  47. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.js.map +1 -0
  48. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.d.ts +75 -0
  49. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.d.ts.map +1 -0
  50. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.js +214 -0
  51. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.js.map +1 -0
  52. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.d.ts +59 -0
  53. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.d.ts.map +1 -0
  54. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.js +166 -0
  55. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.js.map +1 -0
  56. package/dist/flatgeobuf/3.27.2/flat-geobuf.d.ts +6 -0
  57. package/dist/flatgeobuf/3.27.2/flat-geobuf.d.ts.map +1 -0
  58. package/dist/flatgeobuf/3.27.2/flat-geobuf.js +6 -0
  59. package/dist/flatgeobuf/3.27.2/flat-geobuf.js.map +1 -0
  60. package/dist/flatgeobuf/3.27.2/generic/feature.d.ts +19 -0
  61. package/dist/flatgeobuf/3.27.2/generic/feature.d.ts.map +1 -0
  62. package/dist/flatgeobuf/3.27.2/generic/feature.js +220 -0
  63. package/dist/flatgeobuf/3.27.2/generic/feature.js.map +1 -0
  64. package/dist/flatgeobuf/3.27.2/generic/featurecollection.d.ts +18 -0
  65. package/dist/flatgeobuf/3.27.2/generic/featurecollection.d.ts.map +1 -0
  66. package/dist/flatgeobuf/3.27.2/generic/featurecollection.js +162 -0
  67. package/dist/flatgeobuf/3.27.2/generic/featurecollection.js.map +1 -0
  68. package/dist/flatgeobuf/3.27.2/generic/geometry.d.ts +33 -0
  69. package/dist/flatgeobuf/3.27.2/generic/geometry.d.ts.map +1 -0
  70. package/dist/flatgeobuf/3.27.2/generic/geometry.js +81 -0
  71. package/dist/flatgeobuf/3.27.2/generic/geometry.js.map +1 -0
  72. package/dist/flatgeobuf/3.27.2/generic/header.d.ts +5 -0
  73. package/dist/flatgeobuf/3.27.2/generic/header.d.ts.map +1 -0
  74. package/dist/flatgeobuf/3.27.2/generic/header.js +27 -0
  75. package/dist/flatgeobuf/3.27.2/generic/header.js.map +1 -0
  76. package/dist/flatgeobuf/3.27.2/generic.d.ts +16 -0
  77. package/dist/flatgeobuf/3.27.2/generic.d.ts.map +1 -0
  78. package/dist/flatgeobuf/3.27.2/generic.js +9 -0
  79. package/dist/flatgeobuf/3.27.2/generic.js.map +1 -0
  80. package/dist/flatgeobuf/3.27.2/geojson/feature.d.ts +8 -0
  81. package/dist/flatgeobuf/3.27.2/geojson/feature.d.ts.map +1 -0
  82. package/dist/flatgeobuf/3.27.2/geojson/feature.js +13 -0
  83. package/dist/flatgeobuf/3.27.2/geojson/feature.js.map +1 -0
  84. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.d.ts +8 -0
  85. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.d.ts.map +1 -0
  86. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.js +54 -0
  87. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.js.map +1 -0
  88. package/dist/flatgeobuf/3.27.2/geojson/geometry.d.ts +13 -0
  89. package/dist/flatgeobuf/3.27.2/geojson/geometry.d.ts.map +1 -0
  90. package/dist/flatgeobuf/3.27.2/geojson/geometry.js +118 -0
  91. package/dist/flatgeobuf/3.27.2/geojson/geometry.js.map +1 -0
  92. package/dist/flatgeobuf/3.27.2/geojson.d.ts +17 -0
  93. package/dist/flatgeobuf/3.27.2/geojson.d.ts.map +1 -0
  94. package/dist/flatgeobuf/3.27.2/geojson.js +10 -0
  95. package/dist/flatgeobuf/3.27.2/geojson.js.map +1 -0
  96. package/dist/flatgeobuf/3.27.2/header-meta.d.ts +17 -0
  97. package/dist/flatgeobuf/3.27.2/header-meta.d.ts.map +1 -0
  98. package/dist/flatgeobuf/3.27.2/header-meta.js +46 -0
  99. package/dist/flatgeobuf/3.27.2/header-meta.js.map +1 -0
  100. package/dist/flatgeobuf/3.27.2/header.d.ts +2 -0
  101. package/dist/flatgeobuf/3.27.2/header.d.ts.map +1 -0
  102. package/dist/flatgeobuf/3.27.2/header.js +3 -0
  103. package/dist/flatgeobuf/3.27.2/header.js.map +1 -0
  104. package/dist/flatgeobuf/3.27.2/http-reader.d.ts +41 -0
  105. package/dist/flatgeobuf/3.27.2/http-reader.d.ts.map +1 -0
  106. package/dist/flatgeobuf/3.27.2/http-reader.js +193 -0
  107. package/dist/flatgeobuf/3.27.2/http-reader.js.map +1 -0
  108. package/dist/flatgeobuf/3.27.2/index.d.ts +14 -0
  109. package/dist/flatgeobuf/3.27.2/index.d.ts.map +1 -0
  110. package/dist/flatgeobuf/3.27.2/index.js +16 -0
  111. package/dist/flatgeobuf/3.27.2/index.js.map +1 -0
  112. package/dist/flatgeobuf/3.27.2/logger.d.ts +15 -0
  113. package/dist/flatgeobuf/3.27.2/logger.d.ts.map +1 -0
  114. package/dist/flatgeobuf/3.27.2/logger.js +65 -0
  115. package/dist/flatgeobuf/3.27.2/logger.js.map +1 -0
  116. package/dist/flatgeobuf/3.27.2/packedrtree.d.ts +43 -0
  117. package/dist/flatgeobuf/3.27.2/packedrtree.d.ts.map +1 -0
  118. package/dist/flatgeobuf/3.27.2/packedrtree.js +138 -0
  119. package/dist/flatgeobuf/3.27.2/packedrtree.js.map +1 -0
  120. package/dist/flatgeobuf/3.27.2/streams/utils.d.ts +7 -0
  121. package/dist/flatgeobuf/3.27.2/streams/utils.d.ts.map +1 -0
  122. package/dist/flatgeobuf/3.27.2/streams/utils.js +67 -0
  123. package/dist/flatgeobuf/3.27.2/streams/utils.js.map +1 -0
  124. package/dist/flatgeobuf/3.27.2/types/jsts.d.ts +23 -0
  125. package/dist/flatgeobuf/3.27.2/types/slice.d.ts +16 -0
  126. package/dist/flatgeobuf-loader.js +1 -1
  127. package/dist/index.cjs +1547 -6
  128. package/dist/lib/binary-geometries.d.ts +1 -1
  129. package/dist/lib/binary-geometries.d.ts.map +1 -1
  130. package/dist/lib/binary-geometries.js.map +1 -1
  131. package/dist/lib/get-schema-from-fgb-header.d.ts +1 -1
  132. package/dist/lib/get-schema-from-fgb-header.d.ts.map +1 -1
  133. package/dist/lib/get-schema-from-fgb-header.js.map +1 -1
  134. package/dist/lib/parse-flatgeobuf.d.ts +1 -1
  135. package/dist/lib/parse-flatgeobuf.d.ts.map +1 -1
  136. package/dist/lib/parse-flatgeobuf.js +3 -3
  137. package/dist/lib/parse-flatgeobuf.js.map +1 -1
  138. package/package.json +8 -5
  139. package/src/LICENSE +9 -0
  140. package/src/flatgeobuf/3.27.2/LICENSE +29 -0
  141. package/src/flatgeobuf/3.27.2/README.md +45 -0
  142. package/src/flatgeobuf/3.27.2/column-meta.ts +14 -0
  143. package/src/flatgeobuf/3.27.2/config.ts +19 -0
  144. package/src/flatgeobuf/3.27.2/constants.ts +4 -0
  145. package/src/flatgeobuf/3.27.2/crs-meta.ts +8 -0
  146. package/src/flatgeobuf/3.27.2/dumptree.ts +82 -0
  147. package/src/flatgeobuf/3.27.2/feature.ts +3 -0
  148. package/src/flatgeobuf/3.27.2/flat-geobuf/column-type.ts +19 -0
  149. package/src/flatgeobuf/3.27.2/flat-geobuf/column.ts +170 -0
  150. package/src/flatgeobuf/3.27.2/flat-geobuf/crs.ts +114 -0
  151. package/src/flatgeobuf/3.27.2/flat-geobuf/feature.ts +140 -0
  152. package/src/flatgeobuf/3.27.2/flat-geobuf/geometry-type.ts +22 -0
  153. package/src/flatgeobuf/3.27.2/flat-geobuf/geometry.ts +382 -0
  154. package/src/flatgeobuf/3.27.2/flat-geobuf/header.ts +246 -0
  155. package/src/flatgeobuf/3.27.2/flat-geobuf.ts +7 -0
  156. package/src/flatgeobuf/3.27.2/generic/feature.ts +243 -0
  157. package/src/flatgeobuf/3.27.2/generic/featurecollection.ts +227 -0
  158. package/src/flatgeobuf/3.27.2/generic/geometry.ts +120 -0
  159. package/src/flatgeobuf/3.27.2/generic/header.ts +32 -0
  160. package/src/flatgeobuf/3.27.2/generic.ts +33 -0
  161. package/src/flatgeobuf/3.27.2/geojson/feature.ts +20 -0
  162. package/src/flatgeobuf/3.27.2/geojson/featurecollection.ts +101 -0
  163. package/src/flatgeobuf/3.27.2/geojson/geometry.ts +142 -0
  164. package/src/flatgeobuf/3.27.2/geojson.ts +37 -0
  165. package/src/flatgeobuf/3.27.2/header-meta.ts +66 -0
  166. package/src/flatgeobuf/3.27.2/header.ts +3 -0
  167. package/src/flatgeobuf/3.27.2/http-reader.ts +351 -0
  168. package/src/flatgeobuf/3.27.2/index.ts +19 -0
  169. package/src/flatgeobuf/3.27.2/logger.ts +51 -0
  170. package/src/flatgeobuf/3.27.2/packedrtree.ts +255 -0
  171. package/src/flatgeobuf/3.27.2/streams/utils.ts +80 -0
  172. package/src/flatgeobuf/3.27.2/types/jsts.d.ts +23 -0
  173. package/src/flatgeobuf/3.27.2/types/slice.d.ts +16 -0
  174. package/src/lib/binary-geometries.ts +2 -2
  175. package/src/lib/get-schema-from-fgb-header.ts +1 -1
  176. package/src/lib/parse-flatgeobuf.ts +4 -4
package/dist/index.cjs CHANGED
@@ -220,17 +220,1558 @@ function getTypeFromFGBType(fgbType) {
220
220
  }
221
221
  }
222
222
 
223
+ // src/flatgeobuf/3.27.2/flat-geobuf/geometry-type.ts
224
+ var GeometryType2 = /* @__PURE__ */ ((GeometryType3) => {
225
+ GeometryType3[GeometryType3["Unknown"] = 0] = "Unknown";
226
+ GeometryType3[GeometryType3["Point"] = 1] = "Point";
227
+ GeometryType3[GeometryType3["LineString"] = 2] = "LineString";
228
+ GeometryType3[GeometryType3["Polygon"] = 3] = "Polygon";
229
+ GeometryType3[GeometryType3["MultiPoint"] = 4] = "MultiPoint";
230
+ GeometryType3[GeometryType3["MultiLineString"] = 5] = "MultiLineString";
231
+ GeometryType3[GeometryType3["MultiPolygon"] = 6] = "MultiPolygon";
232
+ GeometryType3[GeometryType3["GeometryCollection"] = 7] = "GeometryCollection";
233
+ GeometryType3[GeometryType3["CircularString"] = 8] = "CircularString";
234
+ GeometryType3[GeometryType3["CompoundCurve"] = 9] = "CompoundCurve";
235
+ GeometryType3[GeometryType3["CurvePolygon"] = 10] = "CurvePolygon";
236
+ GeometryType3[GeometryType3["MultiCurve"] = 11] = "MultiCurve";
237
+ GeometryType3[GeometryType3["MultiSurface"] = 12] = "MultiSurface";
238
+ GeometryType3[GeometryType3["Curve"] = 13] = "Curve";
239
+ GeometryType3[GeometryType3["Surface"] = 14] = "Surface";
240
+ GeometryType3[GeometryType3["PolyhedralSurface"] = 15] = "PolyhedralSurface";
241
+ GeometryType3[GeometryType3["TIN"] = 16] = "TIN";
242
+ GeometryType3[GeometryType3["Triangle"] = 17] = "Triangle";
243
+ return GeometryType3;
244
+ })(GeometryType2 || {});
245
+
246
+ // src/flatgeobuf/3.27.2/flat-geobuf/geometry.ts
247
+ var flatbuffers = __toESM(require("flatbuffers"), 1);
248
+ var Geometry = class {
249
+ constructor() {
250
+ this.bb = null;
251
+ this.bb_pos = 0;
252
+ }
253
+ __init(i, bb) {
254
+ this.bb_pos = i;
255
+ this.bb = bb;
256
+ return this;
257
+ }
258
+ static getRootAsGeometry(bb, obj) {
259
+ return (obj || new Geometry()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
260
+ }
261
+ static getSizePrefixedRootAsGeometry(bb, obj) {
262
+ bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
263
+ return (obj || new Geometry()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
264
+ }
265
+ ends(index) {
266
+ const offset = this.bb.__offset(this.bb_pos, 4);
267
+ return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0;
268
+ }
269
+ endsLength() {
270
+ const offset = this.bb.__offset(this.bb_pos, 4);
271
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
272
+ }
273
+ endsArray() {
274
+ const offset = this.bb.__offset(this.bb_pos, 4);
275
+ return offset ? new Uint32Array(
276
+ this.bb.bytes().buffer,
277
+ this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
278
+ this.bb.__vector_len(this.bb_pos + offset)
279
+ ) : null;
280
+ }
281
+ xy(index) {
282
+ const offset = this.bb.__offset(this.bb_pos, 6);
283
+ return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0;
284
+ }
285
+ xyLength() {
286
+ const offset = this.bb.__offset(this.bb_pos, 6);
287
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
288
+ }
289
+ xyArray() {
290
+ const offset = this.bb.__offset(this.bb_pos, 6);
291
+ return offset ? new Float64Array(
292
+ this.bb.bytes().buffer,
293
+ this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
294
+ this.bb.__vector_len(this.bb_pos + offset)
295
+ ) : null;
296
+ }
297
+ z(index) {
298
+ const offset = this.bb.__offset(this.bb_pos, 8);
299
+ return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0;
300
+ }
301
+ zLength() {
302
+ const offset = this.bb.__offset(this.bb_pos, 8);
303
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
304
+ }
305
+ zArray() {
306
+ const offset = this.bb.__offset(this.bb_pos, 8);
307
+ return offset ? new Float64Array(
308
+ this.bb.bytes().buffer,
309
+ this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
310
+ this.bb.__vector_len(this.bb_pos + offset)
311
+ ) : null;
312
+ }
313
+ m(index) {
314
+ const offset = this.bb.__offset(this.bb_pos, 10);
315
+ return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0;
316
+ }
317
+ mLength() {
318
+ const offset = this.bb.__offset(this.bb_pos, 10);
319
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
320
+ }
321
+ mArray() {
322
+ const offset = this.bb.__offset(this.bb_pos, 10);
323
+ return offset ? new Float64Array(
324
+ this.bb.bytes().buffer,
325
+ this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
326
+ this.bb.__vector_len(this.bb_pos + offset)
327
+ ) : null;
328
+ }
329
+ t(index) {
330
+ const offset = this.bb.__offset(this.bb_pos, 12);
331
+ return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0;
332
+ }
333
+ tLength() {
334
+ const offset = this.bb.__offset(this.bb_pos, 12);
335
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
336
+ }
337
+ tArray() {
338
+ const offset = this.bb.__offset(this.bb_pos, 12);
339
+ return offset ? new Float64Array(
340
+ this.bb.bytes().buffer,
341
+ this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
342
+ this.bb.__vector_len(this.bb_pos + offset)
343
+ ) : null;
344
+ }
345
+ tm(index) {
346
+ const offset = this.bb.__offset(this.bb_pos, 14);
347
+ return offset ? this.bb.readUint64(this.bb.__vector(this.bb_pos + offset) + index * 8) : BigInt(0);
348
+ }
349
+ tmLength() {
350
+ const offset = this.bb.__offset(this.bb_pos, 14);
351
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
352
+ }
353
+ type() {
354
+ const offset = this.bb.__offset(this.bb_pos, 16);
355
+ return offset ? this.bb.readUint8(this.bb_pos + offset) : 0 /* Unknown */;
356
+ }
357
+ parts(index, obj) {
358
+ const offset = this.bb.__offset(this.bb_pos, 18);
359
+ return offset ? (obj || new Geometry()).__init(
360
+ this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4),
361
+ this.bb
362
+ ) : null;
363
+ }
364
+ partsLength() {
365
+ const offset = this.bb.__offset(this.bb_pos, 18);
366
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
367
+ }
368
+ static startGeometry(builder) {
369
+ builder.startObject(8);
370
+ }
371
+ static addEnds(builder, endsOffset) {
372
+ builder.addFieldOffset(0, endsOffset, 0);
373
+ }
374
+ static createEndsVector(builder, data) {
375
+ builder.startVector(4, data.length, 4);
376
+ for (let i = data.length - 1; i >= 0; i--) {
377
+ builder.addInt32(data[i]);
378
+ }
379
+ return builder.endVector();
380
+ }
381
+ static startEndsVector(builder, numElems) {
382
+ builder.startVector(4, numElems, 4);
383
+ }
384
+ static addXy(builder, xyOffset) {
385
+ builder.addFieldOffset(1, xyOffset, 0);
386
+ }
387
+ static createXyVector(builder, data) {
388
+ builder.startVector(8, data.length, 8);
389
+ for (let i = data.length - 1; i >= 0; i--) {
390
+ builder.addFloat64(data[i]);
391
+ }
392
+ return builder.endVector();
393
+ }
394
+ static startXyVector(builder, numElems) {
395
+ builder.startVector(8, numElems, 8);
396
+ }
397
+ static addZ(builder, zOffset) {
398
+ builder.addFieldOffset(2, zOffset, 0);
399
+ }
400
+ static createZVector(builder, data) {
401
+ builder.startVector(8, data.length, 8);
402
+ for (let i = data.length - 1; i >= 0; i--) {
403
+ builder.addFloat64(data[i]);
404
+ }
405
+ return builder.endVector();
406
+ }
407
+ static startZVector(builder, numElems) {
408
+ builder.startVector(8, numElems, 8);
409
+ }
410
+ static addM(builder, mOffset) {
411
+ builder.addFieldOffset(3, mOffset, 0);
412
+ }
413
+ static createMVector(builder, data) {
414
+ builder.startVector(8, data.length, 8);
415
+ for (let i = data.length - 1; i >= 0; i--) {
416
+ builder.addFloat64(data[i]);
417
+ }
418
+ return builder.endVector();
419
+ }
420
+ static startMVector(builder, numElems) {
421
+ builder.startVector(8, numElems, 8);
422
+ }
423
+ static addT(builder, tOffset) {
424
+ builder.addFieldOffset(4, tOffset, 0);
425
+ }
426
+ static createTVector(builder, data) {
427
+ builder.startVector(8, data.length, 8);
428
+ for (let i = data.length - 1; i >= 0; i--) {
429
+ builder.addFloat64(data[i]);
430
+ }
431
+ return builder.endVector();
432
+ }
433
+ static startTVector(builder, numElems) {
434
+ builder.startVector(8, numElems, 8);
435
+ }
436
+ static addTm(builder, tmOffset) {
437
+ builder.addFieldOffset(5, tmOffset, 0);
438
+ }
439
+ static createTmVector(builder, data) {
440
+ builder.startVector(8, data.length, 8);
441
+ for (let i = data.length - 1; i >= 0; i--) {
442
+ builder.addInt64(data[i]);
443
+ }
444
+ return builder.endVector();
445
+ }
446
+ static startTmVector(builder, numElems) {
447
+ builder.startVector(8, numElems, 8);
448
+ }
449
+ static addType(builder, type) {
450
+ builder.addFieldInt8(6, type, 0 /* Unknown */);
451
+ }
452
+ static addParts(builder, partsOffset) {
453
+ builder.addFieldOffset(7, partsOffset, 0);
454
+ }
455
+ static createPartsVector(builder, data) {
456
+ builder.startVector(4, data.length, 4);
457
+ for (let i = data.length - 1; i >= 0; i--) {
458
+ builder.addOffset(data[i]);
459
+ }
460
+ return builder.endVector();
461
+ }
462
+ static startPartsVector(builder, numElems) {
463
+ builder.startVector(4, numElems, 4);
464
+ }
465
+ static endGeometry(builder) {
466
+ const offset = builder.endObject();
467
+ return offset;
468
+ }
469
+ static createGeometry(builder, endsOffset, xyOffset, zOffset, mOffset, tOffset, tmOffset, type, partsOffset) {
470
+ Geometry.startGeometry(builder);
471
+ Geometry.addEnds(builder, endsOffset);
472
+ Geometry.addXy(builder, xyOffset);
473
+ Geometry.addZ(builder, zOffset);
474
+ Geometry.addM(builder, mOffset);
475
+ Geometry.addT(builder, tOffset);
476
+ Geometry.addTm(builder, tmOffset);
477
+ Geometry.addType(builder, type);
478
+ Geometry.addParts(builder, partsOffset);
479
+ return Geometry.endGeometry(builder);
480
+ }
481
+ };
482
+
483
+ // src/flatgeobuf/3.27.2/generic/geometry.ts
484
+ function pairFlatCoordinates(xy, z) {
485
+ const newArray = [];
486
+ for (let i = 0; i < xy.length; i += 2) {
487
+ const a = [xy[i], xy[i + 1]];
488
+ if (z)
489
+ a.push(z[i >> 1]);
490
+ newArray.push(a);
491
+ }
492
+ return newArray;
493
+ }
494
+
495
+ // src/flatgeobuf/3.27.2/geojson/geometry.ts
496
+ function extractParts(xy, z, ends) {
497
+ if (!ends || ends.length === 0)
498
+ return [pairFlatCoordinates(xy, z)];
499
+ let s = 0;
500
+ const xySlices = Array.from(ends).map((e) => xy.slice(s, s = e << 1));
501
+ let zSlices;
502
+ if (z) {
503
+ s = 0;
504
+ zSlices = Array.from(ends).map((e) => z.slice(s, s = e));
505
+ }
506
+ return xySlices.map((xy2, i) => pairFlatCoordinates(xy2, zSlices ? zSlices[i] : void 0));
507
+ }
508
+ function toGeoJsonCoordinates(geometry, type) {
509
+ const xy = geometry.xyArray();
510
+ const z = geometry.zArray();
511
+ switch (type) {
512
+ case 1 /* Point */: {
513
+ const a = Array.from(xy);
514
+ if (z)
515
+ a.push(z[0]);
516
+ return a;
517
+ }
518
+ case 4 /* MultiPoint */:
519
+ case 2 /* LineString */:
520
+ return pairFlatCoordinates(xy, z);
521
+ case 5 /* MultiLineString */:
522
+ return extractParts(xy, z, geometry.endsArray());
523
+ case 3 /* Polygon */:
524
+ return extractParts(xy, z, geometry.endsArray());
525
+ }
526
+ }
527
+ function fromGeometry(geometry, headerType) {
528
+ let type = headerType;
529
+ if (type === 0 /* Unknown */) {
530
+ type = geometry.type();
531
+ }
532
+ if (type === 7 /* GeometryCollection */) {
533
+ const geometries = [];
534
+ for (let i = 0; i < geometry.partsLength(); i++) {
535
+ const part = geometry.parts(i);
536
+ const partType = part.type();
537
+ geometries.push(fromGeometry(part, partType));
538
+ }
539
+ return {
540
+ type: GeometryType2[type],
541
+ geometries
542
+ };
543
+ } else if (type === 6 /* MultiPolygon */) {
544
+ const geometries = [];
545
+ for (let i = 0; i < geometry.partsLength(); i++)
546
+ geometries.push(fromGeometry(geometry.parts(i), 3 /* Polygon */));
547
+ return {
548
+ type: GeometryType2[type],
549
+ coordinates: geometries.map((g) => g.coordinates)
550
+ };
551
+ }
552
+ const coordinates = toGeoJsonCoordinates(geometry, type);
553
+ return {
554
+ type: GeometryType2[type],
555
+ coordinates
556
+ };
557
+ }
558
+
559
+ // src/flatgeobuf/3.27.2/generic/feature.ts
560
+ var flatbuffers4 = __toESM(require("flatbuffers"), 1);
561
+
562
+ // src/flatgeobuf/3.27.2/flat-geobuf/feature.ts
563
+ var flatbuffers3 = __toESM(require("flatbuffers"), 1);
564
+
565
+ // src/flatgeobuf/3.27.2/flat-geobuf/column.ts
566
+ var flatbuffers2 = __toESM(require("flatbuffers"), 1);
567
+ var Column = class {
568
+ constructor() {
569
+ this.bb = null;
570
+ this.bb_pos = 0;
571
+ }
572
+ __init(i, bb) {
573
+ this.bb_pos = i;
574
+ this.bb = bb;
575
+ return this;
576
+ }
577
+ static getRootAsColumn(bb, obj) {
578
+ return (obj || new Column()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
579
+ }
580
+ static getSizePrefixedRootAsColumn(bb, obj) {
581
+ bb.setPosition(bb.position() + flatbuffers2.SIZE_PREFIX_LENGTH);
582
+ return (obj || new Column()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
583
+ }
584
+ name(optionalEncoding) {
585
+ const offset = this.bb.__offset(this.bb_pos, 4);
586
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
587
+ }
588
+ type() {
589
+ const offset = this.bb.__offset(this.bb_pos, 6);
590
+ return offset ? this.bb.readUint8(this.bb_pos + offset) : 0 /* Byte */;
591
+ }
592
+ title(optionalEncoding) {
593
+ const offset = this.bb.__offset(this.bb_pos, 8);
594
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
595
+ }
596
+ description(optionalEncoding) {
597
+ const offset = this.bb.__offset(this.bb_pos, 10);
598
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
599
+ }
600
+ width() {
601
+ const offset = this.bb.__offset(this.bb_pos, 12);
602
+ return offset ? this.bb.readInt32(this.bb_pos + offset) : -1;
603
+ }
604
+ precision() {
605
+ const offset = this.bb.__offset(this.bb_pos, 14);
606
+ return offset ? this.bb.readInt32(this.bb_pos + offset) : -1;
607
+ }
608
+ scale() {
609
+ const offset = this.bb.__offset(this.bb_pos, 16);
610
+ return offset ? this.bb.readInt32(this.bb_pos + offset) : -1;
611
+ }
612
+ nullable() {
613
+ const offset = this.bb.__offset(this.bb_pos, 18);
614
+ return offset ? Boolean(this.bb.readInt8(this.bb_pos + offset)) : true;
615
+ }
616
+ unique() {
617
+ const offset = this.bb.__offset(this.bb_pos, 20);
618
+ return offset ? Boolean(this.bb.readInt8(this.bb_pos + offset)) : false;
619
+ }
620
+ primaryKey() {
621
+ const offset = this.bb.__offset(this.bb_pos, 22);
622
+ return offset ? Boolean(this.bb.readInt8(this.bb_pos + offset)) : false;
623
+ }
624
+ metadata(optionalEncoding) {
625
+ const offset = this.bb.__offset(this.bb_pos, 24);
626
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
627
+ }
628
+ static startColumn(builder) {
629
+ builder.startObject(11);
630
+ }
631
+ static addName(builder, nameOffset) {
632
+ builder.addFieldOffset(0, nameOffset, 0);
633
+ }
634
+ static addType(builder, type) {
635
+ builder.addFieldInt8(1, type, 0 /* Byte */);
636
+ }
637
+ static addTitle(builder, titleOffset) {
638
+ builder.addFieldOffset(2, titleOffset, 0);
639
+ }
640
+ static addDescription(builder, descriptionOffset) {
641
+ builder.addFieldOffset(3, descriptionOffset, 0);
642
+ }
643
+ static addWidth(builder, width) {
644
+ builder.addFieldInt32(4, width, -1);
645
+ }
646
+ static addPrecision(builder, precision) {
647
+ builder.addFieldInt32(5, precision, -1);
648
+ }
649
+ static addScale(builder, scale) {
650
+ builder.addFieldInt32(6, scale, -1);
651
+ }
652
+ static addNullable(builder, nullable) {
653
+ builder.addFieldInt8(7, Number(nullable), Number(true));
654
+ }
655
+ static addUnique(builder, unique) {
656
+ builder.addFieldInt8(8, Number(unique), Number(false));
657
+ }
658
+ static addPrimaryKey(builder, primaryKey) {
659
+ builder.addFieldInt8(9, Number(primaryKey), Number(false));
660
+ }
661
+ static addMetadata(builder, metadataOffset) {
662
+ builder.addFieldOffset(10, metadataOffset, 0);
663
+ }
664
+ static endColumn(builder) {
665
+ const offset = builder.endObject();
666
+ builder.requiredField(offset, 4);
667
+ return offset;
668
+ }
669
+ static createColumn(builder, nameOffset, type, titleOffset, descriptionOffset, width, precision, scale, nullable, unique, primaryKey, metadataOffset) {
670
+ Column.startColumn(builder);
671
+ Column.addName(builder, nameOffset);
672
+ Column.addType(builder, type);
673
+ Column.addTitle(builder, titleOffset);
674
+ Column.addDescription(builder, descriptionOffset);
675
+ Column.addWidth(builder, width);
676
+ Column.addPrecision(builder, precision);
677
+ Column.addScale(builder, scale);
678
+ Column.addNullable(builder, nullable);
679
+ Column.addUnique(builder, unique);
680
+ Column.addPrimaryKey(builder, primaryKey);
681
+ Column.addMetadata(builder, metadataOffset);
682
+ return Column.endColumn(builder);
683
+ }
684
+ };
685
+
686
+ // src/flatgeobuf/3.27.2/flat-geobuf/feature.ts
687
+ var Feature = class {
688
+ constructor() {
689
+ this.bb = null;
690
+ this.bb_pos = 0;
691
+ }
692
+ __init(i, bb) {
693
+ this.bb_pos = i;
694
+ this.bb = bb;
695
+ return this;
696
+ }
697
+ static getRootAsFeature(bb, obj) {
698
+ return (obj || new Feature()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
699
+ }
700
+ static getSizePrefixedRootAsFeature(bb, obj) {
701
+ bb.setPosition(bb.position() + flatbuffers3.SIZE_PREFIX_LENGTH);
702
+ return (obj || new Feature()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
703
+ }
704
+ geometry(obj) {
705
+ const offset = this.bb.__offset(this.bb_pos, 4);
706
+ return offset ? (obj || new Geometry()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
707
+ }
708
+ properties(index) {
709
+ const offset = this.bb.__offset(this.bb_pos, 6);
710
+ return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
711
+ }
712
+ propertiesLength() {
713
+ const offset = this.bb.__offset(this.bb_pos, 6);
714
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
715
+ }
716
+ propertiesArray() {
717
+ const offset = this.bb.__offset(this.bb_pos, 6);
718
+ return offset ? new Uint8Array(
719
+ this.bb.bytes().buffer,
720
+ this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
721
+ this.bb.__vector_len(this.bb_pos + offset)
722
+ ) : null;
723
+ }
724
+ columns(index, obj) {
725
+ const offset = this.bb.__offset(this.bb_pos, 8);
726
+ return offset ? (obj || new Column()).__init(
727
+ this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4),
728
+ this.bb
729
+ ) : null;
730
+ }
731
+ columnsLength() {
732
+ const offset = this.bb.__offset(this.bb_pos, 8);
733
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
734
+ }
735
+ static startFeature(builder) {
736
+ builder.startObject(3);
737
+ }
738
+ static addGeometry(builder, geometryOffset) {
739
+ builder.addFieldOffset(0, geometryOffset, 0);
740
+ }
741
+ static addProperties(builder, propertiesOffset) {
742
+ builder.addFieldOffset(1, propertiesOffset, 0);
743
+ }
744
+ static createPropertiesVector(builder, data) {
745
+ builder.startVector(1, data.length, 1);
746
+ for (let i = data.length - 1; i >= 0; i--) {
747
+ builder.addInt8(data[i]);
748
+ }
749
+ return builder.endVector();
750
+ }
751
+ static startPropertiesVector(builder, numElems) {
752
+ builder.startVector(1, numElems, 1);
753
+ }
754
+ static addColumns(builder, columnsOffset) {
755
+ builder.addFieldOffset(2, columnsOffset, 0);
756
+ }
757
+ static createColumnsVector(builder, data) {
758
+ builder.startVector(4, data.length, 4);
759
+ for (let i = data.length - 1; i >= 0; i--) {
760
+ builder.addOffset(data[i]);
761
+ }
762
+ return builder.endVector();
763
+ }
764
+ static startColumnsVector(builder, numElems) {
765
+ builder.startVector(4, numElems, 4);
766
+ }
767
+ static endFeature(builder) {
768
+ const offset = builder.endObject();
769
+ return offset;
770
+ }
771
+ static finishFeatureBuffer(builder, offset) {
772
+ builder.finish(offset);
773
+ }
774
+ static finishSizePrefixedFeatureBuffer(builder, offset) {
775
+ builder.finish(offset, void 0, true);
776
+ }
777
+ static createFeature(builder, geometryOffset, propertiesOffset, columnsOffset) {
778
+ Feature.startFeature(builder);
779
+ Feature.addGeometry(builder, geometryOffset);
780
+ Feature.addProperties(builder, propertiesOffset);
781
+ Feature.addColumns(builder, columnsOffset);
782
+ return Feature.endFeature(builder);
783
+ }
784
+ };
785
+
786
+ // src/flatgeobuf/3.27.2/generic/feature.ts
787
+ var textEncoder = new TextEncoder();
788
+ var textDecoder = new TextDecoder();
789
+ function parseProperties(feature, columns) {
790
+ const properties = {};
791
+ if (!columns || columns.length === 0)
792
+ return properties;
793
+ const array = feature.propertiesArray();
794
+ if (!array)
795
+ return properties;
796
+ const view = new DataView(array.buffer, array.byteOffset);
797
+ const length = feature.propertiesLength();
798
+ let offset = 0;
799
+ while (offset < length) {
800
+ const i = view.getUint16(offset, true);
801
+ offset += 2;
802
+ const column = columns[i];
803
+ const name = column.name;
804
+ switch (column.type) {
805
+ case 2 /* Bool */: {
806
+ properties[name] = Boolean(view.getUint8(offset));
807
+ offset += 1;
808
+ break;
809
+ }
810
+ case 0 /* Byte */: {
811
+ properties[name] = view.getInt8(offset);
812
+ offset += 1;
813
+ break;
814
+ }
815
+ case 1 /* UByte */: {
816
+ properties[name] = view.getUint8(offset);
817
+ offset += 1;
818
+ break;
819
+ }
820
+ case 3 /* Short */: {
821
+ properties[name] = view.getInt16(offset, true);
822
+ offset += 2;
823
+ break;
824
+ }
825
+ case 4 /* UShort */: {
826
+ properties[name] = view.getUint16(offset, true);
827
+ offset += 2;
828
+ break;
829
+ }
830
+ case 5 /* Int */: {
831
+ properties[name] = view.getInt32(offset, true);
832
+ offset += 4;
833
+ break;
834
+ }
835
+ case 6 /* UInt */: {
836
+ properties[name] = view.getUint32(offset, true);
837
+ offset += 4;
838
+ break;
839
+ }
840
+ case 7 /* Long */: {
841
+ properties[name] = Number(view.getBigInt64(offset, true));
842
+ offset += 8;
843
+ break;
844
+ }
845
+ case 8 /* ULong */: {
846
+ properties[name] = Number(view.getBigUint64(offset, true));
847
+ offset += 8;
848
+ break;
849
+ }
850
+ case 9 /* Float */: {
851
+ properties[name] = view.getFloat32(offset, true);
852
+ offset += 4;
853
+ break;
854
+ }
855
+ case 10 /* Double */: {
856
+ properties[name] = view.getFloat64(offset, true);
857
+ offset += 8;
858
+ break;
859
+ }
860
+ case 13 /* DateTime */:
861
+ case 11 /* String */: {
862
+ const length2 = view.getUint32(offset, true);
863
+ offset += 4;
864
+ properties[name] = textDecoder.decode(array.subarray(offset, offset + length2));
865
+ offset += length2;
866
+ break;
867
+ }
868
+ case 12 /* Json */: {
869
+ const length2 = view.getUint32(offset, true);
870
+ offset += 4;
871
+ const str = textDecoder.decode(array.subarray(offset, offset + length2));
872
+ properties[name] = JSON.parse(str);
873
+ offset += length2;
874
+ break;
875
+ }
876
+ default:
877
+ throw new Error(`Unknown type ${column.type}`);
878
+ }
879
+ }
880
+ return properties;
881
+ }
882
+
883
+ // src/flatgeobuf/3.27.2/geojson/feature.ts
884
+ function fromFeature(feature, header) {
885
+ const columns = header.columns;
886
+ const geometry = fromGeometry(feature.geometry(), header.geometryType);
887
+ const geoJsonfeature = {
888
+ type: "Feature",
889
+ geometry,
890
+ properties: parseProperties(feature, columns)
891
+ };
892
+ return geoJsonfeature;
893
+ }
894
+
895
+ // src/flatgeobuf/3.27.2/generic/featurecollection.ts
896
+ var flatbuffers8 = __toESM(require("flatbuffers"), 1);
897
+ var import_slice_source = __toESM(require("slice-source"), 1);
898
+
899
+ // src/flatgeobuf/3.27.2/flat-geobuf/header.ts
900
+ var flatbuffers6 = __toESM(require("flatbuffers"), 1);
901
+
902
+ // src/flatgeobuf/3.27.2/flat-geobuf/crs.ts
903
+ var flatbuffers5 = __toESM(require("flatbuffers"), 1);
904
+ var Crs = class {
905
+ constructor() {
906
+ this.bb = null;
907
+ this.bb_pos = 0;
908
+ }
909
+ __init(i, bb) {
910
+ this.bb_pos = i;
911
+ this.bb = bb;
912
+ return this;
913
+ }
914
+ static getRootAsCrs(bb, obj) {
915
+ return (obj || new Crs()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
916
+ }
917
+ static getSizePrefixedRootAsCrs(bb, obj) {
918
+ bb.setPosition(bb.position() + flatbuffers5.SIZE_PREFIX_LENGTH);
919
+ return (obj || new Crs()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
920
+ }
921
+ org(optionalEncoding) {
922
+ const offset = this.bb.__offset(this.bb_pos, 4);
923
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
924
+ }
925
+ code() {
926
+ const offset = this.bb.__offset(this.bb_pos, 6);
927
+ return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
928
+ }
929
+ name(optionalEncoding) {
930
+ const offset = this.bb.__offset(this.bb_pos, 8);
931
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
932
+ }
933
+ description(optionalEncoding) {
934
+ const offset = this.bb.__offset(this.bb_pos, 10);
935
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
936
+ }
937
+ wkt(optionalEncoding) {
938
+ const offset = this.bb.__offset(this.bb_pos, 12);
939
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
940
+ }
941
+ codeString(optionalEncoding) {
942
+ const offset = this.bb.__offset(this.bb_pos, 14);
943
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
944
+ }
945
+ static startCrs(builder) {
946
+ builder.startObject(6);
947
+ }
948
+ static addOrg(builder, orgOffset) {
949
+ builder.addFieldOffset(0, orgOffset, 0);
950
+ }
951
+ static addCode(builder, code) {
952
+ builder.addFieldInt32(1, code, 0);
953
+ }
954
+ static addName(builder, nameOffset) {
955
+ builder.addFieldOffset(2, nameOffset, 0);
956
+ }
957
+ static addDescription(builder, descriptionOffset) {
958
+ builder.addFieldOffset(3, descriptionOffset, 0);
959
+ }
960
+ static addWkt(builder, wktOffset) {
961
+ builder.addFieldOffset(4, wktOffset, 0);
962
+ }
963
+ static addCodeString(builder, codeStringOffset) {
964
+ builder.addFieldOffset(5, codeStringOffset, 0);
965
+ }
966
+ static endCrs(builder) {
967
+ const offset = builder.endObject();
968
+ return offset;
969
+ }
970
+ static createCrs(builder, orgOffset, code, nameOffset, descriptionOffset, wktOffset, codeStringOffset) {
971
+ Crs.startCrs(builder);
972
+ Crs.addOrg(builder, orgOffset);
973
+ Crs.addCode(builder, code);
974
+ Crs.addName(builder, nameOffset);
975
+ Crs.addDescription(builder, descriptionOffset);
976
+ Crs.addWkt(builder, wktOffset);
977
+ Crs.addCodeString(builder, codeStringOffset);
978
+ return Crs.endCrs(builder);
979
+ }
980
+ };
981
+
982
+ // src/flatgeobuf/3.27.2/flat-geobuf/header.ts
983
+ var Header = class {
984
+ constructor() {
985
+ this.bb = null;
986
+ this.bb_pos = 0;
987
+ }
988
+ __init(i, bb) {
989
+ this.bb_pos = i;
990
+ this.bb = bb;
991
+ return this;
992
+ }
993
+ static getRootAsHeader(bb, obj) {
994
+ return (obj || new Header()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
995
+ }
996
+ static getSizePrefixedRootAsHeader(bb, obj) {
997
+ bb.setPosition(bb.position() + flatbuffers6.SIZE_PREFIX_LENGTH);
998
+ return (obj || new Header()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
999
+ }
1000
+ name(optionalEncoding) {
1001
+ const offset = this.bb.__offset(this.bb_pos, 4);
1002
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
1003
+ }
1004
+ envelope(index) {
1005
+ const offset = this.bb.__offset(this.bb_pos, 6);
1006
+ return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0;
1007
+ }
1008
+ envelopeLength() {
1009
+ const offset = this.bb.__offset(this.bb_pos, 6);
1010
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
1011
+ }
1012
+ envelopeArray() {
1013
+ const offset = this.bb.__offset(this.bb_pos, 6);
1014
+ return offset ? new Float64Array(
1015
+ this.bb.bytes().buffer,
1016
+ this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset),
1017
+ this.bb.__vector_len(this.bb_pos + offset)
1018
+ ) : null;
1019
+ }
1020
+ geometryType() {
1021
+ const offset = this.bb.__offset(this.bb_pos, 8);
1022
+ return offset ? this.bb.readUint8(this.bb_pos + offset) : 0 /* Unknown */;
1023
+ }
1024
+ hasZ() {
1025
+ const offset = this.bb.__offset(this.bb_pos, 10);
1026
+ return offset ? Boolean(this.bb.readInt8(this.bb_pos + offset)) : false;
1027
+ }
1028
+ hasM() {
1029
+ const offset = this.bb.__offset(this.bb_pos, 12);
1030
+ return offset ? Boolean(this.bb.readInt8(this.bb_pos + offset)) : false;
1031
+ }
1032
+ hasT() {
1033
+ const offset = this.bb.__offset(this.bb_pos, 14);
1034
+ return offset ? Boolean(this.bb.readInt8(this.bb_pos + offset)) : false;
1035
+ }
1036
+ hasTm() {
1037
+ const offset = this.bb.__offset(this.bb_pos, 16);
1038
+ return offset ? Boolean(this.bb.readInt8(this.bb_pos + offset)) : false;
1039
+ }
1040
+ columns(index, obj) {
1041
+ const offset = this.bb.__offset(this.bb_pos, 18);
1042
+ return offset ? (obj || new Column()).__init(
1043
+ this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4),
1044
+ this.bb
1045
+ ) : null;
1046
+ }
1047
+ columnsLength() {
1048
+ const offset = this.bb.__offset(this.bb_pos, 18);
1049
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
1050
+ }
1051
+ featuresCount() {
1052
+ const offset = this.bb.__offset(this.bb_pos, 20);
1053
+ return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt("0");
1054
+ }
1055
+ indexNodeSize() {
1056
+ const offset = this.bb.__offset(this.bb_pos, 22);
1057
+ return offset ? this.bb.readUint16(this.bb_pos + offset) : 16;
1058
+ }
1059
+ crs(obj) {
1060
+ const offset = this.bb.__offset(this.bb_pos, 24);
1061
+ return offset ? (obj || new Crs()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
1062
+ }
1063
+ title(optionalEncoding) {
1064
+ const offset = this.bb.__offset(this.bb_pos, 26);
1065
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
1066
+ }
1067
+ description(optionalEncoding) {
1068
+ const offset = this.bb.__offset(this.bb_pos, 28);
1069
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
1070
+ }
1071
+ metadata(optionalEncoding) {
1072
+ const offset = this.bb.__offset(this.bb_pos, 30);
1073
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
1074
+ }
1075
+ static startHeader(builder) {
1076
+ builder.startObject(14);
1077
+ }
1078
+ static addName(builder, nameOffset) {
1079
+ builder.addFieldOffset(0, nameOffset, 0);
1080
+ }
1081
+ static addEnvelope(builder, envelopeOffset) {
1082
+ builder.addFieldOffset(1, envelopeOffset, 0);
1083
+ }
1084
+ static createEnvelopeVector(builder, data) {
1085
+ builder.startVector(8, data.length, 8);
1086
+ for (let i = data.length - 1; i >= 0; i--) {
1087
+ builder.addFloat64(data[i]);
1088
+ }
1089
+ return builder.endVector();
1090
+ }
1091
+ static startEnvelopeVector(builder, numElems) {
1092
+ builder.startVector(8, numElems, 8);
1093
+ }
1094
+ static addGeometryType(builder, geometryType) {
1095
+ builder.addFieldInt8(2, geometryType, 0 /* Unknown */);
1096
+ }
1097
+ static addHasZ(builder, hasZ) {
1098
+ builder.addFieldInt8(3, Number(hasZ), Number(false));
1099
+ }
1100
+ static addHasM(builder, hasM) {
1101
+ builder.addFieldInt8(4, Number(hasM), Number(false));
1102
+ }
1103
+ static addHasT(builder, hasT) {
1104
+ builder.addFieldInt8(5, Number(hasT), Number(false));
1105
+ }
1106
+ static addHasTm(builder, hasTm) {
1107
+ builder.addFieldInt8(6, Number(hasTm), Number(false));
1108
+ }
1109
+ static addColumns(builder, columnsOffset) {
1110
+ builder.addFieldOffset(7, columnsOffset, 0);
1111
+ }
1112
+ static createColumnsVector(builder, data) {
1113
+ builder.startVector(4, data.length, 4);
1114
+ for (let i = data.length - 1; i >= 0; i--) {
1115
+ builder.addOffset(data[i]);
1116
+ }
1117
+ return builder.endVector();
1118
+ }
1119
+ static startColumnsVector(builder, numElems) {
1120
+ builder.startVector(4, numElems, 4);
1121
+ }
1122
+ static addFeaturesCount(builder, featuresCount) {
1123
+ builder.addFieldInt64(8, featuresCount, BigInt("0"));
1124
+ }
1125
+ static addIndexNodeSize(builder, indexNodeSize) {
1126
+ builder.addFieldInt16(9, indexNodeSize, 16);
1127
+ }
1128
+ static addCrs(builder, crsOffset) {
1129
+ builder.addFieldOffset(10, crsOffset, 0);
1130
+ }
1131
+ static addTitle(builder, titleOffset) {
1132
+ builder.addFieldOffset(11, titleOffset, 0);
1133
+ }
1134
+ static addDescription(builder, descriptionOffset) {
1135
+ builder.addFieldOffset(12, descriptionOffset, 0);
1136
+ }
1137
+ static addMetadata(builder, metadataOffset) {
1138
+ builder.addFieldOffset(13, metadataOffset, 0);
1139
+ }
1140
+ static endHeader(builder) {
1141
+ const offset = builder.endObject();
1142
+ return offset;
1143
+ }
1144
+ static finishHeaderBuffer(builder, offset) {
1145
+ builder.finish(offset);
1146
+ }
1147
+ static finishSizePrefixedHeaderBuffer(builder, offset) {
1148
+ builder.finish(offset, void 0, true);
1149
+ }
1150
+ };
1151
+
1152
+ // src/flatgeobuf/3.27.2/header-meta.ts
1153
+ function fromByteBuffer(bb) {
1154
+ const header = Header.getRootAsHeader(bb);
1155
+ const featuresCount = header.featuresCount();
1156
+ const indexNodeSize = header.indexNodeSize();
1157
+ const columns = [];
1158
+ for (let j = 0; j < header.columnsLength(); j++) {
1159
+ const column = header.columns(j);
1160
+ if (!column)
1161
+ throw new Error("Column unexpectedly missing");
1162
+ if (!column.name())
1163
+ throw new Error("Column name unexpectedly missing");
1164
+ columns.push({
1165
+ name: column.name(),
1166
+ type: column.type(),
1167
+ title: column.title(),
1168
+ description: column.description(),
1169
+ width: column.width(),
1170
+ precision: column.precision(),
1171
+ scale: column.scale(),
1172
+ nullable: column.nullable(),
1173
+ unique: column.unique(),
1174
+ primary_key: column.primaryKey()
1175
+ });
1176
+ }
1177
+ const crs = header.crs();
1178
+ const crsMeta = crs ? {
1179
+ org: crs.org(),
1180
+ code: crs.code(),
1181
+ name: crs.name(),
1182
+ description: crs.description(),
1183
+ wkt: crs.wkt(),
1184
+ code_string: crs.codeString()
1185
+ } : null;
1186
+ const headerMeta = {
1187
+ geometryType: header.geometryType(),
1188
+ columns,
1189
+ envelope: null,
1190
+ featuresCount: Number(featuresCount),
1191
+ indexNodeSize,
1192
+ crs: crsMeta,
1193
+ title: header.title(),
1194
+ description: header.description(),
1195
+ metadata: header.metadata()
1196
+ };
1197
+ return headerMeta;
1198
+ }
1199
+
1200
+ // src/flatgeobuf/3.27.2/http-reader.ts
1201
+ var flatbuffers7 = __toESM(require("flatbuffers"), 1);
1202
+ var import_repeater = require("@repeaterjs/repeater");
1203
+
1204
+ // src/flatgeobuf/3.27.2/config.ts
1205
+ var _Config = class {
1206
+ constructor() {
1207
+ this._extraRequestThreshold = 256 * 1024;
1208
+ }
1209
+ /**
1210
+ * Fetch up to this many extra bytes if it will eliminate an extra request
1211
+ */
1212
+ extraRequestThreshold() {
1213
+ return this._extraRequestThreshold;
1214
+ }
1215
+ setExtraRequestThreshold(bytes) {
1216
+ if (bytes < 0) {
1217
+ throw new Error("extraRequestThreshold cannot be negative");
1218
+ }
1219
+ this._extraRequestThreshold = bytes;
1220
+ }
1221
+ };
1222
+ var Config = _Config;
1223
+ Config.global = new _Config();
1224
+
1225
+ // src/flatgeobuf/3.27.2/logger.ts
1226
+ var Logger = class {
1227
+ static debug(...args) {
1228
+ this.log(0 /* Debug */, ...args);
1229
+ }
1230
+ static info(...args) {
1231
+ this.log(1 /* Info */, ...args);
1232
+ }
1233
+ static warn(...args) {
1234
+ this.log(2 /* Warn */, ...args);
1235
+ }
1236
+ static error(...args) {
1237
+ this.log(3 /* Error */, ...args);
1238
+ }
1239
+ static log(level, ...args) {
1240
+ if (this.logLevel > level) {
1241
+ return;
1242
+ }
1243
+ switch (level) {
1244
+ case 0 /* Debug */: {
1245
+ console.debug(...args);
1246
+ break;
1247
+ }
1248
+ case 1 /* Info */: {
1249
+ console.info(...args);
1250
+ break;
1251
+ }
1252
+ case 2 /* Warn */: {
1253
+ console.warn(...args);
1254
+ break;
1255
+ }
1256
+ case 3 /* Error */: {
1257
+ console.error(...args);
1258
+ break;
1259
+ }
1260
+ }
1261
+ }
1262
+ };
1263
+ Logger.logLevel = 2 /* Warn */;
1264
+
1265
+ // src/flatgeobuf/3.27.2/packedrtree.ts
1266
+ var NODE_ITEM_BYTE_LEN = 8 * 4 + 8;
1267
+ var DEFAULT_NODE_SIZE = 16;
1268
+ function calcTreeSize(numItems, nodeSize) {
1269
+ nodeSize = Math.min(Math.max(Number(nodeSize), 2), 65535);
1270
+ let n = numItems;
1271
+ let numNodes = n;
1272
+ do {
1273
+ n = Math.ceil(n / nodeSize);
1274
+ numNodes += n;
1275
+ } while (n !== 1);
1276
+ return numNodes * NODE_ITEM_BYTE_LEN;
1277
+ }
1278
+ function generateLevelBounds(numItems, nodeSize) {
1279
+ if (nodeSize < 2)
1280
+ throw new Error("Node size must be at least 2");
1281
+ if (numItems === 0)
1282
+ throw new Error("Number of items must be greater than 0");
1283
+ let n = numItems;
1284
+ let numNodes = n;
1285
+ const levelNumNodes = [n];
1286
+ do {
1287
+ n = Math.ceil(n / nodeSize);
1288
+ numNodes += n;
1289
+ levelNumNodes.push(n);
1290
+ } while (n !== 1);
1291
+ const levelOffsets = [];
1292
+ n = numNodes;
1293
+ for (const size of levelNumNodes) {
1294
+ levelOffsets.push(n - size);
1295
+ n -= size;
1296
+ }
1297
+ const levelBounds = [];
1298
+ for (let i = 0; i < levelNumNodes.length; i++)
1299
+ levelBounds.push([levelOffsets[i], levelOffsets[i] + levelNumNodes[i]]);
1300
+ return levelBounds;
1301
+ }
1302
+ async function* streamSearch(numItems, nodeSize, rect, readNode) {
1303
+ class NodeRange {
1304
+ constructor(nodes, level) {
1305
+ this._level = level;
1306
+ this.nodes = nodes;
1307
+ }
1308
+ level() {
1309
+ return this._level;
1310
+ }
1311
+ startNodeIdx() {
1312
+ return this.nodes[0];
1313
+ }
1314
+ endNodeIdx() {
1315
+ return this.nodes[1];
1316
+ }
1317
+ extendEndNodeIdx(newIdx) {
1318
+ console.assert(newIdx > this.nodes[1]);
1319
+ this.nodes[1] = newIdx;
1320
+ }
1321
+ toString() {
1322
+ return `[NodeRange level: ${this._level}, nodes: ${this.nodes[0]}-${this.nodes[1]}]`;
1323
+ }
1324
+ }
1325
+ const { minX, minY, maxX, maxY } = rect;
1326
+ Logger.info(`tree items: ${numItems}, nodeSize: ${nodeSize}`);
1327
+ const levelBounds = generateLevelBounds(numItems, nodeSize);
1328
+ const firstLeafNodeIdx = levelBounds[0][0];
1329
+ const rootNodeRange = (() => {
1330
+ const range = [0, 1];
1331
+ const level = levelBounds.length - 1;
1332
+ return new NodeRange(range, level);
1333
+ })();
1334
+ const queue = [rootNodeRange];
1335
+ Logger.debug(
1336
+ `starting stream search with queue: ${queue}, numItems: ${numItems}, nodeSize: ${nodeSize}, levelBounds: ${levelBounds}`
1337
+ );
1338
+ while (queue.length != 0) {
1339
+ const nodeRange = queue.shift();
1340
+ Logger.debug(`popped node: ${nodeRange}, queueLength: ${queue.length}`);
1341
+ const nodeRangeStartIdx = nodeRange.startNodeIdx();
1342
+ const isLeafNode = nodeRangeStartIdx >= firstLeafNodeIdx;
1343
+ const nodeRangeEndIdx = (() => {
1344
+ const [, levelBound] = levelBounds[nodeRange.level()];
1345
+ const nodeIdx = Math.min(nodeRange.endNodeIdx() + nodeSize, levelBound);
1346
+ if (isLeafNode && nodeIdx < levelBound) {
1347
+ return nodeIdx + 1;
1348
+ }
1349
+ return nodeIdx;
1350
+ })();
1351
+ const numNodesInRange = nodeRangeEndIdx - nodeRangeStartIdx;
1352
+ const buffer = await readNode(
1353
+ nodeRangeStartIdx * NODE_ITEM_BYTE_LEN,
1354
+ numNodesInRange * NODE_ITEM_BYTE_LEN
1355
+ );
1356
+ const dataView = new DataView(buffer);
1357
+ for (let nodeIdx = nodeRangeStartIdx; nodeIdx < nodeRangeEndIdx; nodeIdx++) {
1358
+ const nodeIdxInDataView = nodeIdx - nodeRangeStartIdx;
1359
+ const dataViewByteStart = nodeIdxInDataView * NODE_ITEM_BYTE_LEN;
1360
+ if (maxX < dataView.getFloat64(dataViewByteStart + 0, true))
1361
+ continue;
1362
+ if (maxY < dataView.getFloat64(dataViewByteStart + 8, true))
1363
+ continue;
1364
+ if (minX > dataView.getFloat64(dataViewByteStart + 16, true))
1365
+ continue;
1366
+ if (minY > dataView.getFloat64(dataViewByteStart + 24, true))
1367
+ continue;
1368
+ const offset = dataView.getBigUint64(dataViewByteStart + 32, true);
1369
+ if (isLeafNode) {
1370
+ const featureByteOffset = offset;
1371
+ const featureLength = (() => {
1372
+ if (nodeIdx < numItems - 1) {
1373
+ const nextPos = (nodeIdxInDataView + 1) * NODE_ITEM_BYTE_LEN;
1374
+ const nextOffset = dataView.getBigUint64(nextPos + 32, true);
1375
+ return nextOffset - featureByteOffset;
1376
+ }
1377
+ return null;
1378
+ })();
1379
+ const featureIdx = nodeIdx - firstLeafNodeIdx;
1380
+ yield [Number(featureByteOffset), featureIdx, Number(featureLength)];
1381
+ continue;
1382
+ }
1383
+ const firstChildNodeIdx = offset;
1384
+ const extraRequestThresholdNodes = Config.global.extraRequestThreshold() / NODE_ITEM_BYTE_LEN;
1385
+ const nearestNodeRange = queue[queue.length - 1];
1386
+ if (nearestNodeRange !== void 0 && nearestNodeRange.level() == nodeRange.level() - 1 && firstChildNodeIdx < nearestNodeRange.endNodeIdx() + extraRequestThresholdNodes) {
1387
+ Logger.debug(
1388
+ `Merging "nodeRange" request into existing range: ${nearestNodeRange}, newEndNodeIdx: ${nearestNodeRange.endNodeIdx()} -> ${firstChildNodeIdx}`
1389
+ );
1390
+ nearestNodeRange.extendEndNodeIdx(Number(firstChildNodeIdx));
1391
+ continue;
1392
+ }
1393
+ const newNodeRange = (() => {
1394
+ const level = nodeRange.level() - 1;
1395
+ const range = [Number(firstChildNodeIdx), Number(firstChildNodeIdx) + 1];
1396
+ return new NodeRange(range, level);
1397
+ })();
1398
+ if (nearestNodeRange !== void 0 && nearestNodeRange.level() == newNodeRange.level()) {
1399
+ Logger.info(
1400
+ `Same level, but too far away. Pushing new request for nodeIdx: ${firstChildNodeIdx} rather than merging with distant ${nearestNodeRange}`
1401
+ );
1402
+ } else {
1403
+ Logger.info(
1404
+ `Pushing new level for ${newNodeRange} onto queue with nearestNodeRange: ${nearestNodeRange} since there's not already a range for this level.`
1405
+ );
1406
+ }
1407
+ queue.push(newNodeRange);
1408
+ }
1409
+ }
1410
+ }
1411
+
1412
+ // src/flatgeobuf/3.27.2/constants.ts
1413
+ var magicbytes = new Uint8Array([
1414
+ 102,
1415
+ 103,
1416
+ 98,
1417
+ 3,
1418
+ 102,
1419
+ 103,
1420
+ 98,
1421
+ 0
1422
+ ]);
1423
+ var SIZE_PREFIX_LEN = 4;
1424
+
1425
+ // src/flatgeobuf/3.27.2/http-reader.ts
1426
+ var HttpReader = class {
1427
+ constructor(headerClient, header, headerLength, indexLength) {
1428
+ this.headerClient = headerClient;
1429
+ this.header = header;
1430
+ this.headerLength = headerLength;
1431
+ this.indexLength = indexLength;
1432
+ }
1433
+ // Fetch the header, preparing the reader to read Feature data.
1434
+ //
1435
+ // and potentially some opportunistic fetching of the index.
1436
+ static async open(url) {
1437
+ const assumedHeaderLength = 2024;
1438
+ const headerClient = new BufferedHttpRangeClient(url);
1439
+ const assumedIndexLength = (() => {
1440
+ const assumedBranchingFactor = DEFAULT_NODE_SIZE;
1441
+ const prefetchedLayers = 3;
1442
+ let result = 0;
1443
+ let i;
1444
+ for (i = 0; i < prefetchedLayers; i++) {
1445
+ const layer_width = assumedBranchingFactor ** i * NODE_ITEM_BYTE_LEN;
1446
+ result += layer_width;
1447
+ }
1448
+ return result;
1449
+ })();
1450
+ const minReqLength = assumedHeaderLength + assumedIndexLength;
1451
+ Logger.debug(
1452
+ `fetching header. minReqLength: ${minReqLength} (assumedHeaderLength: ${assumedHeaderLength}, assumedIndexLength: ${assumedIndexLength})`
1453
+ );
1454
+ {
1455
+ const bytes2 = new Uint8Array(await headerClient.getRange(0, 8, minReqLength, "header"));
1456
+ if (!bytes2.subarray(0, 3).every((v, i) => magicbytes[i] === v)) {
1457
+ Logger.error(`bytes: ${bytes2} != ${magicbytes}`);
1458
+ throw new Error("Not a FlatGeobuf file");
1459
+ }
1460
+ Logger.debug("magic bytes look good");
1461
+ }
1462
+ let headerLength;
1463
+ {
1464
+ const bytes2 = await headerClient.getRange(8, 4, minReqLength, "header");
1465
+ headerLength = new DataView(bytes2).getUint32(0, true);
1466
+ const HEADER_MAX_BUFFER_SIZE = 1048576 * 10;
1467
+ if (headerLength > HEADER_MAX_BUFFER_SIZE || headerLength < 8) {
1468
+ throw new Error("Invalid header size");
1469
+ }
1470
+ Logger.debug(`headerLength: ${headerLength}`);
1471
+ }
1472
+ const bytes = await headerClient.getRange(12, headerLength, minReqLength, "header");
1473
+ const bb = new flatbuffers7.ByteBuffer(new Uint8Array(bytes));
1474
+ const header = fromByteBuffer(bb);
1475
+ const indexLength = calcTreeSize(header.featuresCount, header.indexNodeSize);
1476
+ Logger.debug("completed: opening http reader");
1477
+ return new HttpReader(headerClient, header, headerLength, indexLength);
1478
+ }
1479
+ async *selectBbox(rect) {
1480
+ const lengthBeforeTree = this.lengthBeforeTree();
1481
+ const bufferedClient = this.headerClient;
1482
+ const readNode = async function(offsetIntoTree, size) {
1483
+ const minReqLength = 0;
1484
+ return bufferedClient.getRange(
1485
+ lengthBeforeTree + offsetIntoTree,
1486
+ size,
1487
+ minReqLength,
1488
+ "index"
1489
+ );
1490
+ };
1491
+ const batches = [];
1492
+ let currentBatch = [];
1493
+ for await (const searchResult of streamSearch(
1494
+ this.header.featuresCount,
1495
+ this.header.indexNodeSize,
1496
+ rect,
1497
+ readNode
1498
+ )) {
1499
+ const [featureOffset, ,] = searchResult;
1500
+ let [, , featureLength] = searchResult;
1501
+ if (!featureLength) {
1502
+ Logger.info("final feature");
1503
+ featureLength = 4;
1504
+ }
1505
+ if (currentBatch.length == 0) {
1506
+ currentBatch.push([featureOffset, featureLength]);
1507
+ continue;
1508
+ }
1509
+ const prevFeature = currentBatch[currentBatch.length - 1];
1510
+ const gap = featureOffset - (prevFeature[0] + prevFeature[1]);
1511
+ if (gap > Config.global.extraRequestThreshold()) {
1512
+ Logger.info(`Pushing new feature batch, since gap ${gap} was too large`);
1513
+ batches.push(currentBatch);
1514
+ currentBatch = [];
1515
+ }
1516
+ currentBatch.push([featureOffset, featureLength]);
1517
+ }
1518
+ this.headerClient.logUsage("header+index");
1519
+ if (currentBatch.length > 0) {
1520
+ batches.push(currentBatch);
1521
+ }
1522
+ const promises = batches.flatMap(
1523
+ (batch) => this.readFeatureBatch(batch)
1524
+ );
1525
+ yield* import_repeater.Repeater.merge(promises);
1526
+ }
1527
+ lengthBeforeTree() {
1528
+ return magicbytes.length + SIZE_PREFIX_LEN + this.headerLength;
1529
+ }
1530
+ lengthBeforeFeatures() {
1531
+ return this.lengthBeforeTree() + this.indexLength;
1532
+ }
1533
+ buildFeatureClient() {
1534
+ return new BufferedHttpRangeClient(this.headerClient.httpClient);
1535
+ }
1536
+ /**
1537
+ * Fetch a batch of features in a single request, yielding each Feature
1538
+ *
1539
+ * `batch`: [offset, length] of features in the batch
1540
+ */
1541
+ async *readFeatureBatch(batch) {
1542
+ const [firstFeatureOffset] = batch[0];
1543
+ const [lastFeatureOffset, lastFeatureLength] = batch[batch.length - 1];
1544
+ const batchStart = firstFeatureOffset;
1545
+ const batchEnd = lastFeatureOffset + lastFeatureLength;
1546
+ const batchSize = batchEnd - batchStart;
1547
+ const featureClient = this.buildFeatureClient();
1548
+ let minFeatureReqLength = batchSize;
1549
+ for (const [featureOffset] of batch) {
1550
+ yield await this.readFeature(featureClient, featureOffset, minFeatureReqLength);
1551
+ minFeatureReqLength = 0;
1552
+ }
1553
+ featureClient.logUsage("feature");
1554
+ }
1555
+ async readFeature(featureClient, featureOffset, minFeatureReqLength) {
1556
+ const offset = featureOffset + this.lengthBeforeFeatures();
1557
+ let featureLength;
1558
+ {
1559
+ const bytes2 = await featureClient.getRange(offset, 4, minFeatureReqLength, "feature length");
1560
+ featureLength = new DataView(bytes2).getUint32(0, true);
1561
+ }
1562
+ const byteBuffer = await featureClient.getRange(
1563
+ offset + 4,
1564
+ featureLength,
1565
+ minFeatureReqLength,
1566
+ "feature data"
1567
+ );
1568
+ const bytes = new Uint8Array(byteBuffer);
1569
+ const bytesAligned = new Uint8Array(featureLength + SIZE_PREFIX_LEN);
1570
+ bytesAligned.set(bytes, SIZE_PREFIX_LEN);
1571
+ const bb = new flatbuffers7.ByteBuffer(bytesAligned);
1572
+ bb.setPosition(SIZE_PREFIX_LEN);
1573
+ return Feature.getRootAsFeature(bb);
1574
+ }
1575
+ };
1576
+ var BufferedHttpRangeClient = class {
1577
+ constructor(source) {
1578
+ this.bytesEverUsed = 0;
1579
+ this.bytesEverFetched = 0;
1580
+ this.buffer = new ArrayBuffer(0);
1581
+ // Byte offset of `buffer` with respect to the beginning of the file being
1582
+ // buffered
1583
+ this.head = 0;
1584
+ if (typeof source === "string") {
1585
+ this.httpClient = new HttpRangeClient(source);
1586
+ } else if (source instanceof HttpRangeClient) {
1587
+ this.httpClient = source;
1588
+ } else {
1589
+ throw new Error("Unknown source ");
1590
+ }
1591
+ }
1592
+ async getRange(start, length, minReqLength, purpose) {
1593
+ this.bytesEverUsed += length;
1594
+ const start_i = start - this.head;
1595
+ const end_i = start_i + length;
1596
+ if (start_i >= 0 && end_i <= this.buffer.byteLength) {
1597
+ return this.buffer.slice(start_i, end_i);
1598
+ }
1599
+ const lengthToFetch = Math.max(length, minReqLength);
1600
+ this.bytesEverFetched += lengthToFetch;
1601
+ Logger.debug(`requesting for new Range: ${start}-${start + lengthToFetch - 1}`);
1602
+ this.buffer = await this.httpClient.getRange(start, lengthToFetch, purpose);
1603
+ this.head = start;
1604
+ return this.buffer.slice(0, length);
1605
+ }
1606
+ logUsage(purpose) {
1607
+ const category = purpose.split(" ")[0];
1608
+ const used = this.bytesEverUsed;
1609
+ const requested = this.bytesEverFetched;
1610
+ const efficiency = (100 * used / requested).toFixed(2);
1611
+ Logger.info(`${category} bytes used/requested: ${used} / ${requested} = ${efficiency}%`);
1612
+ }
1613
+ };
1614
+ var HttpRangeClient = class {
1615
+ constructor(url) {
1616
+ this.requestsEverMade = 0;
1617
+ this.bytesEverRequested = 0;
1618
+ this.url = url;
1619
+ }
1620
+ async getRange(begin, length, purpose) {
1621
+ this.requestsEverMade += 1;
1622
+ this.bytesEverRequested += length;
1623
+ const range = `bytes=${begin}-${begin + length - 1}`;
1624
+ Logger.info(
1625
+ `request: #${this.requestsEverMade}, purpose: ${purpose}), bytes: (this_request: ${length}, ever: ${this.bytesEverRequested}), Range: ${range}`
1626
+ );
1627
+ const response = await fetch(this.url, {
1628
+ headers: {
1629
+ Range: range
1630
+ // TODO: better parallelize requests on Chrome
1631
+ //
1632
+ // Safari and Firefox have no issue performing Range requests
1633
+ // for a resource in parallel, but Chrome will stall a
1634
+ // subsequent request to the resource until it's received the
1635
+ // response headers of the prior request. So, it still allows
1636
+ // some limited parallelization, but it's not ideal.
1637
+ //
1638
+ // This is seemingly an artifact of how Chrome manages caching
1639
+ // and it might differ between platforms. We could work around it
1640
+ // by setting the request header:
1641
+ //
1642
+ // 'Cache-Control': 'no-cache, no-store'
1643
+ //
1644
+ // This allows requests to be fully parallelized in Chrome, but
1645
+ // then Chrome won't cache the response, so it seems not a
1646
+ // great trade-off.
1647
+ //
1648
+ // Another work around would be to make each Range request for
1649
+ // a separate URL by appending something like
1650
+ // `?cache_buster=<range>` to the URL, but then Chrome will
1651
+ // require an additional CORS preflight OPTIONS requests per
1652
+ // Range, which is also not a great trade-off.
1653
+ //
1654
+ // See:
1655
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=969828&q=concurrent%20range%20requests&can=2
1656
+ // https://stackoverflow.com/questions/27513994/chrome-stalls-when-making-multiple-requests-to-same-resource
1657
+ }
1658
+ });
1659
+ return response.arrayBuffer();
1660
+ }
1661
+ };
1662
+
1663
+ // src/flatgeobuf/3.27.2/generic/featurecollection.ts
1664
+ function deserialize(bytes, fromFeature2, headerMetaFn) {
1665
+ if (!bytes.subarray(0, 3).every((v, i) => magicbytes[i] === v))
1666
+ throw new Error("Not a FlatGeobuf file");
1667
+ const bb = new flatbuffers8.ByteBuffer(bytes);
1668
+ const headerLength = bb.readUint32(magicbytes.length);
1669
+ bb.setPosition(magicbytes.length + SIZE_PREFIX_LEN);
1670
+ const headerMeta = fromByteBuffer(bb);
1671
+ if (headerMetaFn)
1672
+ headerMetaFn(headerMeta);
1673
+ let offset = magicbytes.length + SIZE_PREFIX_LEN + headerLength;
1674
+ const { indexNodeSize, featuresCount } = headerMeta;
1675
+ if (indexNodeSize > 0)
1676
+ offset += calcTreeSize(featuresCount, indexNodeSize);
1677
+ const features = [];
1678
+ while (offset < bb.capacity()) {
1679
+ const featureLength = bb.readUint32(offset);
1680
+ bb.setPosition(offset + SIZE_PREFIX_LEN);
1681
+ const feature = Feature.getRootAsFeature(bb);
1682
+ features.push(fromFeature2(feature, headerMeta));
1683
+ offset += SIZE_PREFIX_LEN + featureLength;
1684
+ }
1685
+ return features;
1686
+ }
1687
+ async function* deserializeStream(stream, fromFeature2, headerMetaFn) {
1688
+ const reader = (0, import_slice_source.default)(stream);
1689
+ const read = async (size) => await reader.slice(size);
1690
+ let bytes = new Uint8Array(await read(8, "magic bytes"));
1691
+ if (!bytes.subarray(0, 3).every((v, i) => magicbytes[i] === v))
1692
+ throw new Error("Not a FlatGeobuf file");
1693
+ bytes = new Uint8Array(await read(4, "header length"));
1694
+ let bb = new flatbuffers8.ByteBuffer(bytes);
1695
+ const headerLength = bb.readUint32(0);
1696
+ bytes = new Uint8Array(await read(headerLength, "header data"));
1697
+ bb = new flatbuffers8.ByteBuffer(bytes);
1698
+ const headerMeta = fromByteBuffer(bb);
1699
+ if (headerMetaFn)
1700
+ headerMetaFn(headerMeta);
1701
+ const { indexNodeSize, featuresCount } = headerMeta;
1702
+ if (indexNodeSize > 0) {
1703
+ const treeSize = calcTreeSize(featuresCount, indexNodeSize);
1704
+ await read(treeSize, "entire index, w/o rect");
1705
+ }
1706
+ let feature;
1707
+ while (feature = await readFeature(read, headerMeta, fromFeature2))
1708
+ yield feature;
1709
+ }
1710
+ async function* deserializeFiltered(url, rect, fromFeature2, headerMetaFn) {
1711
+ const reader = await HttpReader.open(url);
1712
+ Logger.debug("opened reader");
1713
+ if (headerMetaFn)
1714
+ headerMetaFn(reader.header);
1715
+ for await (const feature of reader.selectBbox(rect)) {
1716
+ yield fromFeature2(feature, reader.header);
1717
+ }
1718
+ }
1719
+ async function readFeature(read, headerMeta, fromFeature2) {
1720
+ let bytes = new Uint8Array(await read(4, "feature length"));
1721
+ if (bytes.byteLength === 0)
1722
+ return;
1723
+ let bb = new flatbuffers8.ByteBuffer(bytes);
1724
+ const featureLength = bb.readUint32(0);
1725
+ bytes = new Uint8Array(await read(featureLength, "feature data"));
1726
+ const bytesAligned = new Uint8Array(featureLength + 4);
1727
+ bytesAligned.set(bytes, 4);
1728
+ bb = new flatbuffers8.ByteBuffer(bytesAligned);
1729
+ bb.setPosition(SIZE_PREFIX_LEN);
1730
+ const feature = Feature.getRootAsFeature(bb);
1731
+ return fromFeature2(feature, headerMeta);
1732
+ }
1733
+
1734
+ // src/flatgeobuf/3.27.2/geojson/featurecollection.ts
1735
+ function deserialize2(bytes, headerMetaFn) {
1736
+ const features = deserialize(bytes, fromFeature, headerMetaFn);
1737
+ return {
1738
+ type: "FeatureCollection",
1739
+ features
1740
+ };
1741
+ }
1742
+ function deserializeStream2(stream, headerMetaFn) {
1743
+ return deserializeStream(stream, fromFeature, headerMetaFn);
1744
+ }
1745
+ function deserializeFiltered2(url, rect, headerMetaFn) {
1746
+ return deserializeFiltered(url, rect, fromFeature, headerMetaFn);
1747
+ }
1748
+
1749
+ // src/flatgeobuf/3.27.2/geojson.ts
1750
+ function deserialize3(input, rect, headerMetaFn) {
1751
+ if (input instanceof Uint8Array)
1752
+ return deserialize2(input, headerMetaFn);
1753
+ else if (input instanceof ReadableStream)
1754
+ return deserializeStream2(input, headerMetaFn);
1755
+ return deserializeFiltered2(input, rect, headerMetaFn);
1756
+ }
1757
+
1758
+ // src/flatgeobuf/3.27.2/generic.ts
1759
+ function deserialize4(input, fromFeature2, rect) {
1760
+ if (input instanceof Uint8Array)
1761
+ return deserialize(input, fromFeature2);
1762
+ else if (input instanceof ReadableStream)
1763
+ return deserializeStream(input, fromFeature2);
1764
+ return deserializeFiltered(input, rect, fromFeature2);
1765
+ }
1766
+
223
1767
  // src/lib/parse-flatgeobuf.ts
224
- var geojson = __toESM(require("flatgeobuf/lib/mjs/geojson.js"), 1);
225
- var generic = __toESM(require("flatgeobuf/lib/mjs/generic.js"), 1);
226
- var import_feature = require("flatgeobuf/lib/mjs/generic/feature");
227
- var deserializeGeoJson = geojson.deserialize;
228
- var deserializeGeneric = generic.deserialize;
1768
+ var deserializeGeoJson = deserialize3;
1769
+ var deserializeGeneric = deserialize4;
229
1770
  function binaryFromFeature(feature, header) {
230
1771
  const geometry = feature.geometry();
231
1772
  const geometryType = header.geometryType || (geometry == null ? void 0 : geometry.type());
232
1773
  const parsedGeometry = fgbToBinaryGeometry(geometry, geometryType);
233
- parsedGeometry.properties = (0, import_feature.parseProperties)(feature, header.columns);
1774
+ parsedGeometry.properties = parseProperties(feature, header.columns);
234
1775
  return parsedGeometry;
235
1776
  }
236
1777
  function parseFlatGeobuf(arrayBuffer, options) {