@loaders.gl/schema 4.5.3 → 5.0.0-alpha.10

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 (54) hide show
  1. package/LICENSE +14 -3
  2. package/dist/categories/category-gis.d.ts +1 -0
  3. package/dist/categories/category-gis.d.ts.map +1 -1
  4. package/dist/categories/category-image.d.ts +1 -1
  5. package/dist/categories/category-mesh.d.ts +54 -3
  6. package/dist/categories/category-mesh.d.ts.map +1 -1
  7. package/dist/categories/category-mesh.js +10 -1
  8. package/dist/categories/category-mesh.js.map +1 -1
  9. package/dist/deprecated/mesh-utils.d.ts +5 -18
  10. package/dist/deprecated/mesh-utils.d.ts.map +1 -1
  11. package/dist/deprecated/mesh-utils.js +13 -25
  12. package/dist/deprecated/mesh-utils.js.map +1 -1
  13. package/dist/dist.dev.js +1789 -352
  14. package/dist/dist.min.js +4 -3
  15. package/dist/float16.d.ts +19 -0
  16. package/dist/float16.d.ts.map +1 -0
  17. package/dist/float16.js +90 -0
  18. package/dist/float16.js.map +1 -0
  19. package/dist/geometry/arrow-binary-features.d.ts +45 -0
  20. package/dist/geometry/arrow-binary-features.d.ts.map +1 -0
  21. package/dist/geometry/arrow-binary-features.js +5 -0
  22. package/dist/geometry/arrow-binary-features.js.map +1 -0
  23. package/dist/geometry/geoarrow.d.ts +69 -0
  24. package/dist/geometry/geoarrow.d.ts.map +1 -0
  25. package/dist/geometry/geoarrow.js +5 -0
  26. package/dist/geometry/geoarrow.js.map +1 -0
  27. package/dist/index.cjs +180 -17
  28. package/dist/index.cjs.map +2 -3
  29. package/dist/index.d.ts +10 -3
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +5 -3
  32. package/dist/index.js.map +1 -1
  33. package/dist/metadata.d.ts +40 -0
  34. package/dist/metadata.d.ts.map +1 -0
  35. package/dist/metadata.js +86 -0
  36. package/dist/metadata.js.map +1 -0
  37. package/dist/types/schema.d.ts +4 -1
  38. package/dist/types/schema.d.ts.map +1 -1
  39. package/dist/types/types.d.ts +3 -2
  40. package/dist/types/types.d.ts.map +1 -1
  41. package/dist/types/types.js +1 -0
  42. package/dist/types/types.js.map +1 -1
  43. package/package.json +3 -2
  44. package/src/categories/category-gis.ts +8 -0
  45. package/src/categories/category-image.ts +1 -1
  46. package/src/categories/category-mesh.ts +86 -3
  47. package/src/deprecated/mesh-utils.ts +15 -35
  48. package/src/float16.ts +111 -0
  49. package/src/geometry/arrow-binary-features.ts +54 -0
  50. package/src/geometry/geoarrow.ts +116 -0
  51. package/src/index.ts +57 -9
  52. package/src/metadata.ts +115 -0
  53. package/src/types/schema.ts +3 -0
  54. package/src/types/types.ts +7 -0
@@ -5,26 +5,80 @@
5
5
  import type {Schema} from '../types/schema';
6
6
  import type {TypedArray} from '../types/types';
7
7
  import type {ColumnarTable, ArrowTable} from './category-table';
8
+ import * as arrow from 'apache-arrow';
8
9
 
9
10
  /** Mesh as columnar table */
10
11
  export interface MeshTable extends ColumnarTable {
11
12
  // shape: 'mesh-table';
12
- topology: 'point-list' | 'triangle-list' | 'triangle-strip';
13
+ topology: MeshTopology;
13
14
  indices?: MeshAttribute;
14
15
  }
15
16
 
16
17
  /** Mesh as arrow table */
