@loaders.gl/raster 5.0.0-beta.10 → 5.0.0-beta.11

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.
@@ -762,7 +762,7 @@
762
762
  "../core/src/loader-utils/lib/log-utils/log.ts"() {
763
763
  "use strict";
764
764
  init_log();
765
- VERSION2 = true ? "5.0.0-beta.10" : "latest";
765
+ VERSION2 = true ? "5.0.0-beta.11" : "latest";
766
766
  version = VERSION2[0] >= "0" && VERSION2[0] <= "9" ? `v${VERSION2}` : "";
767
767
  log2 = createLog();
768
768
  NullLog = class {
@@ -2481,9 +2481,9 @@
2481
2481
 
2482
2482
  // ../../node_modules/@math.gl/geospatial/dist/terrain/mesh-skirts.js
2483
2483
  function createTerrainSkirt(mesh, options) {
2484
- const { positions, indices } = mesh, { height, edges } = options;
2484
+ const { positions, indices } = mesh, { height, baseZ, edges } = options;
2485
2485
  const maxVertices = options.maxVertices ?? 2e6, maxTriangles = options.maxTriangles ?? 4e6;
2486
- if (!Number.isFinite(height) || height <= 0 || !Number.isSafeInteger(maxVertices) || maxVertices < 0 || maxVertices > 4294967295 || !Number.isSafeInteger(maxTriangles) || maxTriangles < 0 || maxTriangles > 4294967295)
2486
+ if ((baseZ === void 0 ? !(Number.isFinite(height) && height > 0) : height !== void 0 || !Number.isFinite(baseZ)) || !Number.isSafeInteger(maxVertices) || maxVertices < 0 || maxVertices > 4294967295 || !Number.isSafeInteger(maxTriangles) || maxTriangles < 0 || maxTriangles > 4294967295)
2487
2487
  throw new Error("Invalid terrain skirt height or capacity");
2488
2488
  if (!(positions instanceof Float32Array || positions instanceof Float64Array) || positions.length < 3 || positions.length % 3 || !positions.every(Number.isFinite) || !(indices instanceof Uint16Array || indices instanceof Uint32Array) || indices.length % 3 || positions.length / 3 > maxVertices || indices.length / 3 > maxTriangles)
2489
2489
  throw new Error("Invalid terrain skirt mesh or capacity");
@@ -2539,7 +2539,7 @@
2539
2539
  [b, lowerB]
2540
2540
  ]) {
2541
2541
  resultPositions.set(positions.subarray(3 * source, 3 * source + 3), 3 * target);
2542
- resultPositions[3 * target + 2] = positions[3 * source + 2] - height;
2542
+ resultPositions[3 * target + 2] = baseZ ?? positions[3 * source + 2] - height;
2543
2543
  if (!Number.isFinite(resultPositions[3 * target + 2]) || resultPositions[3 * target + 2] >= positions[3 * source + 2])
2544
2544
  throw new Error("Terrain skirt height cannot be represented in position precision");
2545
2545
  sourceVertexIndices[target - vertexCount] = source;
@@ -18364,6 +18364,20 @@ return true;`);
18364
18364
  }
18365
18365
  });
18366
18366
 
18367
+ // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-column-utils.js
18368
+ function isArrowTable2(value) {
18369
+ const table = value;
18370
+ return Boolean(table && Number.isInteger(table.numRows) && Array.isArray(table.batches) && Array.isArray(table.schema?.fields) && typeof table.get === "function" && typeof table.getChild === "function");
18371
+ }
18372
+ function isArrowRecordBatch2(value) {
18373
+ const batch = value;
18374
+ return Boolean(batch && Number.isInteger(batch.numRows) && Array.isArray(batch.schema?.fields) && Array.isArray(batch.data?.children) && typeof batch.get === "function" && typeof batch.getChild === "function");
18375
+ }
18376
+ var init_arrow_column_utils = __esm({
18377
+ "../../node_modules/@math.gl/arrow/dist/arrow/arrow-column-utils.js"() {
18378
+ }
18379
+ });
18380
+
18367
18381
  // ../../node_modules/@math.gl/arrow/dist/arrow/split-arrow-buffers.js
18368
18382
  function splitArrowBuffers(input, options = {}) {
18369
18383
  const retainedBuffers = /* @__PURE__ */ new Set();
@@ -18385,12 +18399,6 @@ return true;`);
18385
18399
  }
