@loaders.gl/core 5.0.0-rc.2 → 5.0.0

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 (229) hide show
  1. package/dist/arrow-geometry/geometry-codecs.cjs +51 -50
  2. package/dist/arrow-geometry/geometry-codecs.cjs.map +3 -3
  3. package/dist/arrow-geometry/geometry-codecs.d.ts +1 -1
  4. package/dist/arrow-geometry/geometry-codecs.d.ts.map +1 -1
  5. package/dist/arrow-geometry/geometry-codecs.js +27 -60
  6. package/dist/arrow-geometry/geometry-codecs.js.map +1 -1
  7. package/dist/arrow-geometry/triangulate-wkb.cjs +33 -118
  8. package/dist/arrow-geometry/triangulate-wkb.cjs.map +2 -2
  9. package/dist/arrow-geometry/triangulate-wkb.d.ts.map +1 -1
  10. package/dist/arrow-geometry/triangulate-wkb.js +39 -142
  11. package/dist/arrow-geometry/triangulate-wkb.js.map +1 -1
  12. package/dist/cluster-source.cjs +124 -370
  13. package/dist/cluster-source.cjs.map +3 -3
  14. package/dist/constants/index.cjs +2 -2
  15. package/dist/constants/index.d.ts +4 -4
  16. package/dist/constants/index.d.ts.map +1 -1
  17. package/dist/constants/index.js +2 -2
  18. package/dist/constants/index.js.map +1 -1
  19. package/dist/dist.dev.js +2 -2
  20. package/dist/dist.min.js +2 -2
  21. package/dist/federated-table-scan-source.cjs +166 -564
  22. package/dist/federated-table-scan-source.cjs.map +3 -3
  23. package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.cjs +15 -0
  24. package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.cjs.map +2 -2
  25. package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.js +19 -1
  26. package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.js.map +1 -1
  27. package/dist/geoarrow/get-geoarrow-vertex-count.cjs +6 -27
  28. package/dist/geoarrow/get-geoarrow-vertex-count.cjs.map +2 -2
  29. package/dist/geoarrow/get-geoarrow-vertex-count.d.ts.map +1 -1
  30. package/dist/geoarrow/get-geoarrow-vertex-count.js +9 -24
  31. package/dist/geoarrow/get-geoarrow-vertex-count.js.map +1 -1
  32. package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.cjs +3 -5
  33. package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.cjs.map +2 -2
  34. package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts +2 -24
  35. package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts.map +1 -1
  36. package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.js +6 -28
  37. package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.js.map +1 -1
  38. package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs +20 -226
  39. package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs.map +2 -2
  40. package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts +1 -2
  41. package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts.map +1 -1
  42. package/dist/geoarrow/lib/kernels/decode-wkt-native.js +23 -264
  43. package/dist/geoarrow/lib/kernels/decode-wkt-native.js.map +1 -1
  44. package/dist/index.cjs +4 -4
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/lib/init.js +1 -1
  47. package/dist/lib/init.js.map +1 -1
  48. package/dist/loader-utils/index.cjs +31 -217
  49. package/dist/loader-utils/index.cjs.map +2 -2
  50. package/dist/loader-utils/json-loader.js +1 -1
  51. package/dist/loader-utils/json-loader.js.map +1 -1
  52. package/dist/loader-utils/lib/log-utils/log.js +1 -1
  53. package/dist/loader-utils/lib/log-utils/log.js.map +1 -1
  54. package/dist/loader-utils/lib/scan-utils/columnar-predicate.d.ts +4 -52
  55. package/dist/loader-utils/lib/scan-utils/columnar-predicate.d.ts.map +1 -1
  56. package/dist/loader-utils/lib/scan-utils/columnar-predicate.js +16 -236
  57. package/dist/loader-utils/lib/scan-utils/columnar-predicate.js.map +1 -1
  58. package/dist/loader-utils/lib/scan-utils/relational-query.d.ts +2 -0
  59. package/dist/loader-utils/lib/scan-utils/relational-query.d.ts.map +1 -1
  60. package/dist/loader-utils/lib/scan-utils/relational-query.js.map +1 -1
  61. package/dist/null-loader.js +1 -1
  62. package/dist/null-loader.js.map +1 -1
  63. package/dist/null-worker-node.js +1 -1
  64. package/dist/null-worker.js +1 -1
  65. package/dist/scan/arrow-execution/expressions.cjs +9 -78
  66. package/dist/scan/arrow-execution/expressions.cjs.map +3 -3
  67. package/dist/scan/arrow-execution/expressions.d.ts +2 -8
  68. package/dist/scan/arrow-execution/expressions.d.ts.map +1 -1
  69. package/dist/scan/arrow-execution/expressions.js +2 -55
  70. package/dist/scan/arrow-execution/expressions.js.map +1 -1
  71. package/dist/scan/arrow-execution/filter-arrow-table.cjs +41 -179
  72. package/dist/scan/arrow-execution/filter-arrow-table.cjs.map +3 -3
  73. package/dist/scan/arrow-execution/filter-arrow-table.d.ts +1 -5
  74. package/dist/scan/arrow-execution/filter-arrow-table.d.ts.map +1 -1
  75. package/dist/scan/arrow-execution/filter-arrow-table.js +44 -190
  76. package/dist/scan/arrow-execution/filter-arrow-table.js.map +1 -1
  77. package/dist/scan/arrow-execution.cjs +2 -2
  78. package/dist/scan/arrow-execution.cjs.map +2 -2
  79. package/dist/scan/arrow-execution.d.ts +1 -1
  80. package/dist/scan/arrow-execution.d.ts.map +1 -1
  81. package/dist/scan/arrow-execution.js +1 -1
  82. package/dist/scan/arrow-execution.js.map +1 -1
  83. package/dist/scan/arrow-query.cjs +3 -3
  84. package/dist/scan/arrow-query.cjs.map +2 -2
  85. package/dist/scan/arrow-query.d.ts +2 -2
  86. package/dist/scan/arrow-query.d.ts.map +1 -1
  87. package/dist/scan/arrow-query.js +2 -2
  88. package/dist/scan/arrow-query.js.map +1 -1
  89. package/dist/scan/federated-table-scan-source.cjs +3 -3
  90. package/dist/scan/federated-table-scan-source.cjs.map +2 -2
  91. package/dist/scan/federated-table-scan-source.js +1 -1
  92. package/dist/scan/federated-table-scan-source.js.map +1 -1
  93. package/dist/scan/index.cjs +9 -49
  94. package/dist/scan/index.cjs.map +3 -3
  95. package/dist/scan/index.d.ts +2 -2
  96. package/dist/scan/index.d.ts.map +1 -1
  97. package/dist/scan/index.js +2 -2
  98. package/dist/scan/index.js.map +1 -1
  99. package/dist/scan/plan-arrow-table-query.cjs +271 -0
  100. package/dist/scan/plan-arrow-table-query.cjs.map +7 -0
  101. package/dist/scan/plan-arrow-table-query.d.ts +50 -0
  102. package/dist/scan/plan-arrow-table-query.d.ts.map +1 -0
  103. package/dist/scan/plan-arrow-table-query.js +257 -0
  104. package/dist/scan/plan-arrow-table-query.js.map +1 -0
  105. package/dist/scan/query-arrow-table-in-batches.cjs +2 -39
  106. package/dist/scan/query-arrow-table-in-batches.cjs.map +2 -2
  107. package/dist/scan/query-arrow-table-in-batches.d.ts +1 -1
  108. package/dist/scan/query-arrow-table-in-batches.d.ts.map +1 -1
  109. package/dist/scan/query-arrow-table-in-batches.js +3 -26
  110. package/dist/scan/query-arrow-table-in-batches.js.map +1 -1
  111. package/dist/scan/query-arrow-table.cjs +7 -443
  112. package/dist/scan/query-arrow-table.cjs.map +3 -3
  113. package/dist/scan/query-arrow-table.d.ts +6 -54
  114. package/dist/scan/query-arrow-table.d.ts.map +1 -1
  115. package/dist/scan/query-arrow-table.js +6 -475
  116. package/dist/scan/query-arrow-table.js.map +1 -1
  117. package/dist/scan/query-pushdown.cjs +3 -4
  118. package/dist/scan/query-pushdown.cjs.map +2 -2
  119. package/dist/scan/query-pushdown.js +4 -5
  120. package/dist/scan/query-pushdown.js.map +1 -1
  121. package/dist/scan/query.cjs +10 -9
  122. package/dist/scan/query.cjs.map +2 -2
  123. package/dist/scan/query.d.ts.map +1 -1
  124. package/dist/scan/query.js +14 -5
  125. package/dist/scan/query.js.map +1 -1
  126. package/dist/scan/scan-engine.cjs +14 -7
  127. package/dist/scan/scan-engine.cjs.map +2 -2
  128. package/dist/scan/scan-engine.d.ts +1 -1
  129. package/dist/scan/scan-engine.d.ts.map +1 -1
  130. package/dist/scan/scan-engine.js +4 -9
  131. package/dist/scan/scan-engine.js.map +1 -1
  132. package/dist/scan/vector-table-scan-source.cjs +14 -3
  133. package/dist/scan/vector-table-scan-source.cjs.map +2 -2
  134. package/dist/scan/vector-table-scan-source.d.ts +1 -1
  135. package/dist/scan/vector-table-scan-source.d.ts.map +1 -1
  136. package/dist/scan/vector-table-scan-source.js +2 -1
  137. package/dist/scan/vector-table-scan-source.js.map +1 -1
  138. package/dist/schema-utils/index.cjs +11 -47
  139. package/dist/schema-utils/index.cjs.map +1 -1
  140. package/dist/schema-utils/lib/arrow/arrow-metadata.d.ts +2 -4
  141. package/dist/schema-utils/lib/arrow/arrow-metadata.d.ts.map +1 -1
  142. package/dist/schema-utils/lib/arrow/arrow-metadata.js +2 -43
  143. package/dist/schema-utils/lib/arrow/arrow-metadata.js.map +1 -1
  144. package/dist/vector-table-scan-source.cjs +854 -1314
  145. package/dist/vector-table-scan-source.cjs.map +3 -3
  146. package/dist/wkt/twkb/index.cjs +68 -5
  147. package/dist/wkt/twkb/index.cjs.map +3 -3
  148. package/dist/wkt/twkb/index.d.ts +10 -2
  149. package/dist/wkt/twkb/index.d.ts.map +1 -1
  150. package/dist/wkt/twkb/index.js +49 -2
  151. package/dist/wkt/twkb/index.js.map +1 -1
  152. package/dist/worker-utils/index.cjs +4 -4
  153. package/dist/worker-utils/index.cjs.map +1 -1
  154. package/dist/worker-utils/lib/env-utils/version.js +1 -1
  155. package/dist/worker-utils/lib/env-utils/version.js.map +1 -1
  156. package/package.json +7 -7
  157. package/src/arrow-geometry/geometry-codecs.ts +35 -78
  158. package/src/arrow-geometry/triangulate-wkb.ts +37 -169
  159. package/src/constants/index.ts +2 -2
  160. package/src/geoarrow/geoarrow-converter/convert-geoarrow-geometry.ts +22 -1
  161. package/src/geoarrow/get-geoarrow-vertex-count.ts +7 -32
  162. package/src/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.ts +6 -30
  163. package/src/geoarrow/lib/kernels/decode-wkt-native.ts +23 -269
  164. package/src/loader-utils/lib/scan-utils/columnar-predicate.ts +46 -363
  165. package/src/loader-utils/lib/scan-utils/relational-query.ts +7 -1
  166. package/src/scan/arrow-execution/expressions.ts +2 -86
  167. package/src/scan/arrow-execution/filter-arrow-table.ts +54 -238
  168. package/src/scan/arrow-execution.ts +1 -1
  169. package/src/scan/arrow-query.ts +2 -2
  170. package/src/scan/federated-table-scan-source.ts +1 -1
  171. package/src/scan/index.ts +2 -2
  172. package/src/scan/plan-arrow-table-query.ts +367 -0
  173. package/src/scan/query-arrow-table-in-batches.ts +4 -33
  174. package/src/scan/query-arrow-table.ts +10 -626
  175. package/src/scan/query-pushdown.ts +3 -4
  176. package/src/scan/query.ts +16 -10
  177. package/src/scan/scan-engine.ts +4 -11
  178. package/src/scan/vector-table-scan-source.ts +2 -1
  179. package/src/schema-utils/lib/arrow/arrow-metadata.ts +2 -50
  180. package/src/wkt/twkb/index.ts +63 -2
  181. package/dist/scan/arrow-execution/portable-predicate-compatibility.cjs +0 -41
  182. package/dist/scan/arrow-execution/portable-predicate-compatibility.cjs.map +0 -7
  183. package/dist/scan/arrow-execution/portable-predicate-compatibility.d.ts +0 -5
  184. package/dist/scan/arrow-execution/portable-predicate-compatibility.d.ts.map +0 -1
  185. package/dist/scan/arrow-execution/portable-predicate-compatibility.js +0 -23
  186. package/dist/scan/arrow-execution/portable-predicate-compatibility.js.map +0 -1
  187. package/dist/scan/arrow-execution/project-arrow-table.cjs +0 -70
  188. package/dist/scan/arrow-execution/project-arrow-table.cjs.map +0 -7
  189. package/dist/scan/arrow-execution/project-arrow-table.d.ts +0 -8
  190. package/dist/scan/arrow-execution/project-arrow-table.d.ts.map +0 -1
  191. package/dist/scan/arrow-execution/project-arrow-table.js +0 -39
  192. package/dist/scan/arrow-execution/project-arrow-table.js.map +0 -1
  193. package/dist/scan/query-arrow-table-math.cjs +0 -41
  194. package/dist/scan/query-arrow-table-math.cjs.map +0 -7
  195. package/dist/scan/query-arrow-table-math.d.ts +0 -5
  196. package/dist/scan/query-arrow-table-math.d.ts.map +0 -1
  197. package/dist/scan/query-arrow-table-math.js +0 -14
  198. package/dist/scan/query-arrow-table-math.js.map +0 -1
  199. package/dist/wkt/twkb/convert-geometry-to-twkb.cjs +0 -211
  200. package/dist/wkt/twkb/convert-geometry-to-twkb.cjs.map +0 -7
  201. package/dist/wkt/twkb/convert-geometry-to-twkb.d.ts +0 -6
  202. package/dist/wkt/twkb/convert-geometry-to-twkb.d.ts.map +0 -1
  203. package/dist/wkt/twkb/convert-geometry-to-twkb.js +0 -204
  204. package/dist/wkt/twkb/convert-geometry-to-twkb.js.map +0 -1
  205. package/dist/wkt/twkb/convert-twkb-to-geometry.cjs +0 -251
  206. package/dist/wkt/twkb/convert-twkb-to-geometry.cjs.map +0 -7
  207. package/dist/wkt/twkb/convert-twkb-to-geometry.d.ts +0 -10
  208. package/dist/wkt/twkb/convert-twkb-to-geometry.d.ts.map +0 -1
  209. package/dist/wkt/twkb/convert-twkb-to-geometry.js +0 -261
  210. package/dist/wkt/twkb/convert-twkb-to-geometry.js.map +0 -1
  211. package/dist/wkt/twkb/twkb-io.cjs +0 -102
  212. package/dist/wkt/twkb/twkb-io.cjs.map +0 -7
  213. package/dist/wkt/twkb/twkb-io.d.ts +0 -33
  214. package/dist/wkt/twkb/twkb-io.d.ts.map +0 -1
  215. package/dist/wkt/twkb/twkb-io.js +0 -78
  216. package/dist/wkt/twkb/twkb-io.js.map +0 -1
  217. package/dist/wkt/twkb/twkb-types.cjs +0 -40
  218. package/dist/wkt/twkb/twkb-types.cjs.map +0 -7
  219. package/dist/wkt/twkb/twkb-types.d.ts +0 -11
  220. package/dist/wkt/twkb/twkb-types.d.ts.map +0 -1
  221. package/dist/wkt/twkb/twkb-types.js +0 -15
  222. package/dist/wkt/twkb/twkb-types.js.map +0 -1
  223. package/src/scan/arrow-execution/portable-predicate-compatibility.ts +0 -27
  224. package/src/scan/arrow-execution/project-arrow-table.ts +0 -53
  225. package/src/scan/query-arrow-table-math.ts +0 -23
  226. package/src/wkt/twkb/convert-geometry-to-twkb.ts +0 -317
  227. package/src/wkt/twkb/convert-twkb-to-geometry.ts +0 -373
  228. package/src/wkt/twkb/twkb-io.ts +0 -85
  229. package/src/wkt/twkb/twkb-types.ts +0 -14
