@loaders.gl/flatgeobuf 4.2.0-alpha.4 → 4.2.0-alpha.5

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 (135) hide show
  1. package/dist/dist.dev.js +286 -241
  2. package/dist/dist.min.js +30 -0
  3. package/dist/flatgeobuf/3.27.2/column-meta.d.ts +1 -1
  4. package/dist/flatgeobuf/3.27.2/column-meta.d.ts.map +1 -1
  5. package/dist/flatgeobuf/3.27.2/column-meta.js +1 -2
  6. package/dist/flatgeobuf/3.27.2/config.js +16 -13
  7. package/dist/flatgeobuf/3.27.2/constants.js +3 -2
  8. package/dist/flatgeobuf/3.27.2/crs-meta.js +1 -2
  9. package/dist/flatgeobuf/3.27.2/dumptree.js +28 -23
  10. package/dist/flatgeobuf/3.27.2/feature.d.ts +1 -1
  11. package/dist/flatgeobuf/3.27.2/feature.d.ts.map +1 -1
  12. package/dist/flatgeobuf/3.27.2/feature.js +2 -3
  13. package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.js +19 -19
  14. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.d.ts +1 -1
  15. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.d.ts.map +1 -1
  16. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.js +117 -117
  17. package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.js +76 -76
  18. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.d.ts +2 -2
  19. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.d.ts.map +1 -1
  20. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.js +96 -90
  21. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.js +22 -22
  22. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.d.ts +1 -1
  23. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.d.ts.map +1 -1
  24. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.js +224 -210
  25. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.d.ts +3 -3
  26. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.d.ts.map +1 -1
  27. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.js +166 -160
  28. package/dist/flatgeobuf/3.27.2/flat-geobuf.d.ts +5 -5
  29. package/dist/flatgeobuf/3.27.2/flat-geobuf.d.ts.map +1 -1
  30. package/dist/flatgeobuf/3.27.2/flat-geobuf.js +1 -1
  31. package/dist/flatgeobuf/3.27.2/generic/feature.d.ts +4 -4
  32. package/dist/flatgeobuf/3.27.2/generic/feature.d.ts.map +1 -1
  33. package/dist/flatgeobuf/3.27.2/generic/feature.js +195 -205
  34. package/dist/flatgeobuf/3.27.2/generic/featurecollection.d.ts +6 -6
  35. package/dist/flatgeobuf/3.27.2/generic/featurecollection.d.ts.map +1 -1
  36. package/dist/flatgeobuf/3.27.2/generic/featurecollection.js +150 -128
  37. package/dist/flatgeobuf/3.27.2/generic/geometry.d.ts +2 -2
  38. package/dist/flatgeobuf/3.27.2/generic/geometry.d.ts.map +1 -1
  39. package/dist/flatgeobuf/3.27.2/generic/geometry.js +78 -66
  40. package/dist/flatgeobuf/3.27.2/generic/header.d.ts +3 -3
  41. package/dist/flatgeobuf/3.27.2/generic/header.d.ts.map +1 -1
  42. package/dist/flatgeobuf/3.27.2/generic/header.js +18 -18
  43. package/dist/flatgeobuf/3.27.2/generic/index.d.ts +4 -4
  44. package/dist/flatgeobuf/3.27.2/generic/index.d.ts.map +1 -1
  45. package/dist/flatgeobuf/3.27.2/generic/index.js +2 -1
  46. package/dist/flatgeobuf/3.27.2/generic.d.ts +7 -7
  47. package/dist/flatgeobuf/3.27.2/generic.d.ts.map +1 -1
  48. package/dist/flatgeobuf/3.27.2/generic.js +11 -3
  49. package/dist/flatgeobuf/3.27.2/geojson/feature.d.ts +3 -3
  50. package/dist/flatgeobuf/3.27.2/geojson/feature.d.ts.map +1 -1
  51. package/dist/flatgeobuf/3.27.2/geojson/feature.js +8 -9
  52. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.d.ts +2 -2
  53. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.d.ts.map +1 -1
  54. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.js +40 -38
  55. package/dist/flatgeobuf/3.27.2/geojson/geometry.d.ts +3 -3
  56. package/dist/flatgeobuf/3.27.2/geojson/geometry.d.ts.map +1 -1
  57. package/dist/flatgeobuf/3.27.2/geojson/geometry.js +107 -103
  58. package/dist/flatgeobuf/3.27.2/geojson/index.d.ts +3 -3
  59. package/dist/flatgeobuf/3.27.2/geojson/index.d.ts.map +1 -1
  60. package/dist/flatgeobuf/3.27.2/geojson/index.js +2 -1
  61. package/dist/flatgeobuf/3.27.2/geojson.d.ts +3 -3
  62. package/dist/flatgeobuf/3.27.2/geojson.d.ts.map +1 -1
  63. package/dist/flatgeobuf/3.27.2/geojson.js +17 -5
  64. package/dist/flatgeobuf/3.27.2/header-meta.d.ts +3 -3
  65. package/dist/flatgeobuf/3.27.2/header-meta.d.ts.map +1 -1
  66. package/dist/flatgeobuf/3.27.2/header-meta.js +46 -43
  67. package/dist/flatgeobuf/3.27.2/header.d.ts +1 -1
  68. package/dist/flatgeobuf/3.27.2/header.d.ts.map +1 -1
  69. package/dist/flatgeobuf/3.27.2/header.js +2 -3
  70. package/dist/flatgeobuf/3.27.2/http-reader.d.ts +3 -3
  71. package/dist/flatgeobuf/3.27.2/http-reader.d.ts.map +1 -1
  72. package/dist/flatgeobuf/3.27.2/http-reader.js +235 -171
  73. package/dist/flatgeobuf/3.27.2/index.d.ts +13 -13
  74. package/dist/flatgeobuf/3.27.2/index.d.ts.map +1 -1
  75. package/dist/flatgeobuf/3.27.2/index.js +5 -13
  76. package/dist/flatgeobuf/3.27.2/logger.js +37 -56
  77. package/dist/flatgeobuf/3.27.2/packedrtree.js +174 -123
  78. package/dist/flatgeobuf/3.27.2/streams/utils.js +59 -58
  79. package/dist/flatgeobuf-loader.js +28 -22
  80. package/dist/index.cjs +175 -199
  81. package/dist/index.cjs.map +7 -0
  82. package/dist/index.d.ts +2 -2
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +3 -1
  85. package/dist/lib/binary-geometries.js +115 -117
  86. package/dist/lib/get-schema-from-fgb-header.js +110 -85
  87. package/dist/lib/parse-flatgeobuf.d.ts +1 -1
  88. package/dist/lib/parse-flatgeobuf.d.ts.map +1 -1
  89. package/dist/lib/parse-flatgeobuf.js +125 -109
  90. package/dist/workers/flatgeobuf-worker.js +3 -1
  91. package/package.json +10 -6
  92. package/src/flatgeobuf/3.27.2/.DS_Store +0 -0
  93. package/dist/LICENSE +0 -9
  94. package/dist/flatgeobuf/3.27.2/LICENSE +0 -29
  95. package/dist/flatgeobuf/3.27.2/README.md +0 -45
  96. package/dist/flatgeobuf/3.27.2/column-meta.js.map +0 -1
  97. package/dist/flatgeobuf/3.27.2/config.js.map +0 -1
  98. package/dist/flatgeobuf/3.27.2/constants.js.map +0 -1
  99. package/dist/flatgeobuf/3.27.2/crs-meta.js.map +0 -1
  100. package/dist/flatgeobuf/3.27.2/dumptree.js.map +0 -1
  101. package/dist/flatgeobuf/3.27.2/feature.js.map +0 -1
  102. package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.js.map +0 -1
  103. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.js.map +0 -1
  104. package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.js.map +0 -1
  105. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.js.map +0 -1
  106. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.js.map +0 -1
  107. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.js.map +0 -1
  108. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.js.map +0 -1
  109. package/dist/flatgeobuf/3.27.2/flat-geobuf.js.map +0 -1
  110. package/dist/flatgeobuf/3.27.2/generic/feature.js.map +0 -1
  111. package/dist/flatgeobuf/3.27.2/generic/featurecollection.js.map +0 -1
  112. package/dist/flatgeobuf/3.27.2/generic/geometry.js.map +0 -1
  113. package/dist/flatgeobuf/3.27.2/generic/header.js.map +0 -1
  114. package/dist/flatgeobuf/3.27.2/generic/index.js.map +0 -1
  115. package/dist/flatgeobuf/3.27.2/generic.js.map +0 -1
  116. package/dist/flatgeobuf/3.27.2/geojson/feature.js.map +0 -1
  117. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.js.map +0 -1
  118. package/dist/flatgeobuf/3.27.2/geojson/geometry.js.map +0 -1
  119. package/dist/flatgeobuf/3.27.2/geojson/index.js.map +0 -1
  120. package/dist/flatgeobuf/3.27.2/geojson.js.map +0 -1
  121. package/dist/flatgeobuf/3.27.2/header-meta.js.map +0 -1
  122. package/dist/flatgeobuf/3.27.2/header.js.map +0 -1
  123. package/dist/flatgeobuf/3.27.2/http-reader.js.map +0 -1
  124. package/dist/flatgeobuf/3.27.2/index.js.map +0 -1
  125. package/dist/flatgeobuf/3.27.2/logger.js.map +0 -1
  126. package/dist/flatgeobuf/3.27.2/packedrtree.js.map +0 -1
  127. package/dist/flatgeobuf/3.27.2/streams/utils.js.map +0 -1
  128. package/dist/flatgeobuf/3.27.2/types/jsts.d.ts +0 -23
  129. package/dist/flatgeobuf/3.27.2/types/slice.d.ts +0 -16
  130. package/dist/flatgeobuf-loader.js.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/lib/binary-geometries.js.map +0 -1
  133. package/dist/lib/get-schema-from-fgb-header.js.map +0 -1
  134. package/dist/lib/parse-flatgeobuf.js.map +0 -1
  135. package/dist/workers/flatgeobuf-worker.js.map +0 -1
