@loaders.gl/flatgeobuf 4.0.0-alpha.5 → 4.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +123 -24
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/flatgeobuf-loader.js +26 -0
  6. package/dist/es5/flatgeobuf-loader.js.map +1 -0
  7. package/dist/es5/index.js +47 -0
  8. package/dist/es5/index.js.map +1 -0
  9. package/dist/es5/lib/binary-geometries.js +137 -0
  10. package/dist/es5/lib/binary-geometries.js.map +1 -0
  11. package/dist/es5/lib/parse-flatgeobuf.js +189 -0
  12. package/dist/es5/lib/parse-flatgeobuf.js.map +1 -0
  13. package/dist/es5/lib/types.js +2 -0
  14. package/dist/es5/lib/types.js.map +1 -0
  15. package/dist/es5/workers/flatgeobuf-worker.js +6 -0
  16. package/dist/es5/workers/flatgeobuf-worker.js.map +1 -0
  17. package/dist/esm/bundle.js +4 -0
  18. package/dist/esm/bundle.js.map +1 -0
  19. package/dist/esm/flatgeobuf-loader.js +18 -0
  20. package/dist/esm/flatgeobuf-loader.js.map +1 -0
  21. package/dist/esm/index.js +12 -0
  22. package/dist/esm/index.js.map +1 -0
  23. package/dist/esm/lib/binary-geometries.js +126 -0
  24. package/dist/esm/lib/binary-geometries.js.map +1 -0
  25. package/dist/esm/lib/parse-flatgeobuf.js +112 -0
  26. package/dist/esm/lib/parse-flatgeobuf.js.map +1 -0
  27. package/dist/esm/lib/types.js +2 -0
  28. package/dist/esm/lib/types.js.map +1 -0
  29. package/dist/esm/workers/flatgeobuf-worker.js +4 -0
  30. package/dist/esm/workers/flatgeobuf-worker.js.map +1 -0
  31. package/dist/flatgeobuf-loader.d.ts +3 -1
  32. package/dist/flatgeobuf-loader.d.ts.map +1 -1
  33. package/dist/flatgeobuf-loader.js +22 -15
  34. package/dist/flatgeobuf-worker.js +147 -37
  35. package/dist/index.d.ts +7 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +13 -10
  38. package/dist/lib/binary-geometries.js +108 -132
  39. package/dist/lib/parse-flatgeobuf.d.ts +7 -2
  40. package/dist/lib/parse-flatgeobuf.d.ts.map +1 -1
  41. package/dist/lib/parse-flatgeobuf.js +115 -97
  42. package/dist/lib/types.d.ts +13 -0
  43. package/dist/lib/types.d.ts.map +1 -0
  44. package/dist/lib/types.js +2 -0
  45. package/dist/workers/flatgeobuf-worker.js +5 -4
  46. package/package.json +7 -7
  47. package/src/flatgeobuf-loader.ts +4 -1
  48. package/src/lib/parse-flatgeobuf.ts +35 -16
  49. package/src/lib/types.ts +13 -0
  50. package/dist/bundle.js.map +0 -1
  51. package/dist/flatgeobuf-loader.js.map +0 -1
  52. package/dist/index.js.map +0 -1
  53. package/dist/lib/binary-geometries.js.map +0 -1
  54. package/dist/lib/parse-flatgeobuf.js.map +0 -1
  55. package/dist/workers/flatgeobuf-worker.js.map +0 -1