18386
18400
  return splitArrowDataBuffers(input, context);
18387
18401
  }
18388
- function isArrowTable2(input) {
18389
- return "batches" in input;
18390
- }
18391
- function isArrowRecordBatch2(input) {
18392
- return "schema" in input && "data" in input && !Array.isArray(input.data);
18393
- }
18394
18402
  function isArrowVector2(input) {
18395
18403
  return "data" in input && Array.isArray(input.data);
18396
18404
  }
@@ -18462,6 +18470,7 @@ return true;`);
18462
18470
  init_Arrow_dom();
18463
18471
  init_arrow_record_batch();
18464
18472
  init_arrow_data();
18473
+ init_arrow_column_utils();
18465
18474
  }
18466
18475
  });
18467
18476
 
@@ -18574,12 +18583,6 @@ return true;`);
18574
18583
  }
18575
18584
  });
18576
18585
 
18577
- // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-column-utils.js
18578
- var init_arrow_column_utils = __esm({
18579
- "../../node_modules/@math.gl/arrow/dist/arrow/arrow-column-utils.js"() {
18580
- }
18581
- });
18582
-
18583
18586
  // ../../node_modules/@math.gl/arrow/dist/arrow/index.js
18584
18587
  var init_arrow = __esm({
18585
18588
  "../../node_modules/@math.gl/arrow/dist/arrow/index.js"() {
@@ -18604,16 +18607,6 @@ return true;`);
18604
18607
  });
18605
18608
 
18606
18609
  // ../core/src/arrow-worker-transport.ts
18607
- function deserializeArrowWorkerTable(result) {
18608
- if (isArrowWorkerEnvelope(result)) {
18609
- return { ...result.metadata, shape: "arrow-table", data: hydrateWorkerTable(result) };
18610
- }
18611
- if (isLegacyArrowWorkerEnvelope(result)) {
18612
- const { arrowBatchMetadata: _snapshots, data: _columns, ...metadata } = result;
18613
- return { ...metadata, data: hydrateWorkerTable(result) };
18614
- }
18615
- throw new Error("Workers require Arrow column transport");
18616
- }
18617
18610
  function serializeNativeArrowWorkerResult(result, options = { copy: "all" }) {
18618
18611
  const batch = result instanceof RecordBatch3;
18619
18612
  if (!batch && !(result instanceof Table)) {
@@ -18637,62 +18630,26 @@ return true;`);
18637
18630
  }
18638
18631
  function serializeArrowWorkerResult(result, options) {
18639
18632
  const workerOptions = options;
18640
- const bufferCopyMode = workerOptions?.core?.workerTransferBufferCopy ?? workerOptions?.workerTransferBufferCopy;
18641
- if (result instanceof Table || result instanceof RecordBatch3) {
18642
- return serializeNativeArrowWorkerResult(result, { copy: bufferCopyMode ?? "all" });
18643
- }
18644
- if (!isArrowTableWrapper(result)) {
18645
- return result;
18646
- }
18647
- const { data, shape: _shape, ...metadata } = result;
18648
- return {
18649
- transport: "arrow-column-envelope",
18650
- metadata: structuredClone(metadata),
18651
- ...serializeWorkerColumns(data, bufferCopyMode ? { copy: bufferCopyMode } : void 0)
18652
- };
18633
+ const copy = workerOptions?.core?.workerTransferBufferCopy ?? workerOptions?.workerTransferBufferCopy;
18634
+ return result instanceof Table || result instanceof RecordBatch3 ? serializeNativeArrowWorkerResult(result, { copy: copy ?? "all" }) : result;
18653
18635
  }
18654
18636
  function deserializeArrowWorkerResult(result) {
18655
18637
  const transport = result?.transport;
18656
- if (transport === "arrow-table-columns" || transport === "arrow-record-batch") {
18657
- return deserializeNativeArrowWorkerResult(result);
18658
- }
18659
- return isArrowWorkerEnvelope(result) || isLegacyArrowWorkerEnvelope(result) ? deserializeArrowWorkerTable(result) : result;
18660
- }
18661
- function isArrowTableWrapper(value) {
18662
- const table = value;
18663
- return Boolean(
18664
- table && table.shape === "arrow-table" && table.data && typeof table.data === "object" && "batches" in table.data
18665
- );
18638
+ return transport === "arrow-table-columns" || transport === "arrow-record-batch" ? deserializeNativeArrowWorkerResult(result) : result;
18666
18639
  }
18667
18640
  function hasArrowWorkerColumns(value) {
18668
18641
  const columns = value;
18669
18642
  return columns?.data?.transport === "arrow-js" && Array.isArray(columns.data.batches);
18670
18643
  }
18671
- function isArrowWorkerEnvelope(value) {
18672
- return value?.transport === "arrow-column-envelope" && hasArrowWorkerColumns(value);
18673
- }
18674
- function isLegacyArrowWorkerEnvelope(value) {
18675
- return value?.shape === "arrow-table" && hasArrowWorkerColumns(value);
18676
- }
18677
18644
  function serializeWorkerColumns(table, options) {
18678
18645
  return {
18679
18646
  arrowBatchMetadata: snapshotBatchMetadata(table),
18680
- data: dehydrateWorkerTable(table, options)
18647
+ data: dehydrateArrowTable(table, options)
18681
18648
  };
18682
18649
  }
18683
- function dehydrateWorkerTable(table, options) {
18684
- const payload = dehydrateArrowTable(table, options);
18685
- if (table.numCols === 0) {
18686
- for (const [index, batch] of table.batches.entries()) {
18687
- payload.batches[index].length = batch.numRows;
18688
- }
18689
- }
18690
- return payload;
18691
- }
18692
18650
  function snapshotBatchMetadata(table) {
18693
18651
  return table.batches.map((batch) => ({
18694
- schema: tableToIPC(new Table(batch.schema, [])),
18695
- metadata: Array.from(batch.metadata)
18652
+ schema: tableToIPC(new Table(batch.schema, []))
18696
18653
  }));
18697
18654
  }
18698
18655
  function hydrateWorkerTable(result) {
@@ -18700,18 +18657,11 @@ return true;`);
18700
18657
  const table = hydrateArrowTable(data);
18701
18658
  const batches = table.batches.map((batch, index) => {
18702
18659
  const snapshot = arrowBatchMetadata?.[index];
18703
- const restored = snapshot ? new RecordBatch3(
18660
+ return snapshot ? createRecordBatchWithMetadata(
18704
18661
  tableFromIPC(snapshot.schema).schema,
18705
18662
  batch.data,
18706
- new Map(snapshot.metadata)
18663
+ snapshot.metadata ? new Map(snapshot.metadata) : getRecordBatchMetadata(batch)
18707
18664
  ) : batch;
18708
- const rowCount = data.batches[index].length;
18709
- if (restored.numCols === 0 && restored.numRows !== rowCount) {
18710
- Object.defineProperty(restored, "data", {
18711
- value: new Data(new Struct([]), 0, rowCount, 0, void 0, [])
18712
- });
18713
- }
18714
- return restored;
18715
18665
  });
18716
18666
  return new Table(table.schema, batches);
18717
18667
  }
@@ -19219,7 +19169,7 @@ return true;`);
19219
19169
  });