@@ -1,132 +1,130 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  export function fgbToBinaryFeature(geometry, type) {
2
- const fgbGeometry = (geometry === null || geometry === void 0 ? void 0 : geometry.geometry()) || null;
3
- return fgbToBinaryGeometry(fgbGeometry, type);
5
+ const fgbGeometry = geometry?.geometry() || null;
6
+ return fgbToBinaryGeometry(fgbGeometry, type);
4
7
  }
5
8
  export function fgbToBinaryGeometry(geometry, type) {
6
- if (geometry === null) {
7
- return null;
8
- }
9
- switch (type) {
10
- case GeometryType.Point:
11
- case GeometryType.MultiPoint:
12
- return parsePoint(geometry);
13
- case GeometryType.LineString:
14
- case GeometryType.MultiLineString:
15
- return parseLines(geometry);
16
- case GeometryType.Polygon:
17
- return parsePolygons(geometry);
18
- case GeometryType.MultiPolygon:
19
- return parseMultiPolygons(geometry);
20
- default:
21
- throw new Error(`Unimplemented geometry type: ${type}`);
22
- }
9
+ if (geometry === null) {
10
+ return null;
11
+ }
12
+ switch (type) {
13
+ case GeometryType.Point:
14
+ case GeometryType.MultiPoint:
15
+ return parsePoint(geometry);
16
+ case GeometryType.LineString:
17
+ case GeometryType.MultiLineString:
18
+ return parseLines(geometry);
19
+ case GeometryType.Polygon:
20
+ return parsePolygons(geometry);
21
+ case GeometryType.MultiPolygon:
22
+ return parseMultiPolygons(geometry);
23
+ default:
24
+ throw new Error(`Unimplemented geometry type: ${type}`);
25
+ }
23
26
  }