@@ -1,16 +1,23 @@
1
- const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
2
- export const FlatGeobufLoader = {
3
- id: 'flatgeobuf',
4
- name: 'FlatGeobuf',
5
- module: 'flatgeobuf',
6
- version: VERSION,
7
- worker: true,
8
- extensions: ['fgb'],
9
- mimeTypes: ['application/octet-stream'],
10
- category: 'geometry',
11
- options: {
12
- flatgeobuf: {}
13
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._typecheckFlatGeobufLoader = exports.FlatGeobufLoader = void 0;
4
+ // __VERSION__ is injected by babel-plugin-version-inline
5
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
7
+ exports.FlatGeobufLoader = {
8
+ id: 'flatgeobuf',
9
+ name: 'FlatGeobuf',
10
+ module: 'flatgeobuf',
11
+ version: VERSION,
12
+ worker: true,
13
+ extensions: ['fgb'],
14
+ mimeTypes: ['application/octet-stream'],
15
+ category: 'geometry',
16
+ options: {
17
+ flatgeobuf: {
18
+ // Set to GeoJSON for backwards compatibility
19
+ shape: 'geojson'
20
+ }
21
+ }
14
22
  };
15
- export const _typecheckFlatGeobufLoader = FlatGeobufLoader;
16
- //# sourceMappingURL=flatgeobuf-loader.js.map
23
+ exports._typecheckFlatGeobufLoader = exports.FlatGeobufLoader;
@@ -3246,16 +3246,33 @@
3246
3246
  }
3247
3247
 
3248
3248
  // ../worker-utils/src/lib/worker-farm/worker-body.ts
3249
+ function getParentPort() {
3250
+ let parentPort;
3251
+ try {
3252
+ eval("globalThis.parentPort = require('worker_threads').parentPort");
3253
+ parentPort = globalThis.parentPort;
3254
+ } catch {
3255
+ }
3256
+ return parentPort;
3257
+ }
3249
3258
  var onMessageWrapperMap = new Map();
3250
3259
  var WorkerBody = class {
3260
+ static inWorkerThread() {
3261
+ return typeof self !== "undefined" || Boolean(getParentPort());
3262
+ }
3251
3263
  static set onmessage(onMessage) {
3252
- self.onmessage = (message) => {
3253
- if (!isKnownMessage(message)) {
3254
- return;
3255
- }
3256
- const { type, payload } = message.data;
3264
+ function handleMessage(message) {
3265
+ const parentPort3 = getParentPort();
3266
+ const { type, payload } = parentPort3 ? message : message.data;
3257
3267
  onMessage(type, payload);
3258
- };
3268
+ }
3269
+ const parentPort2 = getParentPort();
3270
+ if (parentPort2) {
3271
+ parentPort2.on("message", handleMessage);
3272
+ parentPort2.on("exit", () => console.debug("Node worker closing"));
3273
+ } else {
3274
+ globalThis.onmessage = handleMessage;
3275
+ }
3259
3276
  }
3260
3277
  static addEventListener(onMessage) {
3261
3278
  let onMessageWrapper = onMessageWrapperMap.get(onMessage);
@@ -3264,22 +3281,36 @@
3264
3281
  if (!isKnownMessage(message)) {
3265
3282
  return;
3266
3283
  }
3267
- const { type, payload } = message.data;
3284
+ const parentPort3 = getParentPort();
3285
+ const { type, payload } = parentPort3 ? message : message.data;
3268
3286
  onMessage(type, payload);
3269
3287
  };
3270
3288
  }
3271
- self.addEventListener("message", onMessageWrapper);
3289
+ const parentPort2 = getParentPort();
3290
+ if (parentPort2) {
3291
+ console.error("not implemented");
3292
+ } else {
3293
+ globalThis.addEventListener("message", onMessageWrapper);
3294
+ }
3272
3295
  }
3273
3296
  static removeEventListener(onMessage) {
3274
3297
  const onMessageWrapper = onMessageWrapperMap.get(onMessage);
3275
3298
  onMessageWrapperMap.delete(onMessage);
3276
- self.removeEventListener("message", onMessageWrapper);
3299
+ const parentPort2 = getParentPort();
3300
+ if (parentPort2) {
3301
+ console.error("not implemented");
3302
+ } else {
3303
+ globalThis.removeEventListener("message", onMessageWrapper);
3304
+ }
3277
3305
  }
3278
3306
  static postMessage(type, payload) {
3279
- if (self) {
3280
- const data = { source: "loaders.gl", type, payload };
3281
- const transferList = getTransferList(payload);
3282
- self.postMessage(data, transferList);
3307
+ const data = { source: "loaders.gl", type, payload };
3308
+ const transferList = getTransferList(payload);
3309
+ const parentPort2 = getParentPort();
3310
+ if (parentPort2) {
3311
+ parentPort2.postMessage(data, transferList);
3312
+ } else {
3313
+ globalThis.postMessage(data, transferList);
3283
3314
  }
3284
3315
  }
3285
3316
  };
@@ -3291,19 +3322,20 @@
3291
3322
  // ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
3292
3323
  var requestId = 0;