17
18
  export interface MeshArrowTable extends ArrowTable {
18
19
  // shape: 'mesh-arrow-table';
19
- topology: 'point-list' | 'triangle-list' | 'triangle-strip';
20
+ /** Mesh topology represented by the Arrow table rows and indices. */
21
+ topology: MeshTopology;
22
+ /** Optional top-level primitive indices accessor for indexed meshes. */
20
23
  indices?: MeshAttribute;
24
+ /** Raw Apache Arrow table data for Mesh or IndexedMesh columns. */
25
+ data: MeshArrowTableData | IndexedMeshArrowTableData;
21
26
  }
22
27
 
28
+ /** Apache Arrow columns for a mesh vertex table. */
29
+ export type MeshArrowColumns = {
30
+ /** XYZ vertex positions as float32 tuples. */
31
+ POSITION: arrow.FixedSizeList<arrow.Float32>;
32
+ /** Loader-specific vertex attribute columns appended after predefined fields. */
33
+ [attributeName: string]: arrow.DataType;
34
+ };
35
+
36
+ /** Primitive topology names shared by columnar and Arrow mesh representations. */
37
+ export type MeshTopology =
38
+ | 'point-list'
39
+ | 'line-list'
40
+ | 'line-loop'
41
+ | 'line-strip'
42
+ | 'triangle-list'
43
+ | 'triangle-strip'
44
+ | 'triangle-fan';
45
+
46
+ /** Apache Arrow columns for an indexed mesh vertex table. */
47
+ export type IndexedMeshArrowColumns = MeshArrowColumns & {
48
+ /** Unsigned 32-bit primitive indices, stored in row 0 and null for remaining vertex rows. */
49
+ indices: arrow.List<arrow.Uint32>;
50
+ };
51
+
52
+ /** Raw Apache Arrow table data for a mesh vertex table. */
53
+ export type MeshArrowTableData = arrow.Table<MeshArrowColumns>;
54
+
55
+ /** Raw Apache Arrow table data for an indexed mesh vertex table. */
56
+ export type IndexedMeshArrowTableData = arrow.Table<IndexedMeshArrowColumns>;
57
+
58
+ /** Predefined Apache Arrow schema for common mesh vertex columns. */
59
+ export const meshArrowSchema = new arrow.Schema<MeshArrowColumns>([
60
+ new arrow.Field(
61
+ 'POSITION',
62
+ new arrow.FixedSizeList(3, new arrow.Field('value', new arrow.Float32(), false)),
63
+ false
64
+ )
65
+ ]);
66
+
67
+ /** Predefined Apache Arrow schema for indexed mesh vertex tables. */
68
+ export const indexedMeshArrowSchema = new arrow.Schema<IndexedMeshArrowColumns>([
69
+ ...meshArrowSchema.fields,
70
+ new arrow.Field(
71
+ 'indices',
72
+ new arrow.List(new arrow.Field('item', new arrow.Uint32(), false)),
73
+ true
74
+ )
75
+ ]);
76
+
23
77
  /** Geometry part of a Mesh (compatible with a standard luma.gl "mesh") */
24
78
  export type MeshGeometry = {
25
79
  attributes: {[attributeName: string]: MeshAttribute};
26
80
  indices?: MeshAttribute;
27
- topology: 'point-list' | 'triangle-list' | 'triangle-strip';
81
+ topology: MeshTopology;
28
82
  mode: number;
29
83
  };
30
84
 
@@ -39,6 +93,31 @@ export type Mesh = MeshGeometry & {
39
93
  schema: Schema;
40
94
  };
41
95
 
96
+ /** Quantization transform required to reconstruct floating-point attribute values. */
97
+ export type MeshAttributeQuantizationTransform = {
98
+ /** Transform discriminator. */
99
+ type: 'quantization';
100
+ /** Number of quantization bits. */
101
+ bits: number;
102
+ /** Per-component quantization origin. */
103
+ origin: number[];
104
+ /** Quantization range shared by every component. */
105
+ range: number;
106
+ };
107
+
108
+ /** Octahedral transform required to reconstruct directional attribute values. */
109
+ export type MeshAttributeOctahedronTransform = {
110
+ /** Transform discriminator. */
111
+ type: 'octahedron';
112
+ /** Number of quantization bits. */
113
+ bits: number;
114
+ };
115
+
116
+ /** Encoded transform retained on an attribute for deferred CPU or GPU reconstruction. */
117
+ export type MeshAttributeTransform =
118
+ | MeshAttributeQuantizationTransform
119
+ | MeshAttributeOctahedronTransform;
120
+
42
121
  /**
43
122
  * luma.gl compatible attribute descriptors
44
123
  * Can be mapped to any WebGL framework
@@ -49,6 +128,10 @@ export type MeshAttribute = {
49
128
  byteOffset?: number;
50
129
  byteStride?: number;
51
130
  normalized?: boolean;
131
+ /** Logical component type when the storage array does not expose it directly. */
132
+ componentType?: 'float16';
133
+ /** Transform required to reconstruct the logical attribute values. */
134
+ transform?: MeshAttributeTransform;
52
135
  };