27
+ // Parse Point to flat array
24
28
  function parsePoint(geometry) {
25
- const xy = geometry.xyArray();
26
- const z = geometry.zArray();
27
- const positions = blitArrays(xy, z);
28
- return {
29
- positions
30
- };
29
+ const xy = geometry.xyArray();
30
+ const z = geometry.zArray();
31
+ // @ts-expect-error TODO handle null geometries
32
+ const positions = blitArrays(xy, z);
33
+ return { positions };
31
34
  }
32
35
  function parseLines(geometry) {
33
- const xy = geometry.xyArray();
34
- const z = geometry.zArray();
35
- const positions = blitArrays(xy, z);
36
- const ends = geometry.endsArray() && Array.from(geometry.endsArray()) || [xy.length / 2];
37
- ends.unshift(0);
38
- const pathIndices = {
39
- value: new Uint16Array(ends),
40
- size: 1
41
- };
42
- return {
43
- positions,
44
- pathIndices
45
- };
36
+ const xy = geometry.xyArray();
37
+ const z = geometry.zArray();
38
+ const positions = blitArrays(xy, z);
39
+ // If endsArray is null, a single LineString. Otherwise, contains the end
40
+ // indices of each part of the MultiLineString. geometry.endsArray() omits the
41
+ // initial 0 that we have in our internal format.
42
+ // @ts-expect-error TODO handle null geometries
43
+ const ends = (geometry.endsArray() && Array.from(geometry.endsArray())) || [xy.length / 2];
44
+ ends.unshift(0);
45
+ const pathIndices = { value: new Uint16Array(ends), size: 1 };
46
+ return {
47
+ positions,
48
+ pathIndices
49
+ };
46
50
  }