@@ -2,7 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {parseWKB, parseWKTWithMetadata, writeWKB, WKBBuilder} from '@math.gl/core/arrow';
5
+ import {inspectWKTHeader, parseWKB, parseWKTWithMetadata, writeWKB} from '@math.gl/core/arrow';
6
+ import {ensureArrayBuffer} from '../loader-utils/lib/binary-utils/memory-conversion-utils';
6
7
  import type {WellKnownDimension, WellKnownGeometry, WKTParseResult} from '@math.gl/core/arrow';
7
8
  import type {Feature, Geometry, GeoArrowDimension} from '@loaders.gl/core/schema';
8
9
  import {normalizeEmptyPoints} from './geometry-utils';
@@ -35,7 +36,7 @@ export function convertWKBToGeometry(input: ArrayBufferLike | ArrayBufferView):
35
36
  const bytes = ArrayBuffer.isView(input)
36
37
  ? new Uint8Array(input.buffer, input.byteOffset, input.byteLength)
37
38
  : new Uint8Array(input);
38
- return normalizeEmptyPoints(parseWKB(bytes).geometry as Geometry);
39
+ return parseWKB(bytes, {normalizeEmptyPoints: true}).geometry as Geometry;
39
40
  }
40
41
 
41
42
  /** Encodes legacy geometry options with math.gl; collection child markers retain their dimensions. */