53
136
 
54
137
  /** A map of mesh attributes keyed by attribute names */
@@ -1,38 +1,17 @@
1
- // Mesh category utilities
2
- // TODO - move to mesh category module, or to math.gl/geometry module
3
- import {MeshAttributes} from '../categories/category-mesh';
4
- import {TypedArray} from '../types/types';
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
5
4
 
6
- type TypedArrays = {[key: string]: TypedArray};
5
+ import {MeshAttributes} from '../categories/category-mesh';
7
6
 
8
- /**
9
- * Holds an axis aligned bounding box
10
- * TODO - make sure AxisAlignedBoundingBox in math.gl/culling understands this format (or change this format)
11
- */
12
7
  type BoundingBox = [[number, number, number], [number, number, number]];
13
8
 
14
9
  /**
15
- * Get number of vertices in mesh
16
- * @param attributes
17
- * @deprecated Import from shema-utils
18
- */
19
- export function getMeshSize(attributes: TypedArrays): number {
20
- let size = 0;
21
- for (const attributeName in attributes) {
22
- const attribute = attributes[attributeName];
23
- if (ArrayBuffer.isView(attribute)) {
24
- // @ts-ignore DataView doesn't have BYTES_PER_ELEMENT
25
- size += attribute.byteLength * attribute.BYTES_PER_ELEMENT;
26
- }
27
- }
28
- return size;
29
- }
30
-
31
- /**
32
- * Get the (axis aligned) bounding box of a mesh
33
- * @param attributes
34
- * @returns array of two vectors representing the axis aligned bounding box
35
- * @deprecated Import from shema-utils
10
+ * Get the (axis aligned) bounding box of a mesh.
11
+ * @param attributes Mesh attributes.
12
+ * @returns The axis aligned bounding box as minimum and maximum vectors.
13
+ * @deprecated Import `getMeshBoundingBox` from `@loaders.gl/schema-utils` instead. This root
14
+ * export remains temporarily for deck.gl 9.4 compatibility.
36
15
  */
37
16
  // eslint-disable-next-line complexity