3293
3324
  function createLoaderWorker(loader) {
3294
- if (typeof self === "undefined") {
3325
+ if (!WorkerBody.inWorkerThread()) {
3295
3326
  return;
3296
3327
  }
3297
3328
  WorkerBody.onmessage = async (type, payload) => {
3298
3329
  switch (type) {
3299
3330
  case "process":
3300
3331
  try {
3301
- const { input, options = {} } = payload;
3332
+ const { input, options = {}, context = {} } = payload;
3302
3333
  const result = await parseData({
3303
3334
  loader,
3304
3335
  arrayBuffer: input,
3305
3336
  options,
3306
3337
  context: {
3338
+ ...context,
3307
3339
  parse: parseOnMainThread
3308
3340
  }
3309
3341
  });
@@ -3362,8 +3394,54 @@
3362
3394
  return await parser(data, { ...options }, context, loader);
3363
3395
  }
3364
3396
 
3397
+ // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
3398
+ function _typeof(obj) {
3399
+ "@babel/helpers - typeof";
3400
+ return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(obj2) {
3401
+ return typeof obj2;
3402
+ } : function(obj2) {
3403
+ return obj2 && typeof Symbol == "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
3404
+ }, _typeof(obj);
3405
+ }
3406
+
3407
+ // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
3408
+ function _toPrimitive(input, hint) {
3409
+ if (_typeof(input) !== "object" || input === null)
3410
+ return input;
3411
+ var prim = input[Symbol.toPrimitive];
3412
+ if (prim !== void 0) {
3413
+ var res = prim.call(input, hint || "default");
3414
+ if (_typeof(res) !== "object")
3415
+ return res;
3416
+ throw new TypeError("@@toPrimitive must return a primitive value.");
3417
+ }
3418
+ return (hint === "string" ? String : Number)(input);
3419
+ }
3420
+
3421
+ // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
3422
+ function _toPropertyKey(arg) {
3423
+ var key = _toPrimitive(arg, "string");
3424
+ return _typeof(key) === "symbol" ? key : String(key);
3425
+ }
3426
+
3427
+ // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
3428
+ function _defineProperty(obj, key, value) {
3429
+ key = _toPropertyKey(key);
3430
+ if (key in obj) {
3431
+ Object.defineProperty(obj, key, {
3432
+ value,
3433
+ enumerable: true,
3434
+ configurable: true,
3435
+ writable: true
3436
+ });
3437
+ } else {
3438
+ obj[key] = value;
3439
+ }
3440
+ return obj;
3441
+ }
3442
+
3365
3443
  // src/flatgeobuf-loader.ts
3366
- var VERSION = true ? "4.0.0-alpha.5" : "latest";
3444
+ var VERSION = true ? "4.0.0-alpha.6" : "latest";
3367
3445
  var FlatGeobufLoader = {
3368
3446
  id: "flatgeobuf",
3369
3447
  name: "FlatGeobuf",
@@ -3374,7 +3452,9 @@
3374
3452
  mimeTypes: ["application/octet-stream"],
3375
3453
  category: "geometry",
3376
3454
  options: {
3377
- flatgeobuf: {}
3455
+ flatgeobuf: {
3456
+ shape: "geojson"
3457
+ }
3378
3458
  }
3379
3459
  };
3380
3460
 
@@ -3587,7 +3667,7 @@
3587
3667
  var ENDED = -1;
3588
3668
  var whitespace = /\s/;
3589
3669
  var latin = /[A-Za-z]/;
3590
- var keyword = /[A-Za-z84]/;
3670
+ var keyword = /[A-Za-z84_]/;
3591
3671
  var endThings = /[,\]]/;
3592
3672
  var digets = /[\d\.E\-\+]/;
3593
3673
  function Parser(text) {
@@ -3885,15 +3965,14 @@
3885
3965
  if (wkt.AXIS) {
3886
3966
  var axisOrder = "";
3887
3967
  for (var i = 0, ii = wkt.AXIS.length; i < ii; ++i) {
3888
- var axis = wkt.AXIS[i];
3889
- var descriptor = axis[0].toLowerCase();
3890
- if (descriptor.indexOf("north") !== -1) {
3968
+ var axis = [wkt.AXIS[i][0].toLowerCase(), wkt.AXIS[i][1].toLowerCase()];
3969
+ if (axis[0].indexOf("north") !== -1 || (axis[0] === "y" || axis[0] === "lat") && axis[1] === "north") {
3891
3970
  axisOrder += "n";
3892
- } else if (descriptor.indexOf("south") !== -1) {
3971
+ } else if (axis[0].indexOf("south") !== -1 || (axis[0] === "y" || axis[0] === "lat") && axis[1] === "south") {
3893
3972
  axisOrder += "s";
3894
- } else if (descriptor.indexOf("east") !== -1) {
3973
+ } else if (axis[0].indexOf("east") !== -1 || (axis[0] === "x" || axis[0] === "lon") && axis[1] === "east") {
3895
3974
  axisOrder += "e";
3896
- } else if (descriptor.indexOf("west") !== -1) {
3975
+ } else if (axis[0].indexOf("west") !== -1 || (axis[0] === "x" || axis[0] === "lon") && axis[1] === "west") {
3897
3976
  axisOrder += "w";
3898
3977
  }
3899
3978
  }
@@ -3989,12 +4068,22 @@
3989
4068
  };
3990
4069
  var list = [
3991
4070
  ["standard_parallel_1", "Standard_Parallel_1"],
4071
+ ["standard_parallel_1", "Latitude of 1st standard parallel"],
3992
4072
  ["standard_parallel_2", "Standard_Parallel_2"],
4073
+ ["standard_parallel_2", "Latitude of 2nd standard parallel"],
3993
4074
  ["false_easting", "False_Easting"],
4075
+ ["false_easting", "False easting"],
4076
+ ["false-easting", "Easting at false origin"],
3994
4077
  ["false_northing", "False_Northing"],
4078
+ ["false_northing", "False northing"],
4079
+ ["false_northing", "Northing at false origin"],
3995
4080
  ["central_meridian", "Central_Meridian"],
4081
+ ["central_meridian", "Longitude of natural origin"],
4082
+ ["central_meridian", "Longitude of false origin"],
3996
4083
  ["latitude_of_origin", "Latitude_Of_Origin"],
3997
4084
  ["latitude_of_origin", "Central_Parallel"],
4085
+ ["latitude_of_origin", "Latitude of natural origin"],
4086
+ ["latitude_of_origin", "Latitude of false origin"],
3998
4087
  ["scale_factor", "Scale_Factor"],
3999
4088
  ["k0", "scale_factor"],
4000
4089
  ["latitude_of_center", "Latitude_Of_Center"],
@@ -8692,7 +8781,7 @@
8692
8781
  projs_default(core_default);
8693
8782
  var lib_default = core_default;
8694
8783
 
8695
- // node_modules/@math.gl/proj4/dist/esm/lib/proj4-projection.js
8784
+ // ../../node_modules/@math.gl/proj4/dist/esm/lib/proj4-projection.js
8696
8785
  var Proj4Projection = class {
8697
8786
  static defineProjectionAliases(aliases) {
8698
8787
  const aliasArray = [];
@@ -8705,12 +8794,19 @@
8705
8794
  from = "WGS84",
8706
8795
  to = "WGS84"
8707
8796
  }) {
8708
- const projection = lib_default(from, to);
8709
- if (!projection) {
8797
+ _defineProperty(this, "_projection", void 0);
8798
+ this._projection = lib_default(from, to);
8799
+ if (!this._projection) {
8710
8800
  throw new Error("Invalid projection");
8711
8801
  }
8712
- this.project = projection.forward;
8713
- this.unproject = projection.inverse;
8802
+ this.project = this.project.bind(this);
8803
+ this.unproject = this.unproject.bind(this);
8804
+ }
8805
+ project(coord) {
8806
+ return this._projection.forward(coord);
8807
+ }
8808
+ unproject(coord) {
8809
+ return this._projection.inverse(coord);
8714
8810
  }
8715
8811
  };
8716
8812
 
@@ -8848,19 +8944,33 @@
8848
8944
  return parsedGeometry;
8849
8945
  }
8850
8946
  function parseFlatGeobuf(arrayBuffer, options) {
8851
- if (arrayBuffer.byteLength === 0) {
8852
- return [];
8853
- }
8854
- if (options && options.gis && options.gis.format === "binary") {
8855
- return parseFlatGeobufToBinary(arrayBuffer, options);
8947
+ const shape = options?.gis?.format || options?.flatgeobuf?.shape;
8948
+ switch (shape) {
8949
+ case "geojson-row-table": {
8950
+ const table = {
8951
+ shape: "geojson-row-table",
8952
+ data: parseFlatGeobufToGeoJSON(arrayBuffer, options)
8953
+ };
8954
+ return table;
8955
+ }
8956
+ case "columnar-table":
8957
+ return { shape: "columnar-table", data: parseFlatGeobufToBinary(arrayBuffer, options) };
8958
+ case "geojson":
8959
+ return parseFlatGeobufToGeoJSON(arrayBuffer, options);
8960
+ case "binary":
8961
+ return parseFlatGeobufToBinary(arrayBuffer, options);
8962
+ default:
8963
+ throw new Error(shape);
8856
8964
  }
8857
- return parseFlatGeobufToGeoJSON(arrayBuffer, options);
8858
8965
  }
8859
8966
  function parseFlatGeobufToBinary(arrayBuffer, options) {
8860
- const arr = new Uint8Array(arrayBuffer);
8861
- return (0, import_generic.deserialize)(arr, binaryFromFeature);
8967
+ const array = new Uint8Array(arrayBuffer);
8968
+ return (0, import_generic.deserialize)(array, binaryFromFeature);
8862
8969
  }
8863
8970
  function parseFlatGeobufToGeoJSON(arrayBuffer, options) {
8971
+ if (arrayBuffer.byteLength === 0) {
8972
+ return [];
8973
+ }
8864
8974
  const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
8865
8975
  const arr = new Uint8Array(arrayBuffer);
8866
8976
  let headerMeta;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,10 @@ import { FlatGeobufLoader as FlatGeobufWorkerLoader } from './flatgeobuf-loader'
3
3
  import { parseFlatGeobuf, parseFlatGeobufInBatches } from './lib/parse-flatgeobuf';
4
4
  export { FlatGeobufWorkerLoader };
5
5
  export declare const FlatGeobufLoader: {
6
- parse: (arrayBuffer: any, options: any) => Promise<any>;
6
+ parse: (arrayBuffer: any, options: any) => Promise<any[] | import("@loaders.gl/schema").GeoJSONRowTable | AsyncGenerator<import("flatgeobuf/lib/cjs/generic/feature").IFeature, any, unknown> | {
7
+ shape: string;
8
+ data: any[] | AsyncGenerator<import("flatgeobuf/lib/cjs/generic/feature").IFeature, any, unknown>;
9
+ }>;
7
10
  parseSync: typeof parseFlatGeobuf;
8
11
  parseInBatchesFromStream: typeof parseFlatGeobufInBatches;
9
12
  binary: boolean;
@@ -16,7 +19,9 @@ export declare const FlatGeobufLoader: {
16
19
  mimeTypes: string[];
17
20
  category: string;
18
21
  options: {
19
- flatgeobuf: {};
22
+ flatgeobuf: {
23
+ shape: string;
24
+ };
20
25
  };
21
26
  };
22
27
  export declare const _typecheckFlatGeobufLoader: LoaderWithParser;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAC,gBAAgB,IAAI,sBAAsB,EAAC,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAC,eAAe,EAAE,wBAAwB,EAAC,MAAM,wBAAwB,CAAC;AAEjF,OAAO,EAAC,sBAAsB,EAAC,CAAC;AAEhC,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;CAM5B,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,gBAAmC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAC,gBAAgB,IAAI,sBAAsB,EAAC,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAC,eAAe,EAAE,wBAAwB,EAAC,MAAM,wBAAwB,CAAC;AAEjF,OAAO,EAAC,sBAAsB,EAAC,CAAC;AAEhC,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;CAM5B,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,gBAAmC,CAAC"}
package/dist/index.js CHANGED
@@ -1,11 +1,14 @@
1
- import { FlatGeobufLoader as FlatGeobufWorkerLoader } from './flatgeobuf-loader';
2
- import { parseFlatGeobuf, parseFlatGeobufInBatches } from './lib/parse-flatgeobuf';
3
- export { FlatGeobufWorkerLoader };
4
- export const FlatGeobufLoader = { ...FlatGeobufWorkerLoader,
5
- parse: async (arrayBuffer, options) => parseFlatGeobuf(arrayBuffer, options),
6
- parseSync: parseFlatGeobuf,
7
- parseInBatchesFromStream: parseFlatGeobufInBatches,
8
- binary: true
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._typecheckFlatGeobufLoader = exports.FlatGeobufLoader = exports.FlatGeobufWorkerLoader = void 0;
4
+ const flatgeobuf_loader_1 = require("./flatgeobuf-loader");
5
+ Object.defineProperty(exports, "FlatGeobufWorkerLoader", { enumerable: true, get: function () { return flatgeobuf_loader_1.FlatGeobufLoader; } });
6
+ const parse_flatgeobuf_1 = require("./lib/parse-flatgeobuf");
7
+ exports.FlatGeobufLoader = {
8
+ ...flatgeobuf_loader_1.FlatGeobufLoader,
9
+ parse: async (arrayBuffer, options) => (0, parse_flatgeobuf_1.parseFlatGeobuf)(arrayBuffer, options),
10
+ parseSync: parse_flatgeobuf_1.parseFlatGeobuf,
11
+ parseInBatchesFromStream: parse_flatgeobuf_1.parseFlatGeobufInBatches,
12
+ binary: true
9
13
  };
10
- export const _typecheckFlatGeobufLoader = FlatGeobufLoader;
11
- //# sourceMappingURL=index.js.map
14
+ exports._typecheckFlatGeobufLoader = exports.FlatGeobufLoader;
@@ -1,144 +1,120 @@
1
- import { GeometryType } from 'flatgeobuf/lib/cjs/header_generated';
2
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromGeometry = void 0;
4
+ const header_generated_1 = require("flatgeobuf/lib/cjs/header_generated");
5
+ // Parse Point to flat array
3
6
  function parsePoint(geometry) {
4
- const xy = geometry.xyArray();
5
- const z = geometry.zArray();
6
- const positions = blitArrays(xy, z);
7
- return {
8
- positions
9
- };
7
+ const xy = geometry.xyArray();
8
+ const z = geometry.zArray();
9
+ const positions = blitArrays(xy, z);
10
+ return { positions };
10
11
  }
11
-
12
12
  function parseLines(geometry) {
13
- const xy = geometry.xyArray();
14
- const z = geometry.zArray();
15
- const positions = blitArrays(xy, z);
16
- const ends = geometry.endsArray() && Array.from(geometry.endsArray()) || [xy.length / 2];
17
- ends.unshift(0);
18
- const pathIndices = {
19
- value: new Uint16Array(ends),
20
- size: 1
21
- };
22
- return {
23
- positions,
24
- pathIndices
25
- };
13
+ const xy = geometry.xyArray();
14
+ const z = geometry.zArray();
15
+ const positions = blitArrays(xy, z);
16
+ // If endsArray is null, a single LineString. Otherwise, contains the end
17
+ // indices of each part of the MultiLineString. geometry.endsArray() omits the
18
+ // initial 0 that we have in our internal format.
19
+ const ends = (geometry.endsArray() && Array.from(geometry.endsArray())) || [xy.length / 2];
20
+ ends.unshift(0);
21
+ const pathIndices = { value: new Uint16Array(ends), size: 1 };
22
+ return {
23
+ positions,
24
+ pathIndices
25
+ };
26
26
  }
27
-
28
27
  function parsePolygons(geometry) {
29
- const xy = geometry.xyArray();
30
- const z = geometry.zArray();
31
- const positions = blitArrays(xy, z);
32
- const ends = geometry.endsArray() && Array.from(geometry.endsArray()) || [xy.length / 2];
33
- ends.unshift(0);
34
- const primitivePolygonIndices = {
35
- value: new Uint16Array(ends),
36
- size: 1
37
- };
38
- const polygonIndices = {
39
- value: new Uint16Array([0, xy.length / 2]),
40
- size: 1
41
- };
42
- return {
43
- positions,
44
- primitivePolygonIndices,
45
- polygonIndices
46
- };
28
+ const xy = geometry.xyArray();
29
+ const z = geometry.zArray();
30
+ const positions = blitArrays(xy, z);
31
+ // If endsArray is null, a simple Polygon with no inner rings. Otherwise,
32
+ // contains the end indices of each ring of the Polygon. geometry.endsArray()
33
+ // omits the initial 0 that we have in our internal format.
34
+ const ends = (geometry.endsArray() && Array.from(geometry.endsArray())) || [xy.length / 2];
35
+ ends.unshift(0);
36
+ const primitivePolygonIndices = { value: new Uint16Array(ends), size: 1 };
37
+ const polygonIndices = { value: new Uint16Array([0, xy.length / 2]), size: 1 };
38
+ return {
39
+ positions,
40
+ primitivePolygonIndices,
41
+ polygonIndices
42
+ };
47
43
  }
48
-
44
+ // eslint-disable-next-line max-statements
49
45
  function parseMultiPolygons(geometry) {
50
- const parsedParts = [];
51
- let nPositions = 0;
52
- let nPrimitivePolygonIndices = 1;
53
- let nPolygonIndices = 1;
54
-
55
- for (let i = 0; i < geometry.partsLength(); i++) {
56
- const part = geometry.parts(i);
57
- const polygon = parsePolygons(part);
58
- nPositions += polygon.positions.value.length;
59
- nPrimitivePolygonIndices += polygon.primitivePolygonIndices.value.length - 1;
60
- nPolygonIndices += polygon.polygonIndices.value.length - 1;
61
- parsedParts.push(polygon);
62
- }
63
-
64
- const concatPositions = new Float64Array(nPositions);
65
- const concatPrimitivePolygonIndices = new Uint32Array(nPrimitivePolygonIndices);
66
- const concatPolygonIndices = new Uint32Array(nPolygonIndices);
67
- let positionCounter = 0;
68
- let primitivePolygonIndicesCounter = 1;
69
- let polygonIndicesCounter = 1;
70
- const positionSize = parsedParts[0].positions.size;
71
-
72
- for (const parsedPart of parsedParts) {
73
- concatPositions.set(parsedPart.positions.value, positionCounter * positionSize);
74
- concatPrimitivePolygonIndices.set(parsedPart.primitivePolygonIndices.value.subarray(1).map(x => x + positionCounter), primitivePolygonIndicesCounter);
75
- concatPolygonIndices.set(parsedPart.polygonIndices.value.subarray(1).map(x => x + positionCounter), polygonIndicesCounter);
76
- positionCounter += parsedPart.positions.value.length / positionSize;
77
- primitivePolygonIndicesCounter += parsedPart.primitivePolygonIndices.value.length - 1;
78
- polygonIndicesCounter += parsedPart.polygonIndices.value.length - 1;
79
- }
80
-
81
- return {
82
- positions: {
83
- value: concatPositions,
84
- size: positionSize
85
- },
86
- primitivePolygonIndices: {
87
- value: concatPrimitivePolygonIndices,
88
- size: 1
89
- },
90
- polygonIndices: {
91
- value: concatPolygonIndices,
92
- size: 1
46
+ // Create arrays for each geometry part, then concatenate
47
+ const parsedParts = [];
48
+ let nPositions = 0;
49
+ let nPrimitivePolygonIndices = 1;
50
+ let nPolygonIndices = 1;
51
+ for (let i = 0; i < geometry.partsLength(); i++) {
52
+ const part = geometry.parts(i);
53
+ const polygon = parsePolygons(part);
54
+ nPositions += polygon.positions.value.length;
55
+ nPrimitivePolygonIndices += polygon.primitivePolygonIndices.value.length - 1;
56
+ nPolygonIndices += polygon.polygonIndices.value.length - 1;
57
+ parsedParts.push(polygon);
58
+ }
59
+ const concatPositions = new Float64Array(nPositions);
60
+ const concatPrimitivePolygonIndices = new Uint32Array(nPrimitivePolygonIndices);
61
+ const concatPolygonIndices = new Uint32Array(nPolygonIndices);
62
+ let positionCounter = 0;
63
+ let primitivePolygonIndicesCounter = 1;
64
+ let polygonIndicesCounter = 1;
65
+ // Assumes all parts of the multipolygon have the same size
66
+ const positionSize = parsedParts[0].positions.size;
67
+ for (const parsedPart of parsedParts) {
68
+ concatPositions.set(parsedPart.positions.value, positionCounter * positionSize);
69
+ // For indices, need to add positionCounter so that position indices are
70
+ // correct in the concatenated positions
71
+ concatPrimitivePolygonIndices.set(
72
+ // eslint-disable-next-line
73
+ parsedPart.primitivePolygonIndices.value.subarray(1).map((x) => x + positionCounter), primitivePolygonIndicesCounter);
74
+ concatPolygonIndices.set(
75
+ // eslint-disable-next-line
76
+ parsedPart.polygonIndices.value.subarray(1).map((x) => x + positionCounter), polygonIndicesCounter);
77
+ positionCounter += parsedPart.positions.value.length / positionSize;
78
+ primitivePolygonIndicesCounter += parsedPart.primitivePolygonIndices.value.length - 1;
79
+ polygonIndicesCounter += parsedPart.polygonIndices.value.length - 1;
93
80
  }
94
- };
95
- }
96
-
97
- function blitArrays(xy, z) {
98
- if (!z) {
99
81
  return {
100
- value: xy,
101
- size: 2
82
+ positions: { value: concatPositions, size: positionSize },
83
+ primitivePolygonIndices: { value: concatPrimitivePolygonIndices, size: 1 },
84
+ polygonIndices: { value: concatPolygonIndices, size: 1 }
102
85
  };
103
- }
104
-
105
- if (z.length * 2 !== xy.length) {
106
- throw new Error('Z array must be half XY array\'s length');
107
- }
108
-
109
- const totalLength = xy.length + z.length;
110
- const xyz = new Float64Array(totalLength);
111
-
112
- for (let i = 0; i < xy.length / 2; i++) {
113
- xyz[i * 3 + 0] = xy[i * 2 + 0];
114
- xyz[i * 3 + 1] = xy[i * 2 + 1];
115
- xyz[i * 3 + 2] = z[i];
116
- }
117
-
118
- return {
119
- value: xyz,
120
- size: 3
121
- };
122
86
  }
123
-
124
- export function fromGeometry(geometry, type) {
125
- switch (type) {
126
- case GeometryType.Point:
127
- case GeometryType.MultiPoint:
128
- return parsePoint(geometry);
129
-
130
- case GeometryType.LineString:
131
- case GeometryType.MultiLineString:
132
- return parseLines(geometry);
133
-
134
- case GeometryType.Polygon:
135
- return parsePolygons(geometry);
136
-
137
- case GeometryType.MultiPolygon:
138
- return parseMultiPolygons(geometry);
139
-
140
- default:
141
- throw new Error("Unimplemented geometry type: ".concat(type));
142
- }
87
+ // Combine xy and z arrays
88
+ function blitArrays(xy, z) {
89
+ if (!z) {
90
+ return { value: xy, size: 2 };
91
+ }
92
+ if (z.length * 2 !== xy.length) {
93
+ throw new Error('Z array must be half XY array\'s length');
94
+ }
95
+ const totalLength = xy.length + z.length;
96
+ const xyz = new Float64Array(totalLength);
97
+ for (let i = 0; i < xy.length / 2; i++) {
98
+ xyz[i * 3 + 0] = xy[i * 2 + 0];
99
+ xyz[i * 3 + 1] = xy[i * 2 + 1];
100
+ xyz[i * 3 + 2] = z[i];
101
+ }
102
+ return { value: xyz, size: 3 };
103
+ }
104
+ function fromGeometry(geometry, type) {
105
+ switch (type) {
106
+ case header_generated_1.GeometryType.Point:
107
+ case header_generated_1.GeometryType.MultiPoint:
108
+ return parsePoint(geometry);
109
+ case header_generated_1.GeometryType.LineString:
110
+ case header_generated_1.GeometryType.MultiLineString:
111
+ return parseLines(geometry);
112
+ case header_generated_1.GeometryType.Polygon:
113
+ return parsePolygons(geometry);
114
+ case header_generated_1.GeometryType.MultiPolygon:
115
+ return parseMultiPolygons(geometry);
116
+ default:
117
+ throw new Error(`Unimplemented geometry type: ${type}`);
118
+ }
143
119
  }
144
- //# sourceMappingURL=binary-geometries.js.map
120
+ exports.fromGeometry = fromGeometry;
@@ -1,3 +1,8 @@
1
- export declare function parseFlatGeobuf(arrayBuffer: any, options: any): any;
2
- export declare function parseFlatGeobufInBatches(stream: any, options: any): any[] | AsyncGenerator<import("flatgeobuf/lib/cjs/generic/feature").IFeature, any, unknown> | AsyncGenerator<any, void, unknown>;
1
+ import { FlatGeobufLoaderOptions } from './types';
2
+ import { GeoJSONRowTable } from '@loaders.gl/schema';
3
+ export declare function parseFlatGeobuf(arrayBuffer: ArrayBuffer, options?: FlatGeobufLoaderOptions): any[] | GeoJSONRowTable | AsyncGenerator<import("flatgeobuf/lib/cjs/generic/feature").IFeature, any, unknown> | {
4
+ shape: string;
5
+ data: any[] | AsyncGenerator<import("flatgeobuf/lib/cjs/generic/feature").IFeature, any, unknown>;
6
+ };
7
+ export declare function parseFlatGeobufInBatches(stream: any, options: FlatGeobufLoaderOptions): any[] | AsyncGenerator<import("flatgeobuf/lib/cjs/generic/feature").IFeature, any, unknown> | AsyncGenerator<any, void, unknown>;
3
8
  //# sourceMappingURL=parse-flatgeobuf.d.ts.map