47
51
  function parsePolygons(geometry) {
48
- const xy = geometry.xyArray();
49
- const z = geometry.zArray();
50
- const positions = blitArrays(xy, z);
51
- const ends = geometry.endsArray() && Array.from(geometry.endsArray()) || [xy.length / 2];
52
- ends.unshift(0);
53
- const primitivePolygonIndices = {
54
- value: new Uint16Array(ends),
55
- size: 1
56
- };
57
- const polygonIndices = {
58
- value: new Uint16Array([0, xy.length / 2]),
59
- size: 1
60
- };
61
- return {
62
- positions,
63
- primitivePolygonIndices,
64
- polygonIndices
65
- };
52
+ const xy = geometry.xyArray();
53
+ const z = geometry.zArray();
54
+ // @ts-expect-error TODO handle null geometries
55
+ const positions = blitArrays(xy, z);
56
+ // If endsArray is null, a simple Polygon with no inner rings. Otherwise,
57
+ // contains the end indices of each ring of the Polygon. geometry.endsArray()
58
+ // omits the initial 0 that we have in our internal format.
59
+ // @ts-expect-error TODO handle null geometries
60
+ const ends = (geometry.endsArray() && Array.from(geometry.endsArray())) || [xy.length / 2];
61
+ ends.unshift(0);
62
+ const primitivePolygonIndices = { value: new Uint16Array(ends), size: 1 };
63
+ const polygonIndices = { value: new Uint16Array([0, xy.length / 2]), size: 1 };
64
+ return {
65
+ positions,
66
+ primitivePolygonIndices,
67
+ polygonIndices
68
+ };
66
69
  }