@@ -52,72 +53,51 @@ export function convertGeometryToWKB(
52
53
  : options.hasM
53
54
  ? 'xym'
54
55
  : 'xy';
55
- const bytes = encodeGeometry(geometry, dimension);
56
- return bytes.buffer as ArrayBuffer;
56
+ const bytes = writeWKB(describeGeometry(geometry, dimension));
57
+ return ensureArrayBuffer(bytes);
57
58
  }
58
59
 
59
- /** Composes independently encoded collection children; math.gl owns all WKB byte emission. */
60
- function encodeGeometry(geometry: Geometry, dimension: WellKnownDimension): Uint8Array {
61
- if (geometry.type !== 'GeometryCollection') {
62
- return writeWKB(geometry as WellKnownGeometry, dimension);
63
- }
64
- const children = geometry.geometries.map(child =>
65
- encodeGeometry(
66
- child,
67
- (child as Geometry & {__geoarrowDimension?: WellKnownDimension}).__geoarrowDimension ??
68
- dimension
69
- )
70
- );
71
- const headerBuilder = new WKBBuilder({mode: 'measure', dimension});
72
- headerBuilder.beginGeometry('GeometryCollection', children.length);
73
- const headerLength = headerBuilder.finishGeometry();
74
- const bytes = new Uint8Array(
75
- headerLength + children.reduce((total, child) => total + child.length, 0)
76
- );
77
- const writer = new WKBBuilder({mode: 'write', target: bytes, dimension});
78
- writer.beginGeometry('GeometryCollection', children.length);
79
- let byteOffset = writer.finishGeometry();
80
- for (const child of children) {
81
- bytes.set(child, byteOffset);
82
- byteOffset += child.length;
83
- }
84
- return bytes;
60
+ /** Supplies each collection member's effective dimension to the math.gl writer. */
61
+ function describeGeometry(geometry: Geometry, dimension: WellKnownDimension): WKTParseResult {
62
+ return {
63
+ geometry: geometry as WellKnownGeometry,
64
+ dimension,
65
+ children:
66
+ geometry.type === 'GeometryCollection'
67
+ ? geometry.geometries.map(child =>
68
+ describeGeometry(
69
+ child,
70
+ (child as Geometry & {__geoarrowDimension?: WellKnownDimension})
71
+ .__geoarrowDimension ?? dimension
72
+ )
73
+ )
74
+ : undefined
75
+ };
85
76
  }
86
77
 
87
- /** Reads the declared root WKT dimension, retaining the legacy null-on-invalid-header contract. */
78
+ /** Reads the declared root dimension without parsing the coordinate payload. */
88
79
  export function getWKTDimension(input: string): GeoArrowDimension | null {
89
- const match = input
90
- .trim()
91
- .match(
92
- /^(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(ZM|Z|M))?(?:\s|\()/i
93
- );
94
- if (!match) return null;
95
- return match[1]?.toUpperCase() === 'Z'
96
- ? 'xyz'
97
- : match[1]?.toUpperCase() === 'M'
98
- ? 'xym'
99
- : match[1]?.toUpperCase() === 'ZM'
100
- ? 'xyzm'
101
- : 'xy';
80
+ return inspectWKTHeader(input)?.dimension ?? null;
102
81
  }
103
82
 
104
83
  /** Parses WKT with loaders.gl's legacy SRID and invalid-input behavior. */
105
84
  export function convertWKTToGeometry(input: string, options?: ParseWKTOptions): Geometry | null {
106
- const {text, srid, dimension} = splitWKTHeader(input);
85
+ const dimension = getWKTDimension(input);
107
86
  try {
108
87
  // Preserve the legacy parser's treatment of empty parentheses as invalid input.
109
- if (/\(\s*\)\s*$/s.test(text)) {
110
- return null;
111
- }
112
- const collectionHeader = text.match(/^(\s*GEOMETRYCOLLECTION)\s+(?:ZM|Z|M)(?=\s|\()/i);
113
- const parseText =
114
- collectionHeader && dimension !== 'xym'
115
- ? text.replace(collectionHeader[0], collectionHeader[1])
116
- : text;
117
- const parsed = parseWKTWithMetadata(parseText, {inferDimensions: true});
88
+ if (/\(\s*\)\s*$/s.test(input)) return null;
89
+
90
+ const collectionHeader =
91
+ /^(\s*(?:SRID\s*=\s*\d+\s*;\s*)?GEOMETRYCOLLECTION)\s+(?:ZM|Z|M)(?=\s|\()/i;
92
+ const parseText = dimension !== 'xym' ? input.replace(collectionHeader, '$1') : input;
93
+ const parsed = parseWKTWithMetadata(parseText, {
94
+ inferDimensions: true,
95
+ allowMissingInheritedOrdinates: true
96
+ });
97
+ const {srid} = parsed;
118
98
  const geometry = toGeometryWithDimensionMetadata(
119
99
  parsed,
120
- collectionHeader ? dimension : undefined
100
+ collectionHeader.test(input) ? (dimension ?? undefined) : undefined
121
101
  );
122
102
  if (options?.wkt?.crs && srid !== undefined) {
123
103
  Object.defineProperty(geometry, 'crs', {
@@ -161,26 +141,3 @@ function addDimensionMarker(geometry: Geometry, dimension?: WellKnownDimension):
161
141
  }
162
142
  return geometry;
163
143
  }
164
-
165
- /** Separates an optional EWKT SRID prefix and root dimension token. */
166
- function splitWKTHeader(input: string): {
167
- text: string;
168
- srid?: string;
169
- dimension?: WellKnownDimension;
170
- } {
171
- const sridMatch = input.match(/^\s*SRID=(\d+)\s*;\s*/i);
172
- const text = sridMatch ? input.slice(sridMatch[0].length) : input;
173
- const dimensionMatch = text.match(
174
- /^\s*(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(ZM|Z|M))?(?:\s|\()/i
175
- );
176
- const dimensionToken = dimensionMatch?.[1]?.toUpperCase();
177
- const dimension =
178
- dimensionToken === 'Z'
179
- ? 'xyz'
180
- : dimensionToken === 'M'
181
- ? 'xym'
182
- : dimensionToken === 'ZM'
183
- ? 'xyzm'
184
- : undefined;
185
- return {text, srid: sridMatch?.[1], dimension};
186
- }
@@ -30,7 +30,7 @@
30
30
 
31
31
  /* eslint-disable */
32
32
 
33
- import {EWKB_FLAG_M, EWKB_FLAG_SRID, EWKB_FLAG_Z, WKBGeometryType} from './wkb-types';
33
+ import {getWellKnownDimensionSize, visitWKB} from '@math.gl/core/arrow';
34
34
 
35
35
  type WKBPolygonLayout = {
36
36
  ringStart: number;
@@ -47,23 +47,48 @@ type WKBPolygonLayout = {
47
47
  */
48
48
  export function triangulateWKB(wkb: ArrayBufferLike | ArrayBufferView): number[] {
49
49
  const dataView = getWKBDataView(wkb);
50
- const wkbHeader = parseWKBHeaderFast(dataView);
51
50
  const triangles: number[] = [];
52
51
  resetVertexPool();
53
52
  resetRingLayoutPool();
54
53
 
55
- switch (wkbHeader.geometryType) {
56
- case WKBGeometryType.Polygon: {
57
- const parsedPolygon = parseWKBPolygonLayout(dataView, wkbHeader.byteOffset, wkbHeader, 0);
58
- triangulateWKBPolygon(dataView, parsedPolygon.layout, triangles);
59
- return triangles;
54
+ let polygon: WKBPolygonLayout | undefined;
55
+ let vertexOffset = 0;
56
+ try {
57
+ visitWKB(dataView, {
58
+ geometry(header, count, depth) {
59
+ if (
60
+ depth === 0 &&
61
+ header.geometryType !== 'Polygon' &&
62
+ header.geometryType !== 'MultiPolygon'
63
+ ) {
64
+ throw new Error(`WKB: Expected Polygon or MultiPolygon, found ${header.geometryType}`);
65
+ }
66
+ if (header.geometryType !== 'Polygon') return;
67
+ if (polygon) triangulateWKBPolygon(dataView, polygon, triangles);
68
+ polygon = {
69
+ ringStart: ringLayoutPoolLength,
70
+ ringCount: count ?? 0,
71
+ vertexCount: 0,
72
+ dimensions: getWellKnownDimensionSize(header.dimension),
73
+ littleEndian: header.littleEndian
74
+ };
75
+ },
76
+ ring(pointCount, _ringIndex, _depth, byteOffset) {
77
+ ringPointCounts[ringLayoutPoolLength] = pointCount;
78
+ ringCoordinateByteOffsets[ringLayoutPoolLength] = byteOffset;
79
+ ringVertexOffsets[ringLayoutPoolLength++] = vertexOffset;
80
+ polygon!.vertexCount += pointCount;
81
+ vertexOffset += pointCount;
82
+ }
83
+ });
84
+ } catch (cause) {
85
+ if (cause instanceof Error && cause.message.startsWith('WKB Polygon collection contains')) {
86
+ throw new Error('WKB: Inner geometries of MultiPolygon must be Polygon geometries.', {cause});
60
87
  }
61
- case WKBGeometryType.MultiPolygon:
62
- triangulateWKBMultiPolygon(dataView, wkbHeader.byteOffset, wkbHeader.littleEndian, triangles);
63
- return triangles;
64
- default:
65
- throw new Error(`WKB: Expected Polygon or MultiPolygon, found ${wkbHeader.geometryType}`);
88
+ throw cause;
66
89
  }
90
+ if (polygon) triangulateWKBPolygon(dataView, polygon, triangles);
91
+ return triangles;
67
92
  }
68
93
 
69
94
  /**
@@ -78,163 +103,6 @@ function getWKBDataView(wkb: ArrayBufferLike | ArrayBufferView): DataView {
78
103
  return new DataView(wkb);
79
104
  }
80
105
 
81
- /**
82
- * Triangulates each polygon in a WKB MultiPolygon.
83
- * @param dataView Binary WKB input view.
84
- * @param byteOffset Offset to the multipolygon payload.
85
- * @param littleEndian Whether the multipolygon count is little endian.
86
- * @param triangles Output triangle index array.
87
- */
88
- function triangulateWKBMultiPolygon(
89
- dataView: DataView,
90
- byteOffset: number,
91
- littleEndian: boolean,
92
- triangles: number[]
93
- ): void {
94
- const polygonCount = dataView.getUint32(byteOffset, littleEndian);
95
- byteOffset += 4;
96
-
97
- let vertexOffset = 0;
98
- const polygonHeader = {byteOffset} as WKBHeader;
99
- for (let polygonIndex = 0; polygonIndex < polygonCount; polygonIndex++) {
100
- parseWKBHeaderFast(dataView, byteOffset, polygonHeader);
101
- if (polygonHeader.geometryType !== WKBGeometryType.Polygon) {
102
- throw new Error('WKB: Inner geometries of MultiPolygon must be Polygon geometries.');
103
- }
104
-
105
- const parsedPolygon = parseWKBPolygonLayout(
106
- dataView,
107
- polygonHeader.byteOffset,
108
- polygonHeader,
109
- vertexOffset
110
- );
111
- triangulateWKBPolygon(dataView, parsedPolygon.layout, triangles);
112
- vertexOffset += parsedPolygon.layout.vertexCount;
113
- byteOffset = parsedPolygon.byteOffset;
114
- }
115
- }
116
-
117
- /**
118
- * Parses a binary WKB header without generic WKT checks or object merging.
119
- * @param dataView Binary WKB input view.
120
- * @param byteOffset Header byte offset.
121
- * @param target Optional reusable header object.
122
- * @returns Parsed WKB header.
123
- */
124
- function parseWKBHeaderFast(
125
- dataView: DataView,
126
- byteOffset: number = 0,
127
- target?: WKBHeader
128
- ): WKBHeader {
129
- const wkbHeader = target || ({} as WKBHeader);
130
- const littleEndian = dataView.getUint8(byteOffset) === 1;
131
- byteOffset++;
132
-
133
- const geometryCode = dataView.getUint32(byteOffset, littleEndian);
134
- byteOffset += 4;
135
-
136
- const geometryType = (geometryCode & 0x7) as 1 | 2 | 3 | 4 | 5 | 6 | 7;
137
- let dimensions: 2 | 3 | 4 = 2;
138
- let coordinates: 'xy' | 'xyz' | 'xym' | 'xyzm' = 'xy';
139
- let variant: 'wkb' | 'ewkb' | 'iso-wkb' = 'wkb';
140
-
141
- const isoType = (geometryCode - geometryType) / 1000;
142
- if (isoType === 1) {
143
- variant = 'iso-wkb';
144
- dimensions = 3;
145
- coordinates = 'xyz';
146
- } else if (isoType === 2) {
147
- variant = 'iso-wkb';
148
- dimensions = 3;
149
- coordinates = 'xym';
150
- } else if (isoType === 3) {
151
- variant = 'iso-wkb';
152
- dimensions = 4;
153
- coordinates = 'xyzm';
154
- } else if (isoType !== 0) {
155
- const ewkbZ = geometryCode & EWKB_FLAG_Z;
156
- const ewkbM = geometryCode & EWKB_FLAG_M;
157
- const ewkbSRID = geometryCode & EWKB_FLAG_SRID;
158
-
159
- if (ewkbZ && ewkbM) {
160
- variant = 'ewkb';
161
- dimensions = 4;
162
- coordinates = 'xyzm';
163
- } else if (ewkbZ) {
164
- variant = 'ewkb';
165
- dimensions = 3;
166
- coordinates = 'xyz';
167
- } else if (ewkbM) {
168
- variant = 'ewkb';
169
- dimensions = 3;
170
- coordinates = 'xym';
171
- }
172
-
173
- if (ewkbSRID) {
174
- variant = 'ewkb';
175
- wkbHeader.srid = dataView.getUint32(byteOffset, littleEndian);
176
- byteOffset += 4;
177
- } else {
178
- wkbHeader.srid = undefined;
179
- }
180
- } else {
181
- wkbHeader.srid = undefined;
182
- }
183
-
184
- wkbHeader.type = 'wkb';
185
- wkbHeader.variant = variant;
186
- wkbHeader.geometryType = geometryType;
187
- wkbHeader.dimensions = dimensions;
188
- wkbHeader.coordinates = coordinates;
189
- wkbHeader.littleEndian = littleEndian;
190
- wkbHeader.byteOffset = byteOffset;
191
-
192
- return wkbHeader;
193
- }
194
-
195
- /**
196
- * Parses one WKB Polygon payload into ring byte ranges.
197
- * @param dataView Binary WKB input view.
198
- * @param byteOffset Offset to the polygon payload.
199
- * @param wkbHeader Parsed polygon header.
200
- * @param vertexOffset First vertex index of this polygon in the source WKB geometry.
201
- * @returns Parsed polygon layout and the next unread byte offset.
202
- */
203
- function parseWKBPolygonLayout(
204
- dataView: DataView,
205
- byteOffset: number,
206
- wkbHeader: WKBHeader,
207
- vertexOffset: number
208
- ): {layout: WKBPolygonLayout; byteOffset: number} {
209
- const ringCount = dataView.getUint32(byteOffset, wkbHeader.littleEndian);
210
- byteOffset += 4;
211
-
212
- const ringStart = ringLayoutPoolLength;
213
- let vertexCount = 0;
214
-
215
- for (let ringIndex = 0; ringIndex < ringCount; ringIndex++) {
216
- const pointCount = dataView.getUint32(byteOffset, wkbHeader.littleEndian);
217
- byteOffset += 4;
218
- ringPointCounts[ringLayoutPoolLength] = pointCount;
219
- ringCoordinateByteOffsets[ringLayoutPoolLength] = byteOffset;
220
- ringVertexOffsets[ringLayoutPoolLength] = vertexOffset + vertexCount;
221
- ringLayoutPoolLength++;
222
- byteOffset += pointCount * wkbHeader.dimensions * 8;
223
- vertexCount += pointCount;
224
- }
225
-
226
- return {
227
- layout: {
228
- ringStart,
229
- ringCount,
230
- vertexCount,
231
- dimensions: wkbHeader.dimensions,
232
- littleEndian: wkbHeader.littleEndian
233
- },
234
- byteOffset
235
- };
236
- }
237
-
238
106
  /**
239
107
  * Computes a triangulation of one WKB polygon layout.
240
108
  * @param dataView Binary WKB input view.
@@ -11,7 +11,7 @@
11
11
  * `yarn test-audit`, which fails when this value differs from the target branch or when a test
12
12
  * hard-codes a different branch.
13
13
  */
14
- export const LOADERS_GL_FIXTURE_BRANCH = 'master';
14
+ export const LOADERS_GL_FIXTURE_BRANCH = '5.0-release';
15
15
 
16
16
  /** Raw GitHub URL of the repository root at {@link LOADERS_GL_FIXTURE_BRANCH}, with a trailing slash. */
17
17
  export const LOADERS_GL_RAW_FIXTURE_URL = `https://raw.githubusercontent.com/visgl/loaders.gl/${LOADERS_GL_FIXTURE_BRANCH}/`;
@@ -20,4 +20,4 @@ export const LOADERS_GL_RAW_FIXTURE_URL = `https://raw.githubusercontent.com/vis
20
20
  export const LOADERS_GL_REDIRECTING_FIXTURE_URL = `https://github.com/visgl/loaders.gl/raw/${LOADERS_GL_FIXTURE_BRANCH}/`;
21
21
 
22
22
  /** Default npm distribution tag for worker assets on this branch. */
23
- export const NPM_TAG = 'beta';
23
+ export const NPM_TAG = 'latest';
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import * as arrow from 'apache-arrow';
6
- import {convertGeoArrowColumn, decodeGeoArrowWKB} from '@math.gl/core/arrow';
6
+ import {convertGeoArrowColumn, decodeGeoArrowWKB, decodeGeoArrowWKT} from '@math.gl/core/arrow';
7
7
  import type {DecodeGeoArrowWKBOptions} from '@math.gl/core/arrow';
8
8
  import {
9
9
  convertGeometryToWKB,
@@ -462,6 +462,27 @@ function convertGeometryColumnWithMath(
462
462
  targetEncoding: GeoArrowEncoding,
463
463
  options?: GeoArrowGeometryConvertOptions
464
464
  ): arrow.Vector | null {
465
+ if (
466
+ sourceEncoding === 'geoarrow.wkt' &&
467
+ isConcreteNativeEncoding(targetEncoding) &&
468
+ options?.dimension &&
469
+ options.maxGeometryCollectionDepth === DEFAULT_MAX_GEOMETRY_COLLECTION_DEPTH
470
+ ) {
471
+ try {
472
+ const source = makeGeoArrowColumnFromArrowVector(column, {encoding: sourceEncoding});
473
+ return makeArrowVectorFromGeoArrowColumn(
474
+ decodeGeoArrowWKT(source, {
475
+ encoding: targetEncoding,
476
+ dimension: options.dimension,
477
+ coordinateLayout: options.coordinates,
478
+ offsetType: options.offsetType
479
+ })
480
+ );
481
+ } catch {
482
+ // Keep the existing promotion and diagnostic paths for incompatible rows.
483
+ return null;
484
+ }
485
+ }
465
486
  const sourceIsNative = isMathGeoArrowNativeEncoding(sourceEncoding);
466
487
  const targetIsNative = isMathGeoArrowNativeEncoding(targetEncoding);
467
488
  const supportsConversion =
@@ -3,9 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import * as arrow from 'apache-arrow';
6
- import {scanWKB} from '@math.gl/core/arrow';
7
- import type {Geometry} from '@loaders.gl/core/schema';
8
- import {convertWKTToGeometry} from '@loaders.gl/core/arrow-geometry/geometry-codecs';
6
+ import {countWKTVertices, scanWKB} from '@math.gl/core/arrow';
9
7
 
10
8
  import {
11
9
  isGeoArrowBox,
@@ -155,40 +153,17 @@ function getWKTDataVertexCount(data: arrow.Data): number {
155
153
  for (let rowIndex = 0; rowIndex < vector.length; rowIndex++) {
156
154
  const value = vector.get(rowIndex);
157
155
  if (value == null) continue;
158
- const geometry = convertWKTToGeometry(String(value));
159
- if (!geometry) throw new Error(`Invalid WKT geometry at row ${rowIndex}.`);
160
- vertexCount += countGeometryVertices(geometry);
156
+ try {
157
+ if (/\(\s*\)\s*$/.test(String(value))) throw new Error('Empty WKT geometry body');
158
+ vertexCount += countWKTVertices(String(value), {inferDimensions: true});
159
+ } catch (cause) {
160
+ throw new Error(`Invalid WKT geometry at row ${rowIndex}.`, {cause});
161
+ }
161
162
  }
162
163
 
163
164
  return vertexCount;
164
165
  }
165
166
 
166
- /** Counts coordinate tuples in a parsed geometry, including nested collections. */
167
- function countGeometryVertices(geometry: Geometry): number {
168
- switch (geometry.type) {
169
- case 'Point':
170
- return geometry.coordinates.length > 0 ? 1 : 0;
171
- case 'MultiPoint':
172
- case 'LineString':
173
- return geometry.coordinates.length;
174
- case 'Polygon':
175
- return geometry.coordinates.reduce((count, ring) => count + ring.length, 0);
176
- case 'MultiLineString':
177
- return geometry.coordinates.reduce((count, line) => count + line.length, 0);
178
- case 'MultiPolygon':
179
- return geometry.coordinates.reduce(
180
- (count, polygon) =>
181
- count + polygon.reduce((polygonCount, ring) => polygonCount + ring.length, 0),
182
- 0
183
- );
184
- case 'GeometryCollection':
185
- return geometry.geometries.reduce(
186
- (count, childGeometry) => count + countGeometryVertices(childGeometry),
187
- 0
188
- );
189
- }
190
- }
191
-
192
167
  /**
193
168
  * Counts vertices in one Arrow Binary WKB data chunk.
194
169
  * @param data Arrow Binary or LargeBinary data chunk.
@@ -2,47 +2,23 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {inspectWKBHeader} from '@math.gl/core/arrow';
5
+ import {inspectWKBHeader, inspectWKTHeader} from '@math.gl/core/arrow';
6
6
  import type {WellKnownDimension, WKBGeometryType as MathWKBGeometryType} from '@math.gl/core/arrow';
7
7
  import type {WKBGeometryType, WKBHeader} from './wkb-types';
8
8
  import {MAX_SRID, WKT_MAGIC_STRINGS, WKT_MAGIC_BYTES} from './wkb-types';
9
9
 
10
- /**
11
- * Check if a string is WKT.
12
- * @param input A potential WKT geometry string
13
- * @return `true` if input appears to be a WKT geometry string, `false` otherwise
14
-
15
- * @note We only support the "geojson" subset of the OGC simple features standard
16
- * @todo Does not handle leading spaces which appear to be permitted per the spec:
17
- * "A WKT string contains no white space outside of double quotes.
18
- * However padding with white space to improve human readability is permitted;
19
- * the examples of WKT that are included in this document have
20
- * spaces and line feeds inserted to improve clarity. Any padding is stripped out or ignored by parsers."
21
- */
10
+ /** Checks whether the input starts with a supported WKT geometry header. */
22
11
  export function isWKT(input: string | ArrayBufferLike): boolean {
23
12
  return getWKTGeometryType(input) !== null;
24
13
  }
25
14
 
26
- /**
27
- * Get the geometry type of a WKT string.
28
- * @param input A potential WKT geometry string
29
- * @return `true` if input appears to be a WKT geometry string, `false` otherwise
30
-
31
- * @note We only support the "geojson" subset of the OGC simple features standard
32
- * @todo Does not handle leading spaces which appear to be permitted per the spec:
33
- * "A WKT string contains no white space outside of double quotes.
34
- * However padding with white space to improve human readability is permitted;
35
- * the examples of WKT that are included in this document have
36
- * spaces and line feeds inserted to improve clarity. Any padding is stripped out or ignored by parsers."
37
- */
15
+ /** Classifies string WKT/EWKT headers or binary WKT prefixes without parsing coordinates. */
38
16
  export function getWKTGeometryType(input: string | ArrayBufferLike): WKBGeometryType | null {
39
17
  if (typeof input === 'string') {
40
- const match = input.match(
41
- /^(POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(?:ZM|Z|M))?(?:\s|\()/i
42
- );
43
- if (!match?.[1]) return null;
18
+ const header = inspectWKTHeader(input);
19
+ if (!header) return null;
44
20
  const geometryType = WKT_MAGIC_STRINGS.findIndex(magicString =>
45
- magicString.startsWith(match[1].toUpperCase())
21
+ magicString.startsWith(header.geometryType.toUpperCase())
46
22
  );
47
23
  return geometryType >= 0 ? ((geometryType + 1) as WKBGeometryType) : null;
48
24
  }