19220
19170
 
19221
19171
  // ../core/src/lib/loader-utils/native-arrow.ts
19222
- function isNativeArrowTable(value) {
19172
+ function isArrowTable3(value) {
19223
19173
  return Boolean(
19224
19174
  value && typeof value === "object" && "schema" in value && "batches" in value && Array.isArray(value.batches) && "numRows" in value && typeof value.numRows === "number" && "getChildAt" in value && typeof value.getChildAt === "function"
19225
19175
  );
@@ -19423,7 +19373,7 @@ return true;`);
19423
19373
  });
19424
19374
 
19425
19375
  // ../core/src/schema-utils/lib/mesh/convert-mesh-to-table.ts
19426
- function convertMeshToArrowTableWrapper(mesh, batchSize) {
19376
+ function convertMeshToArrowTable(mesh) {
19427
19377
  return makeMeshArrowTable(mesh.attributes, {
19428
19378
  schema: mesh.schema,
19429
19379
  topology: mesh.topology,
@@ -19444,22 +19394,14 @@ return true;`);
19444
19394
  fields.push(
19445
19395
  getAttributeArrowField(options.schema, attributeName, column, attribute.componentType)
19446
19396
  );
19447
- if (attributeName === "POSITION" && options.indices?.value?.length) {
19397
+ if (attributeName === attributeNames[0] && options.indices?.value?.length) {
19448
19398
  const indicesField = indexedMeshArrowSchema.fields.find((field) => field.name === "indices");
19449
19399
  columns.indices = getIndicesVector(options.indices.value, column.length, indicesField.type);
19450
19400
  fields.push(indicesField);
19451
19401
  }
19452
19402
  }
19453
19403
  const arrowSchema = new Schema2(fields, getMeshArrowMetadata(options));
19454
- const table = columns[attributeNames[0]]?.length === 0 ? new Table(arrowSchema) : new Table(arrowSchema, columns);
19455
- const schema = serializeArrowSchema(table.schema);
19456
- return {
19457
- shape: "arrow-table",
19458
- schema,
19459
- data: table,
19460
- topology: options.topology || "point-list",
19461
- indices: options.indices
19462
- };
19404
+ return columns[attributeNames[0]]?.length === 0 ? new Table(arrowSchema) : new Table(arrowSchema, columns);
19463
19405
  }