70
+ // eslint-disable-next-line max-statements
67
71
  function parseMultiPolygons(geometry) {
68
- const parsedParts = [];
69
- let nPositions = 0;
70
- let nPrimitivePolygonIndices = 1;
71
- let nPolygonIndices = 1;
72
- for (let i = 0; i < geometry.partsLength(); i++) {
73
- const part = geometry.parts(i);
74
- const polygon = parsePolygons(part);
75
- nPositions += polygon.positions.value.length;
76
- nPrimitivePolygonIndices += polygon.primitivePolygonIndices.value.length - 1;
77
- nPolygonIndices += polygon.polygonIndices.value.length - 1;
78
- parsedParts.push(polygon);
79
- }
80
- const concatPositions = new Float64Array(nPositions);
81
- const concatPrimitivePolygonIndices = new Uint32Array(nPrimitivePolygonIndices);
82
- const concatPolygonIndices = new Uint32Array(nPolygonIndices);
83
- let positionCounter = 0;
84
- let primitivePolygonIndicesCounter = 1;
85
- let polygonIndicesCounter = 1;
86
- const positionSize = parsedParts[0].positions.size;
87
- for (const parsedPart of parsedParts) {
88
- concatPositions.set(parsedPart.positions.value, positionCounter * positionSize);
89
- concatPrimitivePolygonIndices.set(parsedPart.primitivePolygonIndices.value.subarray(1).map(x => x + positionCounter), primitivePolygonIndicesCounter);
90
- concatPolygonIndices.set(parsedPart.polygonIndices.value.subarray(1).map(x => x + positionCounter), polygonIndicesCounter);
91
- positionCounter += parsedPart.positions.value.length / positionSize;
92
- primitivePolygonIndicesCounter += parsedPart.primitivePolygonIndices.value.length - 1;
93
- polygonIndicesCounter += parsedPart.polygonIndices.value.length - 1;
94
- }
95
- return {
96
- positions: {
97
- value: concatPositions,
98
- size: positionSize
99
- },
100
- primitivePolygonIndices: {
101
- value: concatPrimitivePolygonIndices,
102
- size: 1
103
- },
104
- polygonIndices: {
105
- value: concatPolygonIndices,
106
- size: 1
72
+ // Create arrays for each geometry part, then concatenate
73
+ const parsedParts = [];
74
+ let nPositions = 0;
75
+ let nPrimitivePolygonIndices = 1;
76
+ let nPolygonIndices = 1;
77
+ for (let i = 0; i < geometry.partsLength(); i++) {
78
+ const part = geometry.parts(i);
79
+ // @ts-expect-error TODO handle null geometries
80
+ const polygon = parsePolygons(part);
81
+ nPositions += polygon.positions.value.length;
82
+ nPrimitivePolygonIndices += polygon.primitivePolygonIndices.value.length - 1;
83
+ nPolygonIndices += polygon.polygonIndices.value.length - 1;
84
+ parsedParts.push(polygon);
85
+ }
86
+ const concatPositions = new Float64Array(nPositions);
87
+ const concatPrimitivePolygonIndices = new Uint32Array(nPrimitivePolygonIndices);
88
+ const concatPolygonIndices = new Uint32Array(nPolygonIndices);
89
+ let positionCounter = 0;
90
+ let primitivePolygonIndicesCounter = 1;
91
+ let polygonIndicesCounter = 1;
92
+ // Assumes all parts of the multipolygon have the same size
93
+ const positionSize = parsedParts[0].positions.size;
94
+ for (const parsedPart of parsedParts) {
95
+ concatPositions.set(parsedPart.positions.value, positionCounter * positionSize);
96
+ // For indices, need to add positionCounter so that position indices are
97
+ // correct in the concatenated positions
98
+ concatPrimitivePolygonIndices.set(
99
+ // eslint-disable-next-line
100
+ parsedPart.primitivePolygonIndices.value.subarray(1).map((x) => x + positionCounter), primitivePolygonIndicesCounter);
101
+ concatPolygonIndices.set(
102
+ // eslint-disable-next-line
103
+ parsedPart.polygonIndices.value.subarray(1).map((x) => x + positionCounter), polygonIndicesCounter);
104
+ positionCounter += parsedPart.positions.value.length / positionSize;
105
+ primitivePolygonIndicesCounter += parsedPart.primitivePolygonIndices.value.length - 1;
106
+ polygonIndicesCounter += parsedPart.polygonIndices.value.length - 1;
107
107
  }
108
- };
109
- }
110
- function blitArrays(xy, z) {
111
- if (!z) {
112
108
  return {
113
- value: xy,
114
- size: 2
109
+ positions: { value: concatPositions, size: positionSize },
110
+ primitivePolygonIndices: { value: concatPrimitivePolygonIndices, size: 1 },
111
+ polygonIndices: { value: concatPolygonIndices, size: 1 }
115
112
  };
116
- }
117
- if (z.length * 2 !== xy.length) {
118
- throw new Error('Z array must be half XY array\'s length');
119
- }
120
- const totalLength = xy.length + z.length;
121
- const xyz = new Float64Array(totalLength);
122
- for (let i = 0; i < xy.length / 2; i++) {
123
- xyz[i * 3 + 0] = xy[i * 2 + 0];
124
- xyz[i * 3 + 1] = xy[i * 2 + 1];
125
- xyz[i * 3 + 2] = z[i];
126
- }
127
- return {
128
- value: xyz,
129
- size: 3
130
- };
131
113
  }
132
- //# sourceMappingURL=binary-geometries.js.map
114
+ // Combine xy and z arrays
115
+ function blitArrays(xy, z) {
116
+ if (!z) {
117
+ return { value: xy, size: 2 };
118
+ }
119
+ if (z.length * 2 !== xy.length) {
120
+ throw new Error('Z array must be half XY array\'s length');
121
+ }
122
+ const totalLength = xy.length + z.length;
123
+ const xyz = new Float64Array(totalLength);
124
+ for (let i = 0; i < xy.length / 2; i++) {
125
+ xyz[i * 3 + 0] = xy[i * 2 + 0];
126
+ xyz[i * 3 + 1] = xy[i * 2 + 1];
127
+ xyz[i * 3 + 2] = z[i];
128
+ }
129
+ return { value: xyz, size: 3 };
130
+ }
@@ -1,90 +1,115 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ /**
5
+ * @param fgbHeader
6
+ * geometryType: GeometryType;
7
+ * columns: ColumnMeta[] | null;
8
+ * envelope: Float64Array | null;
9
+ * featuresCount: number;
10
+ * indexNodeSize: number;
11
+ * crs: CrsMeta | null;
12
+ * title: string | null;
13
+ * description: string | null;
14
+ * metadata: string | null;
15
+ */
1
16
  export function getSchemaFromFGBHeader(fgbHeader) {
2
- var _fgbHeader$envelope, _fgbHeader$columns;
3
- const metadata = {
4
- title: fgbHeader.title || '',
5
- description: fgbHeader.description || '',
6
- crs: JSON.stringify(fgbHeader.crs) || '',
7
- metadata: fgbHeader.metadata || '',
8
- geometryType: String(fgbHeader.geometryType),
9
- indexNodeSize: String(fgbHeader.indexNodeSize),
10
- featureCount: String(fgbHeader.featuresCount),
11
- bounds: ((_fgbHeader$envelope = fgbHeader.envelope) === null || _fgbHeader$envelope === void 0 ? void 0 : _fgbHeader$envelope.join(',')) || ''
12
- };
13
- const fields = ((_fgbHeader$columns = fgbHeader.columns) === null || _fgbHeader$columns === void 0 ? void 0 : _fgbHeader$columns.map(column => getFieldFromFGBColumn(column))) || [];
14
- return {
15
- metadata,
16
- fields
17
- };
17
+ const metadata = {
18
+ title: fgbHeader.title || '',
19
+ description: fgbHeader.description || '',
20
+ crs: JSON.stringify(fgbHeader.crs) || '',
21
+ metadata: fgbHeader.metadata || '',
22
+ geometryType: String(fgbHeader.geometryType),
23
+ indexNodeSize: String(fgbHeader.indexNodeSize),
24
+ featureCount: String(fgbHeader.featuresCount),
25
+ bounds: fgbHeader.envelope?.join(',') || ''
26
+ };
27
+ const fields = fgbHeader.columns?.map((column) => getFieldFromFGBColumn(column)) || [];
28
+ return { metadata, fields };
18
29
  }
30
+ /**
31
+ * name: string;
32
+ * type: ColumnType;
33
+ * title: string | null;
34
+ * description: string | null;
35
+ * width: number;
36
+ * precision: number;
37
+ * scale: number;
38
+ * nullable: boolean;
39
+ * unique: boolean;
40
+ * primary_key: boolean;
41
+ */
19
42
  function getFieldFromFGBColumn(fgbColumn) {
20
- const metadata = {
21
- title: fgbColumn.title || '',
22
- description: fgbColumn.description || '',
23
- width: String(fgbColumn.width),
24
- precision: String(fgbColumn.precision),
25
- scale: String(fgbColumn.scale),
26
- unique: String(fgbColumn.unique),
27
- primary_key: String(fgbColumn.primary_key)
28
- };
29
- return {
30
- name: fgbColumn.name,
31
- type: getTypeFromFGBType(fgbColumn.type),
32
- nullable: fgbColumn.nullable,
33
- metadata
34
- };
43
+ const metadata = {
44
+ title: fgbColumn.title || '',
45
+ description: fgbColumn.description || '',
46
+ width: String(fgbColumn.width),
47
+ precision: String(fgbColumn.precision),
48
+ scale: String(fgbColumn.scale),
49
+ unique: String(fgbColumn.unique),
50
+ primary_key: String(fgbColumn.primary_key)
51
+ };
52
+ return {
53
+ name: fgbColumn.name,
54
+ type: getTypeFromFGBType(fgbColumn.type),
55
+ nullable: fgbColumn.nullable,
56
+ metadata
57
+ };
35
58
  }
36
- var fgbColumnType = function (fgbColumnType) {
37
- fgbColumnType[fgbColumnType["Byte"] = 0] = "Byte";
38
- fgbColumnType[fgbColumnType["UByte"] = 1] = "UByte";
39
- fgbColumnType[fgbColumnType["Bool"] = 2] = "Bool";
40
- fgbColumnType[fgbColumnType["Short"] = 3] = "Short";
41
- fgbColumnType[fgbColumnType["UShort"] = 4] = "UShort";
42
- fgbColumnType[fgbColumnType["Int"] = 5] = "Int";
43
- fgbColumnType[fgbColumnType["UInt"] = 6] = "UInt";
44
- fgbColumnType[fgbColumnType["Long"] = 7] = "Long";
45
- fgbColumnType[fgbColumnType["ULong"] = 8] = "ULong";
46
- fgbColumnType[fgbColumnType["Float"] = 9] = "Float";
47
- fgbColumnType[fgbColumnType["Double"] = 10] = "Double";
48
- fgbColumnType[fgbColumnType["String"] = 11] = "String";
49
- fgbColumnType[fgbColumnType["Json"] = 12] = "Json";
50
- fgbColumnType[fgbColumnType["DateTime"] = 13] = "DateTime";
51
- fgbColumnType[fgbColumnType["Binary"] = 14] = "Binary";
52
- return fgbColumnType;
53
- }(fgbColumnType || {});
54
- function getTypeFromFGBType(fgbType) {
55
- switch (fgbType) {
56
- case fgbColumnType.Byte:
57
- return 'int8';
58
- case fgbColumnType.UByte:
59
- return 'uint8';
60
- case fgbColumnType.Bool:
61
- return 'bool';
62
- case fgbColumnType.Short:
63
- return 'int16';
64
- case fgbColumnType.UShort:
65
- return 'uint16';
66
- case fgbColumnType.Int:
67
- return 'int32';
68
- case fgbColumnType.UInt:
69
- return 'uint32';
70
- case fgbColumnType.Long:
71
- return 'int64';
72
- case fgbColumnType.ULong:
73
- return 'uint64';
74
- case fgbColumnType.Float:
75
- return 'float32';
76
- case fgbColumnType.Double:
77
- return 'float64';
78
- case fgbColumnType.String:
79
- return 'utf8';
80
- case fgbColumnType.Json:
81
- return 'null';
82
- case fgbColumnType.DateTime:
83
- return 'date-millisecond';
84
- case fgbColumnType.Binary:
85
- return 'binary';
86
- default:
87
- return 'null';
88
- }
59
+ /** Note: fgb.ColumType does not appear to be exported */
60
+ var fgbColumnType;
61
+ (function (fgbColumnType) {
62
+ fgbColumnType[fgbColumnType["Byte"] = 0] = "Byte";
63
+ fgbColumnType[fgbColumnType["UByte"] = 1] = "UByte";
64
+ fgbColumnType[fgbColumnType["Bool"] = 2] = "Bool";
65
+ fgbColumnType[fgbColumnType["Short"] = 3] = "Short";
66
+ fgbColumnType[fgbColumnType["UShort"] = 4] = "UShort";
67
+ fgbColumnType[fgbColumnType["Int"] = 5] = "Int";
68
+ fgbColumnType[fgbColumnType["UInt"] = 6] = "UInt";
69
+ fgbColumnType[fgbColumnType["Long"] = 7] = "Long";
70
+ fgbColumnType[fgbColumnType["ULong"] = 8] = "ULong";
71
+ fgbColumnType[fgbColumnType["Float"] = 9] = "Float";
72
+ fgbColumnType[fgbColumnType["Double"] = 10] = "Double";
73
+ fgbColumnType[fgbColumnType["String"] = 11] = "String";
74
+ fgbColumnType[fgbColumnType["Json"] = 12] = "Json";
75
+ fgbColumnType[fgbColumnType["DateTime"] = 13] = "DateTime";
76
+ fgbColumnType[fgbColumnType["Binary"] = 14] = "Binary";
77
+ })(fgbColumnType || (fgbColumnType = {}));
78
+ /** Convert FGB types to arrow like types */
79
+ // eslint-disable-next-line complexity
80
+ function getTypeFromFGBType(fgbType /* fgb.ColumnMeta['type'] */) {
81
+ switch (fgbType) {
82
+ case fgbColumnType.Byte:
83
+ return 'int8';
84
+ case fgbColumnType.UByte:
85
+ return 'uint8';
86
+ case fgbColumnType.Bool:
87
+ return 'bool';
88
+ case fgbColumnType.Short:
89
+ return 'int16';
90
+ case fgbColumnType.UShort:
91
+ return 'uint16';
92
+ case fgbColumnType.Int:
93
+ return 'int32';
94
+ case fgbColumnType.UInt:
95
+ return 'uint32';
96
+ case fgbColumnType.Long:
97
+ return 'int64';
98
+ case fgbColumnType.ULong:
99
+ return 'uint64';
100
+ case fgbColumnType.Float:
101
+ return 'float32';
102
+ case fgbColumnType.Double:
103
+ return 'float64';
104
+ case fgbColumnType.String:
105
+ return 'utf8';
106
+ case fgbColumnType.Json:
107
+ return 'null';
108
+ case fgbColumnType.DateTime:
109
+ return 'date-millisecond';
110
+ case fgbColumnType.Binary:
111
+ return 'binary';
112
+ default:
113
+ return 'null';
114
+ }
89
115
  }
90
- //# sourceMappingURL=get-schema-from-fgb-header.js.map
@@ -1,4 +1,4 @@
1
- import type { FlatGeobufLoaderOptions } from '../flatgeobuf-loader';
1
+ import type { FlatGeobufLoaderOptions } from "../flatgeobuf-loader.js";
2
2
  import type { Table } from '@loaders.gl/schema';
3
3
  import * as fgb from '../flatgeobuf/3.27.2';
4
4
  export declare function parseFlatGeobuf(arrayBuffer: ArrayBuffer, options?: FlatGeobufLoaderOptions): Table;
@@ -1 +1 @@
1
- {"version":3,"file":"parse-flatgeobuf.d.ts","sourceRoot":"","sources":["../../src/lib/parse-flatgeobuf.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAe,KAAK,EAAS,MAAM,oBAAoB,CAAC;AAKpE,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAC;AAgC5C,wBAAgB,eAAe,CAC7B,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,uBAAuB,GAChC,KAAK,CAoBP;AAyDD,wBAAgB,wBAAwB,CAAC,MAAM,KAAA,EAAE,OAAO,EAAE,uBAAuB,2FAUhF"}
1
+ {"version":3,"file":"parse-flatgeobuf.d.ts","sourceRoot":"","sources":["../../src/lib/parse-flatgeobuf.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,uBAAuB,EAAC,gCAA6B;AAClE,OAAO,KAAK,EAAe,KAAK,EAAS,MAAM,oBAAoB,CAAC;AAKpE,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAC;AAgC5C,wBAAgB,eAAe,CAC7B,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,uBAAuB,GAChC,KAAK,CAoBP;AAyDD,wBAAgB,wBAAwB,CAAC,MAAM,KAAA,EAAE,OAAO,EAAE,uBAAuB,2FAUhF"}