38
17
  export function getMeshBoundingBox(attributes: MeshAttributes): BoundingBox {
@@ -44,12 +23,12 @@ export function getMeshBoundingBox(attributes: MeshAttributes): BoundingBox {
44
23
  let maxZ = -Infinity;
45
24
 
46
25
  const positions = attributes.POSITION ? attributes.POSITION.value : [];
47
- const len = positions && positions.length;
26
+ const length = positions && positions.length;
48
27
 
49
- for (let i = 0; i < len; i += 3) {
50
- const x = positions[i];
51
- const y = positions[i + 1];
52
- const z = positions[i + 2];
28
+ for (let index = 0; index < length; index += 3) {
29
+ const x = positions[index];
30
+ const y = positions[index + 1];
31
+ const z = positions[index + 2];
53
32
 
54
33
  minX = x < minX ? x : minX;
55
34
  minY = y < minY ? y : minY;
@@ -59,6 +38,7 @@ export function getMeshBoundingBox(attributes: MeshAttributes): BoundingBox {
59
38
  maxY = y > maxY ? y : maxY;
60
39
  maxZ = z > maxZ ? z : maxZ;
61
40
  }
41
+
62
42
  return [
63
43
  [minX, minY, minZ],
64
44
  [maxX, maxY, maxZ]
package/src/float16.ts ADDED
@@ -0,0 +1,111 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {getFloat16ArrayConstructor, NativeFloat16ArrayConstructor} from '@math.gl/types';
6
+
7
+ /** Array storage used for logical Float16 values. */
8
+ export type Float16ArrayStorage = Float16Array | Uint16Array;
9
+
10
+ /** Create native Float16 storage when the runtime supports it. */
11
+ export function createFloat16Array(length: number): Float16ArrayStorage {
12
+ const ArrayConstructor = getFloat16ArrayConstructor();
13
+ return new ArrayConstructor(length) as Float16ArrayStorage;
14
+ }
15
+
16
+ /** Check whether an array is backed by the native Float16Array implementation. */
17
+ export function isNativeFloat16Array(value: unknown): value is Float16Array {
18
+ return Boolean(NativeFloat16ArrayConstructor && value instanceof NativeFloat16ArrayConstructor);
19
+ }
20
+
21
+ /** Write a numeric value into native or binary16 fallback storage. */
22
+ export function setFloat16Value(array: Float16ArrayStorage, index: number, value: number): void {
23
+ if (isNativeFloat16Array(array)) {
24
+ array[index] = value;
25
+ } else {
26
+ array[index] = encodeFloat16(value);
27
+ }
28
+ }
29
+
30
+ /** Read a numeric value from native or binary16 fallback storage. */
31
+ export function getFloat16Value(array: Float16ArrayStorage, index: number): number {
32
+ if (isNativeFloat16Array(array)) {
33
+ return array[index];
34
+ }
35
+ return decodeFloat16(array[index]);
36
+ }
37
+
38
+ /** Return the binary16 words used by Apache Arrow and GPU APIs. */
39
+ export function getFloat16Storage(array: Float16ArrayStorage): Uint16Array {
40
+ return isNativeFloat16Array(array)
41
+ ? new Uint16Array(array.buffer, array.byteOffset, array.length)
42
+ : array;
43
+ }
44
+
45
+ /** Convert byte- or word-scaled color components to logical Float16 values. */
46
+ export function convertColorArrayToFloat16(
47
+ values: ArrayLike<number>,
48
+ sourceScale: number
49
+ ): Float16ArrayStorage {
50
+ const result = createFloat16Array(values.length);
51
+ for (let index = 0; index < values.length; index++) {
52
+ setFloat16Value(result, index, values[index] / sourceScale);
53
+ }
54
+ return result;
55
+ }
56
+
57
+ /** Convert byte- or word-scaled color components to logical Float32 values. */
58
+ export function convertColorArrayToFloat32(
59
+ values: ArrayLike<number>,
60
+ sourceScale: number
61
+ ): Float32Array {
62
+ return Float32Array.from(values, value => value / sourceScale);
63
+ }
64
+
65
+ /** Encode a JavaScript number as an IEEE-754 binary16 bit pattern. */
66
+ export function encodeFloat16(value: number): number {
67
+ if (!Number.isFinite(value)) {
68
+ return value === Infinity ? 0x7c00 : value === -Infinity ? 0xfc00 : 0x7e00;
69
+ }
70
+
71
+ const sign = value < 0 || Object.is(value, -0) ? 0x8000 : 0;
72
+ const absoluteValue = Math.abs(value);
73
+ if (absoluteValue === 0) {
74
+ return sign;
75
+ }
76
+
77
+ // Values at or above the midpoint between the largest finite half and
78
+ // infinity round to infinity using IEEE-754 round-to-nearest-even.
79
+ if (absoluteValue >= 65520) {
80
+ return sign | 0x7c00;
81
+ }
82
+ if (absoluteValue >= 65504) {
83
+ return sign | 0x7bff;
84
+ }
85
+
86
+ const exponent = Math.floor(Math.log2(absoluteValue));
87
+ if (exponent < -14) {
88
+ return sign | Math.round(absoluteValue / 2 ** -24);
89
+ }
90
+
91
+ const normalizedExponent = exponent + 15;
92
+ const mantissa = Math.round((absoluteValue / 2 ** exponent - 1) * 1024);
93
+ if (mantissa === 1024) {
94
+ return sign | ((normalizedExponent + 1) << 10);
95
+ }
96
+ return sign | (normalizedExponent << 10) | mantissa;
97
+ }
98
+
99
+ /** Decode an IEEE-754 binary16 bit pattern. */
100
+ function decodeFloat16(value: number): number {
101
+ const sign = value & 0x8000 ? -1 : 1;
102
+ const exponent = (value >> 10) & 0x1f;
103
+ const mantissa = value & 0x3ff;
104
+ if (exponent === 0) {
105
+ return sign * mantissa * 2 ** -24;
106
+ }
107
+ if (exponent === 0x1f) {
108
+ return mantissa ? NaN : sign * Infinity;
109
+ }
110
+ return sign * (1 + mantissa / 1024) * 2 ** (exponent - 15);
111
+ }
@@ -0,0 +1,54 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type * as arrow from 'apache-arrow';
6
+ import type {BinaryFeatureCollection, BinaryProperties} from './binary-features';
7
+ import type {BinaryGeometryType} from './binary-geometries';
8
+
9
+ /** One Arrow-backed binary feature family table. */
10
+ export type ArrowBinaryFeatureTable = {
11
+ /** Geometry family stored in this table. */
12
+ type: BinaryGeometryType;
13
+ /** Arrow table wrapper for the family. */
14
+ table: arrow.Table;
15
+ /** Original feature-level properties sidecar from the binary feature collection. */
16
+ properties: BinaryProperties['properties'];
17
+ /** Optional original feature fields sidecar. */
18
+ fields?: BinaryProperties['fields'];
19
+ };
20
+
21
+ /** Arrow-backed wrapper for binary point features. */
22
+ export type ArrowBinaryPointFeature = ArrowBinaryFeatureTable & {
23
+ type: 'Point';
24
+ };
25
+
26
+ /** Arrow-backed wrapper for binary line features. */
27
+ export type ArrowBinaryLineFeature = ArrowBinaryFeatureTable & {
28
+ type: 'LineString';
29
+ };
30
+
31
+ /** Arrow-backed wrapper for binary polygon features. */
32
+ export type ArrowBinaryPolygonFeature = ArrowBinaryFeatureTable & {
33
+ type: 'Polygon';
34
+ };
35
+
36
+ /**
37
+ * Arrow-backed wrapper for a binary feature collection.
38
+ *
39
+ * This mirrors the existing `BinaryFeatureCollection` family split while exposing the
40
+ * renderable arrays through Arrow nested list columns.
41
+ */
42
+ export type ArrowBinaryFeatureCollection = {
43
+ /** Discriminator for Arrow-backed binary feature collections. */
44
+ shape: 'arrow-binary-feature-collection';
45
+ /** Optional Arrow-backed point family table. */
46
+ points?: ArrowBinaryPointFeature;
47
+ /** Optional Arrow-backed line family table. */
48
+ lines?: ArrowBinaryLineFeature;
49
+ /** Optional Arrow-backed polygon family table. */
50
+ polygons?: ArrowBinaryPolygonFeature;
51
+ };
52
+
53
+ /** Supported binary feature collection wrapper shapes. */
54
+ export type BinaryFeatureCollectionLike = BinaryFeatureCollection | ArrowBinaryFeatureCollection;
@@ -0,0 +1,116 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /** Canonical GeoArrow extension names. */
6
+ export type GeoArrowEncoding =
7
+ | 'geoarrow.geometry'
8
+ | 'geoarrow.geometrycollection'
9
+ | 'geoarrow.multipolygon'
10
+ | 'geoarrow.polygon'
11
+ | 'geoarrow.multilinestring'
12
+ | 'geoarrow.linestring'
13
+ | 'geoarrow.multipoint'
14
+ | 'geoarrow.point'
15
+ | 'geoarrow.box'
16
+ | 'geoarrow.wkb'
17
+ | 'geoarrow.wkt';
18
+
19
+ /** Preferred output policy for loader-facing GeoArrow conversions. */
20
+ export type GeoArrowEncodingPreference = 'geoarrow.wkb' | 'geoarrow.geometry' | 'optimized';
21
+
22
+ /** Coordinate dimensions understood by GeoArrow and GeoParquet. */
23
+ export type GeoArrowDimension = 'xy' | 'xyz' | 'xym' | 'xyzm';
24
+
25
+ /** Coordinate memory layouts understood by GeoArrow. */
26
+ export type GeoArrowCoordinateLayout = 'interleaved' | 'separated';
27
+
28
+ /** Offset widths supported by variable-length GeoArrow arrays. */
29
+ export type GeoArrowOffsetType = 'int32' | 'int64';
30
+
31
+ /** One axis-aligned GeoArrow Box value in canonical child order. */
32
+ export type GeoArrowBox = {
33
+ xmin: number;
34
+ ymin: number;
35
+ xmax: number;
36
+ ymax: number;
37
+ zmin?: number;
38
+ zmax?: number;
39
+ mmin?: number;
40
+ mmax?: number;
41
+ };
42
+
43
+ /** Non-planar edge interpretations used by geospatial metadata. */
44
+ export type GeoArrowEdgeType = 'spherical' | 'vincenty' | 'thomas' | 'andoyer' | 'karney';
45
+
46
+ /** Geometry type names used by GeoParquet metadata. */
47
+ export type GeoParquetGeometryType =
48
+ | 'Point'
49
+ | 'LineString'
50
+ | 'Polygon'
51
+ | 'MultiPoint'
52
+ | 'MultiLineString'
53
+ | 'MultiPolygon'
54
+ | 'GeometryCollection'
55
+ | 'Point Z'
56
+ | 'LineString Z'
57
+ | 'Polygon Z'
58
+ | 'MultiPoint Z'
59
+ | 'MultiLineString Z'
60
+ | 'MultiPolygon Z'
61
+ | 'GeometryCollection Z'
62
+ | 'Point M'
63
+ | 'LineString M'
64
+ | 'Polygon M'
65
+ | 'MultiPoint M'
66
+ | 'MultiLineString M'
67
+ | 'MultiPolygon M'
68
+ | 'GeometryCollection M'
69
+ | 'Point ZM'
70
+ | 'LineString ZM'
71
+ | 'Polygon ZM'
72
+ | 'MultiPoint ZM'
73
+ | 'MultiLineString ZM'
74
+ | 'MultiPolygon ZM'
75
+ | 'GeometryCollection ZM';
76
+
77
+ /** JSON-compatible CRS value accepted by GeoArrow extension metadata. */
78
+ export type GeoArrowCRSValue = Record<string, unknown> | string;
79
+
80
+ /** CRS representation tag used by GeoArrow extension metadata. */
81
+ export type GeoArrowCRSType = 'projjson' | 'wkt2:2019' | 'authority_code' | 'srid';
82
+
83
+ /** CRS metadata attached to a GeoArrow field. */
84
+ export type GeoArrowCRSMetadata =
85
+ | {crs?: undefined; crs_type?: undefined}
86
+ | {crs: Record<string, unknown>; crs_type?: 'projjson'}
87
+ | {crs: string; crs_type: 'wkt2:2019' | 'authority_code' | 'srid'}
88
+ | {crs: string; crs_type?: undefined};
89
+
90
+ /** Metadata attached to a GeoArrow extension field. */
91
+ export type GeoArrowMetadata = GeoArrowCRSMetadata & {
92
+ encoding?: GeoArrowEncoding;
93
+ edges?: GeoArrowEdgeType;
94
+ geometry_types?: GeoParquetGeometryType[];
95
+ [key: string]: unknown;
96
+ };
97
+
98
+ /** Metadata for one geometry column in a GeoParquet file. */
99
+ export type GeoColumnMetadata = {
100
+ encoding: string;
101
+ geometry_types: GeoParquetGeometryType[];
102
+ crs?: Record<string, unknown> | null;
103
+ orientation?: 'counterclockwise';
104
+ bbox?: number[];
105
+ edges?: 'planar' | GeoArrowEdgeType;
106
+ epoch?: number;
107
+ [key: string]: unknown;
108
+ };
109
+
110
+ /** File-level GeoParquet metadata stored under the `geo` key. */
111
+ export type GeoMetadata = {
112
+ version?: string;
113
+ primary_column?: string;
114
+ columns: Record<string, GeoColumnMetadata>;
115
+ [key: string]: unknown;
116
+ };
package/src/index.ts CHANGED
@@ -12,11 +12,47 @@ export type {
12
12
  ArrayType,
13
13
  AnyArray
14
14
  } from './types/types';
15
+ export {
16
+ createFloat16Array,
17
+ convertColorArrayToFloat16,
18
+ convertColorArrayToFloat32,
19
+ encodeFloat16,
20
+ getFloat16Storage,
21
+ getFloat16Value,
22
+ isNativeFloat16Array,
23
+ setFloat16Value
24
+ } from './float16';
15
25
 
16
26
  // SCHEMAS AND DATA TYPES
17
27
 
18
- export type {Schema, Field, DataType, SchemaMetadata, FieldMetadata} from './types/schema';
28
+ export type {Schema, Field, DataType, KeyType, SchemaMetadata, FieldMetadata} from './types/schema';
29
+ export type {Metadata, SchemaWithMetadata} from './metadata';
30
+ export {
31
+ getGeoMetadata,
32
+ getMetadataValue,
33
+ parseJSONStringMetadata,
34
+ setGeoMetadata,
35
+ setMetadataValue,
36
+ unpackGeoMetadata,
37
+ unpackJSONStringMetadata
38
+ } from './metadata';
19
39
  export type {Batch} from './types/batch';
40
+ export type {
41
+ GeoArrowEncoding,
42
+ GeoArrowEncodingPreference,
43
+ GeoArrowDimension,
44
+ GeoArrowCoordinateLayout,
45
+ GeoArrowOffsetType,
46
+ GeoArrowBox,
47
+ GeoArrowEdgeType,
48
+ GeoArrowCRSValue,
49
+ GeoArrowCRSType,
50
+ GeoArrowCRSMetadata,
51
+ GeoArrowMetadata,
52
+ GeoParquetGeometryType,
53
+ GeoColumnMetadata,
54
+ GeoMetadata
55
+ } from './geometry/geoarrow';
20
56
 
21
57
  // TABLE CATEGORY TYPES
22
58
  export type {
@@ -42,12 +78,22 @@ export type {
42
78
  export type {
43
79
  MeshTable,
44
80
  MeshArrowTable,
81
+ MeshArrowColumns,
82
+ IndexedMeshArrowColumns,
83
+ MeshArrowTableData,
84
+ IndexedMeshArrowTableData,
45
85
  Mesh,
46
86
  MeshGeometry,
47
87
  MeshAttribute,
48
- MeshAttributes
88
+ MeshAttributeOctahedronTransform,
89
+ MeshAttributeQuantizationTransform,
90
+ MeshAttributeTransform,
91
+ MeshAttributes,
92
+ MeshTopology
49
93
  } from './categories/category-mesh';
50
-
94
+ export {meshArrowSchema, indexedMeshArrowSchema} from './categories/category-mesh';
95
+ /** @deprecated Import `getMeshBoundingBox` from `@loaders.gl/schema-utils`. */
96
+ export {getMeshBoundingBox} from './deprecated/mesh-utils';
51
97
  // TEXTURES
52
98
  export type {
53
99
  TextureMetadata,
@@ -113,9 +159,11 @@ export type {
113
159
  BinaryLineFeature,
114
160
  BinaryPolygonFeature
115
161
  } from './categories/category-gis';
116
-
117
- // DEPRECATED
118
-
119
- // MESH CATEGORY
120
-
121
- export {getMeshSize, getMeshBoundingBox} from './deprecated/mesh-utils';
162
+ export type {
163
+ ArrowBinaryFeatureTable,
164
+ ArrowBinaryPointFeature,
165
+ ArrowBinaryLineFeature,
166
+ ArrowBinaryPolygonFeature,
167
+ ArrowBinaryFeatureCollection,
168
+ BinaryFeatureCollectionLike
169
+ } from './categories/category-gis';
@@ -0,0 +1,115 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {GeoMetadata} from './geometry/geoarrow';
6
+
7
+ /** Metadata container compatible with Apache Arrow metadata maps and plain objects. */
8
+ export type Metadata = Map<string, string> | Record<string, string>;
9
+
10
+ /** Arrow-like schema shape that exposes schema and field metadata. */
11
+ export type SchemaWithMetadata = {
12
+ /** Schema-level metadata. */
13
+ metadata?: Metadata;
14
+ /** Top-level fields with optional metadata. */
15
+ fields?: {name: string; metadata?: Metadata}[];
16
+ };
17
+
18
+ /**
19
+ * Reads one metadata value from an Arrow-like metadata container.
20
+ *
21
+ * @param metadata Metadata map or object.
22
+ * @param key Metadata key.
23
+ * @returns Stored value or `null` when absent.
24
+ */
25
+ export function getMetadataValue(metadata: Metadata, key: string): string | null {
26
+ return metadata instanceof Map ? metadata.get(key) || null : metadata[key] || null;
27
+ }
28
+
29
+ /**
30
+ * Writes one metadata value to an Arrow-like metadata container.
31
+ *
32
+ * @param metadata Metadata map or object.
33
+ * @param key Metadata key.
34
+ * @param value Metadata value.
35
+ */
36
+ export function setMetadataValue(metadata: Metadata, key: string, value: string): void {
37
+ if (metadata instanceof Map) {
38
+ metadata.set(key, value);
39
+ } else {
40
+ metadata[key] = value;
41
+ }
42
+ }
43
+
44
+ /** Reads GeoParquet metadata from a schema metadata container. */
45
+ export function getGeoMetadata(metadata: Metadata | undefined): GeoMetadata | null {
46
+ if (!metadata) {
47
+ return null;
48
+ }
49
+
50
+ const stringifiedGeoMetadata = getMetadataValue(metadata, 'geo');
51
+ const geoMetadata = stringifiedGeoMetadata && parseJSONStringMetadata(stringifiedGeoMetadata);
52
+ if (!geoMetadata) {
53
+ return null;
54
+ }
55
+
56
+ for (const column of Object.values(geoMetadata.columns || {})) {
57
+ if (column && typeof column === 'object' && typeof column.encoding === 'string') {
58
+ column.encoding = column.encoding.toLowerCase();
59
+ }
60
+ }
61
+
62
+ return geoMetadata as GeoMetadata;
63
+ }
64
+
65
+ /** Stores GeoParquet metadata under the top-level `geo` key. */
66
+ export function setGeoMetadata(metadata: Metadata, geoMetadata: GeoMetadata): void {
67
+ setMetadataValue(metadata, 'geo', JSON.stringify(geoMetadata));
68
+ }
69
+
70
+ /** Unpacks top-level GeoParquet metadata into flattened metadata entries. */
71
+ export function unpackGeoMetadata(metadata: Metadata): void {
72
+ const geoMetadata = getGeoMetadata(metadata);
73
+ if (!geoMetadata) {
74
+ return;
75
+ }
76
+
77
+ const {version, primary_column: primaryColumn, columns} = geoMetadata;
78
+ if (version) {
79
+ setMetadataValue(metadata, 'geo.version', version);
80
+ }
81
+ if (primaryColumn) {
82
+ setMetadataValue(metadata, 'geo.primary_column', primaryColumn);
83
+ }
84
+ setMetadataValue(metadata, 'geo.columns', Object.keys(columns || {}).join(','));
85
+ }
86
+
87
+ /** Unpacks one JSON metadata value into flattened metadata entries. */
88
+ export function unpackJSONStringMetadata(metadata: Metadata, metadataKey: string): void {
89
+ const stringifiedMetadata = getMetadataValue(metadata, metadataKey);
90
+ const json = stringifiedMetadata && parseJSONStringMetadata(stringifiedMetadata);
91
+
92
+ for (const [key, value] of Object.entries(json || {})) {
93
+ setMetadataValue(
94
+ metadata,
95
+ `${metadataKey}.${key}`,
96
+ typeof value === 'string' ? value : JSON.stringify(value)
97
+ );
98
+ }
99
+ }
100
+
101
+ /** Parses one JSON metadata value into an object. */
102
+ export function parseJSONStringMetadata(
103
+ stringifiedMetadata: string
104
+ ): Record<string, unknown> | null {
105
+ if (!stringifiedMetadata) {
106
+ return null;
107
+ }
108
+
109
+ try {
110
+ const metadata = JSON.parse(stringifiedMetadata);
111
+ return metadata && typeof metadata === 'object' ? metadata : null;
112
+ } catch {
113
+ return null;
114
+ }
115
+ }