19464
19406
  function getAttributeArrowVector(value, size, componentType) {
19465
19407
  if (componentType === "float16") {
@@ -19584,18 +19526,10 @@ return true;`);
19584
19526
 
19585
19527
  // ../core/src/schema-utils/lib/mesh/convert-table-to-mesh.ts
19586
19528
  function convertTableToMesh(table) {
19587
- if (isNativeArrowTable(table)) return convertArrowTableToMesh(table);
19588
- switch (table.shape) {
19589
- // case 'columnar-table':
19590
- // return convertColumnarTableToMesh(table);
19591
- case "arrow-table":
19592
- return convertArrowTableToMesh(table);
19593
- default:
19594
- throw new Error(table.shape);
19595
- }
19529
+ if (isArrowTable3(table)) return convertArrowTableToMesh(table);
19530
+ throw new Error(table.shape);
19596
19531
  }
19597
- function convertArrowTableToMesh(table) {
19598
- const arrowTable = isNativeArrowTable(table) ? table : table.data;
19532
+ function convertArrowTableToMesh(arrowTable) {
19599
19533
  const schema = serializeArrowSchema(arrowTable.schema);
19600
19534
  const localBounds = arrowTable.batches.length === 1 ? arrowTable.batches[0].metadata.get("boundingBox") : void 0;
19601
19535
  if (localBounds) schema.metadata = { ...schema.metadata, boundingBox: localBounds };
@@ -19699,13 +19633,18 @@ return true;`);
19699
19633
  if (!(attributeData.type instanceof FixedSizeList2)) {
19700
19634
  return attributeData.toArray();
19701
19635
  }
19702
- const values = attributeData.data[0].children[0].values;
19636
+ if (attributeData.length === 0) {
19637
+ const EmptyStorage = attributeData.type.valueType.ArrayType;
19638
+ return new EmptyStorage(0);
19639
+ }
19640
+ const values = attributeData.data.find((chunk) => chunk.length > 0).children[0].values;
19703
19641
  const TypedArrayConstructor = values.constructor;
19704
19642
  const typedArray = new TypedArrayConstructor(attributeData.length * size);
19705
19643
  let targetOffset = 0;
19706
19644
  for (const data of attributeData.data) {
19707
- const child = data.children[0];
19708
19645
  const sourceLength = data.length * size;
19646
+ if (sourceLength === 0) continue;
19647
+ const child = data.children[0];
19709
19648
  const sourceOffset = child.offset || data.offset * size;
19710
19649
  const sourceStart = sourceOffset + sourceLength <= child.values.length ? sourceOffset : 0;
19711
19650
  const source = child.values.subarray(sourceStart, sourceStart + sourceLength);
@@ -20027,7 +19966,7 @@ return true;`);
20027
19966
  var init_version = __esm({
20028
19967
  "../images/src/lib/utils/version.ts"() {
20029
19968
  "use strict";
20030
- VERSION3 = true ? "5.0.0-beta.10" : "latest";
19969
+ VERSION3 = true ? "5.0.0-beta.11" : "latest";
20031
19970
  }
20032
19971
  });
20033
19972
 
@@ -20561,7 +20500,7 @@ return true;`);
20561
20500
  var init_version2 = __esm({
20562
20501
  "src/terrain/lib/utils/version.ts"() {
20563
20502
  "use strict";
20564
- VERSION4 = true ? "5.0.0-beta.10" : "latest";
20503
+ VERSION4 = true ? "5.0.0-beta.11" : "latest";
20565
20504
  }
20566
20505
  });
20567
20506
 
@@ -20653,9 +20592,9 @@ return true;`);
20653
20592
  ...options?.terrain
20654
20593
  };
20655
20594
  const mesh = makeTerrainMeshFromImage(terrainImage, terrainOptions);
20656
- const table = convertMeshToArrowTableWrapper(mesh);
20595
+ const table = convertMeshToArrowTable(mesh);
20657
20596
  if (options?.terrain?.shape === "arrow") {
20658
- return table.data;
20597
+ return table;
20659
20598
  }
20660
20599
  return {
20661
20600
  ...convertTableToMesh(table),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/raster",
3
- "version": "5.0.0-beta.10",
3
+ "version": "5.0.0-beta.11",
4
4
  "description": "GeoTIFF, OME-TIFF, LERC, and terrain raster loaders",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -309,9 +309,9 @@
309
309
  "pre-build": "npm run copy-libs && node ./build-cjs.mjs && npm run build-worker-terrain && npm run build-worker-quantized-mesh"
310
310
  },
311
311
  "dependencies": {
312
- "@loaders.gl/documents": "5.0.0-beta.10",
313
- "@loaders.gl/images": "5.0.0-beta.10",
314
- "@math.gl/geospatial": "5.0.0-beta.10"
312
+ "@loaders.gl/documents": "5.0.0-beta.11",
313
+ "@loaders.gl/images": "5.0.0-beta.11",
314
+ "@math.gl/geospatial": "5.0.0-beta.11"
315
315
  },
316
316
  "peerDependencies": {
317
317
  "@loaders.gl/core": "~5.0.0-alpha.0",
@@ -357,5 +357,5 @@
357
357
  "terrain",
358
358
  "tif"
359
359
  ],
360
- "gitHead": "efdd84034c25e2e5dbb41bc88b75af56cb2176da"
360
+ "gitHead": "d23c857c2a9c0a028e63d58bf9e1a94a1b27a0fd"
361
361
  }
@@ -9,7 +9,7 @@ import {
9
9
  import type {LoaderWithParser} from '@loaders.gl/core/loader-utils';
10
10
  import type {Table} from 'apache-arrow';
11
11
  import type {Mesh} from '@loaders.gl/core/schema';
12
- import {convertMeshToArrowTableWrapper, convertTableToMesh} from '@loaders.gl/core/schema-utils';
12
+ import {convertMeshToArrowTable, convertTableToMesh} from '@loaders.gl/core/schema-utils';
13
13
  import {parseQuantizedMesh} from './lib/parse-quantized-mesh';
14
14
  import {
15
15
  QuantizedMeshLoader as QuantizedMeshLoaderMetadata,
@@ -35,9 +35,9 @@ function parseQuantizedMeshInRequestedShape(
35
35
  options?: QuantizedMeshLoaderOptions
36
36
  ): Mesh | Table {
37
37
  const mesh = parseQuantizedMesh(arrayBuffer, options?.['quantized-mesh']);
38
- const table = convertMeshToArrowTableWrapper(mesh);
38
+ const table = convertMeshToArrowTable(mesh);
39
39
  if (options?.['quantized-mesh']?.shape === 'arrow') {
40
- return table.data;
40
+ return table;
41
41
  }
42
42
  return {
43
43
  ...convertTableToMesh(table),
@@ -4,8 +4,8 @@
4
4
 
5
5
  import type {Table} from 'apache-arrow';
6
6
  import type {WriterOptions, WriterWithEncoder} from '@loaders.gl/core/loader-utils';
7
- import type {Mesh, MeshArrowTable, MeshAttribute} from '@loaders.gl/core/schema';
8
- import {convertMeshToArrowTableWrapper, convertTableToMesh} from '@loaders.gl/core/schema-utils';
7
+ import type {Mesh, MeshAttribute} from '@loaders.gl/core/schema';
8
+ import {convertMeshToArrowTable, convertTableToMesh} from '@loaders.gl/core/schema-utils';
9
9
  import {VERSION} from './lib/utils/version';
10
10
  import {QuantizedMeshFormat} from './terrain-format';
11
11
 
@@ -28,22 +28,18 @@ export type QuantizedMeshWriterOptions = WriterOptions & {
28
28
  export const QuantizedMeshWriter = {
29
29
  ...QuantizedMeshFormat,
30
30
  version: VERSION,
31
- dataType: null as unknown as Mesh | MeshArrowTable | Table,
31
+ dataType: null as unknown as Mesh | Table,
32
32
  batchType: null as never,
33
33
  options: {
34
34
  'quantized-mesh': {}
35
35
  },
36
36
  encode: async (data, options) => encodeQuantizedMeshSync(data, options),
37
37
  encodeSync: encodeQuantizedMeshSync
38
- } as const satisfies WriterWithEncoder<
39
- Mesh | MeshArrowTable | Table,
40
- never,
41
- QuantizedMeshWriterOptions
42
- >;
38
+ } as const satisfies WriterWithEncoder<Mesh | Table, never, QuantizedMeshWriterOptions>;
43
39
 
44
40
  /** Encode mesh category data as quantized mesh terrain bytes. */
45
41
  function encodeQuantizedMeshSync(
46
- data: Mesh | MeshArrowTable | Table,
42
+ data: Mesh | Table,
47
43
  options: QuantizedMeshWriterOptions = {}
48
44
  ): ArrayBuffer {
49
45
  const mesh = convertTableToMesh(normalizeMeshArrowTable(data));
@@ -92,12 +88,12 @@ function encodeQuantizedMeshSync(
92
88
  return arrayBuffer;
93
89
  }
94
90
 
95
- /** Return mesh data as a MeshArrowTable, converting plain Mesh data first. */
96
- function normalizeMeshArrowTable(data: Mesh | MeshArrowTable | Table): MeshArrowTable | Table {
91
+ /** Return mesh data as a native Arrow table, converting plain Mesh data first. */
92
+ function normalizeMeshArrowTable(data: Mesh | Table): Table {
97
93
  if (!('attributes' in data)) {
98
94
  return data;
99
95
  }
100
- return convertMeshToArrowTableWrapper(data as Mesh);
96
+ return convertMeshToArrowTable(data as Mesh);
101
97
  }
102
98
 
103
99
  /** Return a required mesh attribute or throw a format-specific error. */
@@ -10,7 +10,7 @@ import type {LoaderContext, LoaderWithParser} from '@loaders.gl/core/loader-util
10
10
  import {parseFromContext} from '@loaders.gl/core/loader-utils';
11
11
  import type {Table} from 'apache-arrow';
12
12
  import type {Mesh} from '@loaders.gl/core/schema';
13
- import {convertMeshToArrowTableWrapper, convertTableToMesh} from '@loaders.gl/core/schema-utils';
13
+ import {convertMeshToArrowTable, convertTableToMesh} from '@loaders.gl/core/schema-utils';
14
14
  import {ImageLoader, getImageData} from '@loaders.gl/images';
15
15
  import {TerrainOptions, makeTerrainMeshFromImage} from './lib/parse-terrain';
16
16
  import {
@@ -68,9 +68,9 @@ export async function parseTerrain(
68
68
  ...options?.terrain
69
69
  } as TerrainOptions;
70
70
  const mesh = makeTerrainMeshFromImage(terrainImage, terrainOptions);
71
- const table = convertMeshToArrowTableWrapper(mesh);
71
+ const table = convertMeshToArrowTable(mesh);
72
72
  if (options?.terrain?.shape === 'arrow') {
73
- return table.data;
73
+ return table;
74
74
  }
75
75
  return {
76
76
  ...convertTableToMesh(table),