@loaders.gl/geospatial 5.0.0-alpha.14 → 5.0.0-beta.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 (834) hide show
  1. package/LICENSE +2 -30
  2. package/README.md +10 -1
  3. package/THIRD-PARTY-NOTICES.md +21 -0
  4. package/WKT-README.md +14 -0
  5. package/dist/dbf-loader-types.cjs +68 -0
  6. package/dist/dbf-loader-types.cjs.map +7 -0
  7. package/dist/dbf-loader-types.d.ts +2 -0
  8. package/dist/dbf-loader-types.d.ts.map +1 -0
  9. package/dist/dbf-loader-types.js +2 -0
  10. package/dist/dbf-loader-types.js.map +1 -0
  11. package/dist/dbf-loader.cjs +83 -0
  12. package/dist/dbf-loader.cjs.map +7 -0
  13. package/dist/dbf-loader.d.ts +2 -0
  14. package/dist/dbf-loader.d.ts.map +1 -0
  15. package/dist/dbf-loader.js +2 -0
  16. package/dist/dbf-loader.js.map +1 -0
  17. package/dist/dbf-worker.js +1670 -673
  18. package/dist/dbf.cjs +31 -0
  19. package/dist/dbf.cjs.map +7 -0
  20. package/dist/flatgeobuf/bundled.cjs +33 -0
  21. package/dist/flatgeobuf/bundled.cjs.map +7 -0
  22. package/dist/flatgeobuf/flatgeobuf-format.cjs +40 -0
  23. package/dist/flatgeobuf/flatgeobuf-format.cjs.map +7 -0
  24. package/dist/flatgeobuf/flatgeobuf-loader-types.cjs +72 -0
  25. package/dist/flatgeobuf/flatgeobuf-loader-types.cjs.map +7 -0
  26. package/dist/flatgeobuf/flatgeobuf-loader-types.d.ts +25 -34
  27. package/dist/flatgeobuf/flatgeobuf-loader-types.d.ts.map +1 -1
  28. package/dist/flatgeobuf/flatgeobuf-loader-types.js +10 -5
  29. package/dist/flatgeobuf/flatgeobuf-loader-types.js.map +1 -1
  30. package/dist/flatgeobuf/flatgeobuf-loader.cjs +66 -0
  31. package/dist/flatgeobuf/flatgeobuf-loader.cjs.map +7 -0
  32. package/dist/flatgeobuf/flatgeobuf-loader.d.ts +22 -6
  33. package/dist/flatgeobuf/flatgeobuf-loader.d.ts.map +1 -1
  34. package/dist/flatgeobuf/flatgeobuf-loader.js +4 -2
  35. package/dist/flatgeobuf/flatgeobuf-loader.js.map +1 -1
  36. package/dist/flatgeobuf/flatgeobuf-source-loader.cjs +242 -0
  37. package/dist/flatgeobuf/flatgeobuf-source-loader.cjs.map +7 -0
  38. package/dist/flatgeobuf/flatgeobuf-source-loader.d.ts +8 -32
  39. package/dist/flatgeobuf/flatgeobuf-source-loader.d.ts.map +1 -1
  40. package/dist/flatgeobuf/flatgeobuf-source-loader.js +16 -22
  41. package/dist/flatgeobuf/flatgeobuf-source-loader.js.map +1 -1
  42. package/dist/flatgeobuf/flatgeobuf-table-query-capabilities.cjs +37 -0
  43. package/dist/flatgeobuf/flatgeobuf-table-query-capabilities.cjs.map +7 -0
  44. package/dist/flatgeobuf/index.cjs +19 -5522
  45. package/dist/flatgeobuf/index.cjs.map +4 -3
  46. package/dist/flatgeobuf/index.d.ts +1 -3
  47. package/dist/flatgeobuf/index.d.ts.map +1 -1
  48. package/dist/flatgeobuf/index.js +1 -4
  49. package/dist/flatgeobuf/index.js.map +1 -1
  50. package/dist/flatgeobuf/lib/flatgeobuf-reader.cjs +596 -0
  51. package/dist/flatgeobuf/lib/flatgeobuf-reader.cjs.map +7 -0
  52. package/dist/flatgeobuf/lib/flatgeobuf-reader.d.ts +2 -2
  53. package/dist/flatgeobuf/lib/flatgeobuf-reader.d.ts.map +1 -1
  54. package/dist/flatgeobuf/lib/flatgeobuf-reader.js.map +1 -1
  55. package/dist/flatgeobuf/lib/flatgeobuf-worker-transport.cjs +43 -0
  56. package/dist/flatgeobuf/lib/flatgeobuf-worker-transport.cjs.map +7 -0
  57. package/dist/flatgeobuf/lib/flatgeobuf-worker-transport.d.ts +5 -4
  58. package/dist/flatgeobuf/lib/flatgeobuf-worker-transport.d.ts.map +1 -1
  59. package/dist/flatgeobuf/lib/flatgeobuf-worker-transport.js +7 -34
  60. package/dist/flatgeobuf/lib/flatgeobuf-worker-transport.js.map +1 -1
  61. package/dist/flatgeobuf/lib/parse-flatgeobuf.cjs +330 -0
  62. package/dist/flatgeobuf/lib/parse-flatgeobuf.cjs.map +7 -0
  63. package/dist/flatgeobuf/lib/parse-flatgeobuf.d.ts +3 -2
  64. package/dist/flatgeobuf/lib/parse-flatgeobuf.d.ts.map +1 -1
  65. package/dist/flatgeobuf/lib/parse-flatgeobuf.js +9 -9
  66. package/dist/flatgeobuf/lib/parse-flatgeobuf.js.map +1 -1
  67. package/dist/flatgeobuf/unbundled.cjs +31 -0
  68. package/dist/flatgeobuf/unbundled.cjs.map +7 -0
  69. package/dist/flatgeobuf/unbundled.d.ts +1 -1
  70. package/dist/flatgeobuf/unbundled.d.ts.map +1 -1
  71. package/dist/flatgeobuf/unbundled.js +1 -1
  72. package/dist/flatgeobuf/unbundled.js.map +1 -1
  73. package/dist/flatgeobuf-loader-types.cjs +74 -0
  74. package/dist/flatgeobuf-loader-types.cjs.map +7 -0
  75. package/dist/flatgeobuf-loader-types.d.ts +2 -0
  76. package/dist/flatgeobuf-loader-types.d.ts.map +1 -0
  77. package/dist/flatgeobuf-loader-types.js +2 -0
  78. package/dist/flatgeobuf-loader-types.js.map +1 -0
  79. package/dist/flatgeobuf-loader.cjs +68 -0
  80. package/dist/flatgeobuf-loader.cjs.map +7 -0
  81. package/dist/flatgeobuf-loader.d.ts +2 -0
  82. package/dist/flatgeobuf-loader.d.ts.map +1 -0
  83. package/dist/flatgeobuf-loader.js +2 -0
  84. package/dist/flatgeobuf-loader.js.map +1 -0
  85. package/dist/flatgeobuf-source-loader.cjs +244 -0
  86. package/dist/flatgeobuf-source-loader.cjs.map +7 -0
  87. package/dist/flatgeobuf-source-loader.d.ts +2 -0
  88. package/dist/flatgeobuf-source-loader.d.ts.map +1 -0
  89. package/dist/flatgeobuf-source-loader.js +2 -0
  90. package/dist/flatgeobuf-source-loader.js.map +1 -0
  91. package/dist/flatgeobuf-worker.js +7152 -3857
  92. package/dist/flatgeobuf.cjs +25 -0
  93. package/dist/flatgeobuf.cjs.map +7 -0
  94. package/dist/geopackage/bundled.cjs +31 -0
  95. package/dist/geopackage/bundled.cjs.map +7 -0
  96. package/dist/geopackage/geopackage-format.cjs +40 -0
  97. package/dist/geopackage/geopackage-format.cjs.map +7 -0
  98. package/dist/geopackage/geopackage-loader-options.cjs +33 -0
  99. package/dist/geopackage/geopackage-loader-options.cjs.map +7 -0
  100. package/dist/geopackage/geopackage-loader-types.cjs +67 -0
  101. package/dist/geopackage/geopackage-loader-types.cjs.map +7 -0
  102. package/dist/geopackage/geopackage-loader-types.d.ts +19 -6
  103. package/dist/geopackage/geopackage-loader-types.d.ts.map +1 -1
  104. package/dist/geopackage/geopackage-loader-types.js +8 -2
  105. package/dist/geopackage/geopackage-loader-types.js.map +1 -1
  106. package/dist/geopackage/geopackage-loader.cjs +39 -0
  107. package/dist/geopackage/geopackage-loader.cjs.map +7 -0
  108. package/dist/geopackage/geopackage-loader.d.ts +11 -3
  109. package/dist/geopackage/geopackage-loader.d.ts.map +1 -1
  110. package/dist/geopackage/geopackage-loader.js +2 -0
  111. package/dist/geopackage/geopackage-loader.js.map +1 -1
  112. package/dist/geopackage/geopackage-source-loader.cjs +263 -0
  113. package/dist/geopackage/geopackage-source-loader.cjs.map +7 -0
  114. package/dist/geopackage/geopackage-source-loader.d.ts +17 -43
  115. package/dist/geopackage/geopackage-source-loader.d.ts.map +1 -1
  116. package/dist/geopackage/geopackage-source-loader.js +42 -42
  117. package/dist/geopackage/geopackage-source-loader.js.map +1 -1
  118. package/dist/geopackage/index.cjs +16 -4412
  119. package/dist/geopackage/index.cjs.map +4 -3
  120. package/dist/geopackage/index.d.ts +1 -1
  121. package/dist/geopackage/index.d.ts.map +1 -1
  122. package/dist/geopackage/index.js +1 -1
  123. package/dist/geopackage/index.js.map +1 -1
  124. package/dist/geopackage/lib/geopackage-tile-metadata.cjs +124 -0
  125. package/dist/geopackage/lib/geopackage-tile-metadata.cjs.map +7 -0
  126. package/dist/geopackage/lib/parse-geopackage.cjs +535 -0
  127. package/dist/geopackage/lib/parse-geopackage.cjs.map +7 -0
  128. package/dist/geopackage/lib/parse-geopackage.d.ts +2 -1
  129. package/dist/geopackage/lib/parse-geopackage.d.ts.map +1 -1
  130. package/dist/geopackage/lib/parse-geopackage.js +13 -10
  131. package/dist/geopackage/lib/parse-geopackage.js.map +1 -1
  132. package/dist/geopackage/lib/types.cjs +19 -0
  133. package/dist/geopackage/lib/types.cjs.map +7 -0
  134. package/dist/geopackage/unbundled.cjs +31 -0
  135. package/dist/geopackage/unbundled.cjs.map +7 -0
  136. package/dist/geopackage-loader-types.cjs +69 -0
  137. package/dist/geopackage-loader-types.cjs.map +7 -0
  138. package/dist/geopackage-loader-types.d.ts +2 -0
  139. package/dist/geopackage-loader-types.d.ts.map +1 -0
  140. package/dist/geopackage-loader-types.js +2 -0
  141. package/dist/geopackage-loader-types.js.map +1 -0
  142. package/dist/geopackage-loader.cjs +41 -0
  143. package/dist/geopackage-loader.cjs.map +7 -0
  144. package/dist/geopackage-loader.d.ts +2 -0
  145. package/dist/geopackage-loader.d.ts.map +1 -0
  146. package/dist/geopackage-loader.js +2 -0
  147. package/dist/geopackage-loader.js.map +1 -0
  148. package/dist/geopackage-source-loader.cjs +265 -0
  149. package/dist/geopackage-source-loader.cjs.map +7 -0
  150. package/dist/geopackage-source-loader.d.ts +2 -0
  151. package/dist/geopackage-source-loader.d.ts.map +1 -0
  152. package/dist/geopackage-source-loader.js +2 -0
  153. package/dist/geopackage-source-loader.js.map +1 -0
  154. package/dist/geopackage.cjs +25 -0
  155. package/dist/geopackage.cjs.map +7 -0
  156. package/dist/gpx-loader-types.cjs +61 -0
  157. package/dist/gpx-loader-types.cjs.map +7 -0
  158. package/dist/gpx-loader-types.d.ts +2 -0
  159. package/dist/gpx-loader-types.d.ts.map +1 -0
  160. package/dist/gpx-loader-types.js +2 -0
  161. package/dist/gpx-loader-types.js.map +1 -0
  162. package/dist/gpx-loader.cjs +79 -0
  163. package/dist/gpx-loader.cjs.map +7 -0
  164. package/dist/gpx-loader.d.ts +2 -0
  165. package/dist/gpx-loader.d.ts.map +1 -0
  166. package/dist/gpx-loader.js +2 -0
  167. package/dist/gpx-loader.js.map +1 -0
  168. package/dist/gpx.cjs +31 -0
  169. package/dist/gpx.cjs.map +7 -0
  170. package/dist/hex-wkb-loader-types.cjs +74 -0
  171. package/dist/hex-wkb-loader-types.cjs.map +7 -0
  172. package/dist/hex-wkb-loader-types.d.ts +2 -0
  173. package/dist/hex-wkb-loader-types.d.ts.map +1 -0
  174. package/dist/hex-wkb-loader-types.js +2 -0
  175. package/dist/hex-wkb-loader-types.js.map +1 -0
  176. package/dist/hex-wkb-loader.cjs +69 -0
  177. package/dist/hex-wkb-loader.cjs.map +7 -0
  178. package/dist/hex-wkb-loader.d.ts +2 -0
  179. package/dist/hex-wkb-loader.d.ts.map +1 -0
  180. package/dist/hex-wkb-loader.js +2 -0
  181. package/dist/hex-wkb-loader.js.map +1 -0
  182. package/dist/index.cjs +64 -15169
  183. package/dist/index.cjs.map +4 -3
  184. package/dist/index.d.ts +3 -3
  185. package/dist/index.d.ts.map +1 -1
  186. package/dist/index.js +3 -3
  187. package/dist/index.js.map +1 -1
  188. package/dist/kml/bundled.cjs +50 -0
  189. package/dist/kml/bundled.cjs.map +7 -0
  190. package/dist/kml/bundled.d.ts +1 -1
  191. package/dist/kml/bundled.d.ts.map +1 -1
  192. package/dist/kml/bundled.js +1 -1
  193. package/dist/kml/bundled.js.map +1 -1
  194. package/dist/kml/gpx-loader-types.cjs +59 -0
  195. package/dist/kml/gpx-loader-types.cjs.map +7 -0
  196. package/dist/kml/gpx-loader-types.d.ts +11 -6
  197. package/dist/kml/gpx-loader-types.d.ts.map +1 -1
  198. package/dist/kml/gpx-loader-types.js +4 -2
  199. package/dist/kml/gpx-loader-types.js.map +1 -1
  200. package/dist/kml/gpx-loader.cjs +77 -0
  201. package/dist/kml/gpx-loader.cjs.map +7 -0
  202. package/dist/kml/gpx-loader.d.ts +9 -18
  203. package/dist/kml/gpx-loader.d.ts.map +1 -1
  204. package/dist/kml/gpx-loader.js +3 -3
  205. package/dist/kml/gpx-loader.js.map +1 -1
  206. package/dist/kml/index.cjs +48 -11414
  207. package/dist/kml/index.cjs.map +4 -3
  208. package/dist/kml/index.d.ts +1 -1
  209. package/dist/kml/index.d.ts.map +1 -1
  210. package/dist/kml/index.js +1 -1
  211. package/dist/kml/index.js.map +1 -1
  212. package/dist/kml/kml-format.cjs +87 -0
  213. package/dist/kml/kml-format.cjs.map +7 -0
  214. package/dist/kml/kml-loader-types.cjs +59 -0
  215. package/dist/kml/kml-loader-types.cjs.map +7 -0
  216. package/dist/kml/kml-loader-types.d.ts +11 -6
  217. package/dist/kml/kml-loader-types.d.ts.map +1 -1
  218. package/dist/kml/kml-loader-types.js +5 -3
  219. package/dist/kml/kml-loader-types.js.map +1 -1
  220. package/dist/kml/kml-loader.cjs +75 -0
  221. package/dist/kml/kml-loader.cjs.map +7 -0
  222. package/dist/kml/kml-loader.d.ts +9 -18
  223. package/dist/kml/kml-loader.d.ts.map +1 -1
  224. package/dist/kml/kml-loader.js +2 -2
  225. package/dist/kml/kml-loader.js.map +1 -1
  226. package/dist/kml/kml-parser.cjs +443 -0
  227. package/dist/kml/kml-parser.cjs.map +7 -0
  228. package/dist/kml/kml-parser.d.ts.map +1 -1
  229. package/dist/kml/kml-parser.js +3 -2
  230. package/dist/kml/kml-parser.js.map +1 -1
  231. package/dist/kml/kml-writer.cjs +210 -0
  232. package/dist/kml/kml-writer.cjs.map +7 -0
  233. package/dist/kml/kml-writer.js +1 -1
  234. package/dist/kml/kml-writer.js.map +1 -1
  235. package/dist/kml/kmz-archive.cjs +90 -0
  236. package/dist/kml/kmz-archive.cjs.map +7 -0
  237. package/dist/kml/kmz-loader-types.cjs +66 -0
  238. package/dist/kml/kmz-loader-types.cjs.map +7 -0
  239. package/dist/kml/kmz-loader-types.d.ts +24 -6
  240. package/dist/kml/kmz-loader-types.d.ts.map +1 -1
  241. package/dist/kml/kmz-loader-types.js +10 -2
  242. package/dist/kml/kmz-loader-types.js.map +1 -1
  243. package/dist/kml/kmz-loader.cjs +69 -0
  244. package/dist/kml/kmz-loader.cjs.map +7 -0
  245. package/dist/kml/kmz-loader.d.ts +13 -3
  246. package/dist/kml/kmz-loader.d.ts.map +1 -1
  247. package/dist/kml/kmz-loader.js +5 -2
  248. package/dist/kml/kmz-loader.js.map +1 -1
  249. package/dist/kml/kmz-source.cjs +175 -0
  250. package/dist/kml/kmz-source.cjs.map +7 -0
  251. package/dist/kml/kmz-source.d.ts +2 -32
  252. package/dist/kml/kmz-source.d.ts.map +1 -1
  253. package/dist/kml/kmz-source.js +7 -19
  254. package/dist/kml/kmz-source.js.map +1 -1
  255. package/dist/kml/lib/feature-collection-to-arrow.cjs +150 -0
  256. package/dist/kml/lib/feature-collection-to-arrow.cjs.map +7 -0
  257. package/dist/kml/lib/feature-collection-to-arrow.d.ts +3 -2
  258. package/dist/kml/lib/feature-collection-to-arrow.d.ts.map +1 -1
  259. package/dist/kml/lib/feature-collection-to-arrow.js +3 -3
  260. package/dist/kml/lib/feature-collection-to-arrow.js.map +1 -1
  261. package/dist/kml/sports-track-parser.cjs +384 -0
  262. package/dist/kml/sports-track-parser.cjs.map +7 -0
  263. package/dist/kml/sports-track-parser.js +3 -2
  264. package/dist/kml/sports-track-parser.js.map +1 -1
  265. package/dist/kml/tcx-loader-types.cjs +59 -0
  266. package/dist/kml/tcx-loader-types.cjs.map +7 -0
  267. package/dist/kml/tcx-loader-types.d.ts +11 -6
  268. package/dist/kml/tcx-loader-types.d.ts.map +1 -1
  269. package/dist/kml/tcx-loader-types.js +4 -2
  270. package/dist/kml/tcx-loader-types.js.map +1 -1
  271. package/dist/kml/tcx-loader.cjs +77 -0
  272. package/dist/kml/tcx-loader.cjs.map +7 -0
  273. package/dist/kml/tcx-loader.d.ts +9 -18
  274. package/dist/kml/tcx-loader.d.ts.map +1 -1
  275. package/dist/kml/tcx-loader.js +3 -3
  276. package/dist/kml/tcx-loader.js.map +1 -1
  277. package/dist/kml/unbundled.cjs +50 -0
  278. package/dist/kml/unbundled.cjs.map +7 -0
  279. package/dist/kml/unbundled.d.ts +1 -1
  280. package/dist/kml/unbundled.d.ts.map +1 -1
  281. package/dist/kml/unbundled.js +1 -1
  282. package/dist/kml/unbundled.js.map +1 -1
  283. package/dist/kml-loader-types.cjs +61 -0
  284. package/dist/kml-loader-types.cjs.map +7 -0
  285. package/dist/kml-loader-types.d.ts +2 -0
  286. package/dist/kml-loader-types.d.ts.map +1 -0
  287. package/dist/kml-loader-types.js +2 -0
  288. package/dist/kml-loader-types.js.map +1 -0
  289. package/dist/kml-loader.cjs +77 -0
  290. package/dist/kml-loader.cjs.map +7 -0
  291. package/dist/kml-loader.d.ts +2 -0
  292. package/dist/kml-loader.d.ts.map +1 -0
  293. package/dist/kml-loader.js +2 -0
  294. package/dist/kml-loader.js.map +1 -0
  295. package/dist/kml-writer.cjs +212 -0
  296. package/dist/kml-writer.cjs.map +7 -0
  297. package/dist/kml-writer.d.ts +2 -0
  298. package/dist/kml-writer.d.ts.map +1 -0
  299. package/dist/kml-writer.js +2 -0
  300. package/dist/kml-writer.js.map +1 -0
  301. package/dist/kml.cjs +25 -0
  302. package/dist/kml.cjs.map +7 -0
  303. package/dist/kmz-loader-types.cjs +68 -0
  304. package/dist/kmz-loader-types.cjs.map +7 -0
  305. package/dist/kmz-loader-types.d.ts +2 -0
  306. package/dist/kmz-loader-types.d.ts.map +1 -0
  307. package/dist/kmz-loader-types.js +2 -0
  308. package/dist/kmz-loader-types.js.map +1 -0
  309. package/dist/kmz-loader.cjs +71 -0
  310. package/dist/kmz-loader.cjs.map +7 -0
  311. package/dist/kmz-loader.d.ts +2 -0
  312. package/dist/kmz-loader.d.ts.map +1 -0
  313. package/dist/kmz-loader.js +2 -0
  314. package/dist/kmz-loader.js.map +1 -0
  315. package/dist/kmz-source.cjs +177 -0
  316. package/dist/kmz-source.cjs.map +7 -0
  317. package/dist/kmz-source.d.ts +2 -0
  318. package/dist/kmz-source.d.ts.map +1 -0
  319. package/dist/kmz-source.js +2 -0
  320. package/dist/kmz-source.js.map +1 -0
  321. package/dist/kmz.cjs +31 -0
  322. package/dist/kmz.cjs.map +7 -0
  323. package/dist/shapefile/bundled.cjs +41 -0
  324. package/dist/shapefile/bundled.cjs.map +7 -0
  325. package/dist/shapefile/dbf-format.cjs +40 -0
  326. package/dist/shapefile/dbf-format.cjs.map +7 -0
  327. package/dist/shapefile/dbf-loader-types.cjs +66 -0
  328. package/dist/shapefile/dbf-loader-types.cjs.map +7 -0
  329. package/dist/shapefile/dbf-loader-types.d.ts +1 -3
  330. package/dist/shapefile/dbf-loader-types.d.ts.map +1 -1
  331. package/dist/shapefile/dbf-loader-types.js +4 -4
  332. package/dist/shapefile/dbf-loader-types.js.map +1 -1
  333. package/dist/shapefile/dbf-loader.cjs +81 -0
  334. package/dist/shapefile/dbf-loader.cjs.map +7 -0
  335. package/dist/shapefile/dbf-loader.d.ts +311 -4
  336. package/dist/shapefile/dbf-loader.d.ts.map +1 -1
  337. package/dist/shapefile/dbf-loader.js +43 -11
  338. package/dist/shapefile/dbf-loader.js.map +1 -1
  339. package/dist/shapefile/index.cjs +33 -5721
  340. package/dist/shapefile/index.cjs.map +4 -3
  341. package/dist/shapefile/index.d.ts +0 -4
  342. package/dist/shapefile/index.d.ts.map +1 -1
  343. package/dist/shapefile/index.js +0 -5
  344. package/dist/shapefile/index.js.map +1 -1
  345. package/dist/shapefile/lib/parsers/build-geoarrow-geometry-arrow.cjs +166 -0
  346. package/dist/shapefile/lib/parsers/build-geoarrow-geometry-arrow.cjs.map +7 -0
  347. package/dist/shapefile/lib/parsers/build-geoarrow-geometry-arrow.d.ts +1 -1
  348. package/dist/shapefile/lib/parsers/build-geoarrow-geometry-arrow.d.ts.map +1 -1
  349. package/dist/shapefile/lib/parsers/build-geoarrow-geometry-arrow.js +3 -3
  350. package/dist/shapefile/lib/parsers/build-geoarrow-geometry-arrow.js.map +1 -1
  351. package/dist/shapefile/lib/parsers/build-wkb-geometry-arrow.cjs +266 -0
  352. package/dist/shapefile/lib/parsers/build-wkb-geometry-arrow.cjs.map +7 -0
  353. package/dist/shapefile/lib/parsers/build-wkb-geometry-arrow.d.ts +1 -1
  354. package/dist/shapefile/lib/parsers/build-wkb-geometry-arrow.d.ts.map +1 -1
  355. package/dist/shapefile/lib/parsers/build-wkb-geometry-arrow.js +2 -2
  356. package/dist/shapefile/lib/parsers/build-wkb-geometry-arrow.js.map +1 -1
  357. package/dist/shapefile/lib/parsers/parse-dbf-to-arrow.cjs +306 -0
  358. package/dist/shapefile/lib/parsers/parse-dbf-to-arrow.cjs.map +7 -0
  359. package/dist/shapefile/lib/parsers/parse-dbf-to-arrow.d.ts +5 -3
  360. package/dist/shapefile/lib/parsers/parse-dbf-to-arrow.d.ts.map +1 -1
  361. package/dist/shapefile/lib/parsers/parse-dbf-to-arrow.js +10 -2
  362. package/dist/shapefile/lib/parsers/parse-dbf-to-arrow.js.map +1 -1
  363. package/dist/shapefile/lib/parsers/parse-dbf.cjs +287 -0
  364. package/dist/shapefile/lib/parsers/parse-dbf.cjs.map +7 -0
  365. package/dist/shapefile/lib/parsers/parse-shapefile.cjs +286 -0
  366. package/dist/shapefile/lib/parsers/parse-shapefile.cjs.map +7 -0
  367. package/dist/shapefile/lib/parsers/parse-shapefile.js +3 -3
  368. package/dist/shapefile/lib/parsers/parse-shapefile.js.map +1 -1
  369. package/dist/shapefile/lib/parsers/parse-shp-geometry.cjs +359 -0
  370. package/dist/shapefile/lib/parsers/parse-shp-geometry.cjs.map +7 -0
  371. package/dist/shapefile/lib/parsers/parse-shp-geometry.d.ts +1 -1
  372. package/dist/shapefile/lib/parsers/parse-shp-geometry.d.ts.map +1 -1
  373. package/dist/shapefile/lib/parsers/parse-shp-geometry.js +1 -1
  374. package/dist/shapefile/lib/parsers/parse-shp-geometry.js.map +1 -1
  375. package/dist/shapefile/lib/parsers/parse-shp-header.cjs +60 -0
  376. package/dist/shapefile/lib/parsers/parse-shp-header.cjs.map +7 -0
  377. package/dist/shapefile/lib/parsers/parse-shp-header.d.ts +2 -1
  378. package/dist/shapefile/lib/parsers/parse-shp-header.d.ts.map +1 -1
  379. package/dist/shapefile/lib/parsers/parse-shp-header.js +4 -5
  380. package/dist/shapefile/lib/parsers/parse-shp-header.js.map +1 -1
  381. package/dist/shapefile/lib/parsers/parse-shp-to-arrow.cjs +165 -0
  382. package/dist/shapefile/lib/parsers/parse-shp-to-arrow.cjs.map +7 -0
  383. package/dist/shapefile/lib/parsers/parse-shp-to-arrow.js +5 -5
  384. package/dist/shapefile/lib/parsers/parse-shp-to-arrow.js.map +1 -1
  385. package/dist/shapefile/lib/parsers/parse-shp.cjs +184 -0
  386. package/dist/shapefile/lib/parsers/parse-shp.cjs.map +7 -0
  387. package/dist/shapefile/lib/parsers/parse-shp.js +1 -1
  388. package/dist/shapefile/lib/parsers/parse-shp.js.map +1 -1
  389. package/dist/shapefile/lib/parsers/parse-shx.cjs +49 -0
  390. package/dist/shapefile/lib/parsers/parse-shx.cjs.map +7 -0
  391. package/dist/shapefile/lib/parsers/types.cjs +19 -0
  392. package/dist/shapefile/lib/parsers/types.cjs.map +7 -0
  393. package/dist/shapefile/lib/parsers/types.d.ts +3 -3
  394. package/dist/shapefile/lib/parsers/types.d.ts.map +1 -1
  395. package/dist/shapefile/lib/shapefile-worker-transport.cjs +77 -0
  396. package/dist/shapefile/lib/shapefile-worker-transport.cjs.map +7 -0
  397. package/dist/shapefile/lib/shapefile-worker-transport.d.ts +6 -7
  398. package/dist/shapefile/lib/shapefile-worker-transport.d.ts.map +1 -1
  399. package/dist/shapefile/lib/shapefile-worker-transport.js +43 -35
  400. package/dist/shapefile/lib/shapefile-worker-transport.js.map +1 -1
  401. package/dist/shapefile/lib/streaming/binary-chunk-reader.cjs +31 -0
  402. package/dist/shapefile/lib/streaming/binary-chunk-reader.cjs.map +7 -0
  403. package/dist/shapefile/lib/streaming/binary-reader.cjs +77 -0
  404. package/dist/shapefile/lib/streaming/binary-reader.cjs.map +7 -0
  405. package/dist/shapefile/lib/streaming/zip-batch-iterators.cjs +73 -0
  406. package/dist/shapefile/lib/streaming/zip-batch-iterators.cjs.map +7 -0
  407. package/dist/shapefile/shapefile-arrow-loader.cjs +413 -0
  408. package/dist/shapefile/shapefile-arrow-loader.cjs.map +7 -0
  409. package/dist/shapefile/shapefile-arrow-loader.d.ts.map +1 -1
  410. package/dist/shapefile/shapefile-arrow-loader.js +59 -20
  411. package/dist/shapefile/shapefile-arrow-loader.js.map +1 -1
  412. package/dist/shapefile/shapefile-loader-types.cjs +65 -0
  413. package/dist/shapefile/shapefile-loader-types.cjs.map +7 -0
  414. package/dist/shapefile/shapefile-loader-types.d.ts +23 -12
  415. package/dist/shapefile/shapefile-loader-types.d.ts.map +1 -1
  416. package/dist/shapefile/shapefile-loader-types.js +7 -3
  417. package/dist/shapefile/shapefile-loader-types.js.map +1 -1
  418. package/dist/shapefile/shapefile-loader.cjs +122 -0
  419. package/dist/shapefile/shapefile-loader.cjs.map +7 -0
  420. package/dist/shapefile/shapefile-loader.d.ts +52 -8
  421. package/dist/shapefile/shapefile-loader.d.ts.map +1 -1
  422. package/dist/shapefile/shapefile-loader.js +90 -10
  423. package/dist/shapefile/shapefile-loader.js.map +1 -1
  424. package/dist/shapefile/shp-format.cjs +57 -0
  425. package/dist/shapefile/shp-format.cjs.map +7 -0
  426. package/dist/shapefile/shp-loader-types.cjs +65 -0
  427. package/dist/shapefile/shp-loader-types.cjs.map +7 -0
  428. package/dist/shapefile/shp-loader-types.d.ts +1 -3
  429. package/dist/shapefile/shp-loader-types.d.ts.map +1 -1
  430. package/dist/shapefile/shp-loader-types.js +4 -4
  431. package/dist/shapefile/shp-loader-types.js.map +1 -1
  432. package/dist/shapefile/shp-loader.cjs +106 -0
  433. package/dist/shapefile/shp-loader.cjs.map +7 -0
  434. package/dist/shapefile/shp-loader.d.ts +191 -2
  435. package/dist/shapefile/shp-loader.d.ts.map +1 -1
  436. package/dist/shapefile/shp-loader.js +62 -8
  437. package/dist/shapefile/shp-loader.js.map +1 -1
  438. package/dist/shapefile/unbundled.cjs +37 -0
  439. package/dist/shapefile/unbundled.cjs.map +7 -0
  440. package/dist/shapefile/unbundled.d.ts +2 -2
  441. package/dist/shapefile/unbundled.d.ts.map +1 -1
  442. package/dist/shapefile/unbundled.js +2 -2
  443. package/dist/shapefile/unbundled.js.map +1 -1
  444. package/dist/shapefile-arrow-loader.cjs +415 -0
  445. package/dist/shapefile-arrow-loader.cjs.map +7 -0
  446. package/dist/shapefile-arrow-loader.d.ts +2 -0
  447. package/dist/shapefile-arrow-loader.d.ts.map +1 -0
  448. package/dist/shapefile-arrow-loader.js +2 -0
  449. package/dist/shapefile-arrow-loader.js.map +1 -0
  450. package/dist/shapefile-loader-types.cjs +67 -0
  451. package/dist/shapefile-loader-types.cjs.map +7 -0
  452. package/dist/shapefile-loader-types.d.ts +2 -0
  453. package/dist/shapefile-loader-types.d.ts.map +1 -0
  454. package/dist/shapefile-loader-types.js +2 -0
  455. package/dist/shapefile-loader-types.js.map +1 -0
  456. package/dist/shapefile-loader.cjs +124 -0
  457. package/dist/shapefile-loader.cjs.map +7 -0
  458. package/dist/shapefile-loader.d.ts +2 -0
  459. package/dist/shapefile-loader.d.ts.map +1 -0
  460. package/dist/shapefile-loader.js +2 -0
  461. package/dist/shapefile-loader.js.map +1 -0
  462. package/dist/shapefile-worker.js +36978 -0
  463. package/dist/shapefile.cjs +25 -0
  464. package/dist/shapefile.cjs.map +7 -0
  465. package/dist/shp-loader-types.cjs +67 -0
  466. package/dist/shp-loader-types.cjs.map +7 -0
  467. package/dist/shp-loader-types.d.ts +2 -0
  468. package/dist/shp-loader-types.d.ts.map +1 -0
  469. package/dist/shp-loader-types.js +2 -0
  470. package/dist/shp-loader-types.js.map +1 -0
  471. package/dist/shp-loader.cjs +108 -0
  472. package/dist/shp-loader.cjs.map +7 -0
  473. package/dist/shp-loader.d.ts +2 -0
  474. package/dist/shp-loader.d.ts.map +1 -0
  475. package/dist/shp-loader.js +2 -0
  476. package/dist/shp-loader.js.map +1 -0
  477. package/dist/shp-worker.js +7329 -5592
  478. package/dist/shp.cjs +31 -0
  479. package/dist/shp.cjs.map +7 -0
  480. package/dist/tcx-loader-types.cjs +61 -0
  481. package/dist/tcx-loader-types.cjs.map +7 -0
  482. package/dist/tcx-loader-types.d.ts +2 -0
  483. package/dist/tcx-loader-types.d.ts.map +1 -0
  484. package/dist/tcx-loader-types.js +2 -0
  485. package/dist/tcx-loader-types.js.map +1 -0
  486. package/dist/tcx-loader.cjs +79 -0
  487. package/dist/tcx-loader.cjs.map +7 -0
  488. package/dist/tcx-loader.d.ts +2 -0
  489. package/dist/tcx-loader.d.ts.map +1 -0
  490. package/dist/tcx-loader.js +2 -0
  491. package/dist/tcx-loader.js.map +1 -0
  492. package/dist/tcx.cjs +31 -0
  493. package/dist/tcx.cjs.map +7 -0
  494. package/dist/twkb-loader-types.cjs +73 -0
  495. package/dist/twkb-loader-types.cjs.map +7 -0
  496. package/dist/twkb-loader-types.d.ts +2 -0
  497. package/dist/twkb-loader-types.d.ts.map +1 -0
  498. package/dist/twkb-loader-types.js +2 -0
  499. package/dist/twkb-loader-types.js.map +1 -0
  500. package/dist/twkb-loader.cjs +47 -0
  501. package/dist/twkb-loader.cjs.map +7 -0
  502. package/dist/twkb-loader.d.ts +2 -0
  503. package/dist/twkb-loader.d.ts.map +1 -0
  504. package/dist/twkb-loader.js +2 -0
  505. package/dist/twkb-loader.js.map +1 -0
  506. package/dist/twkb-writer.cjs +52 -0
  507. package/dist/twkb-writer.cjs.map +7 -0
  508. package/dist/twkb-writer.d.ts +2 -0
  509. package/dist/twkb-writer.d.ts.map +1 -0
  510. package/dist/twkb-writer.js +2 -0
  511. package/dist/twkb-writer.js.map +1 -0
  512. package/dist/twkb.cjs +34 -0
  513. package/dist/twkb.cjs.map +7 -0
  514. package/dist/twkb.d.ts +3 -0
  515. package/dist/twkb.d.ts.map +1 -0
  516. package/dist/twkb.js +6 -0
  517. package/dist/twkb.js.map +1 -0
  518. package/dist/wkb-loader-types.cjs +62 -0
  519. package/dist/wkb-loader-types.cjs.map +7 -0
  520. package/dist/wkb-loader-types.d.ts +2 -0
  521. package/dist/wkb-loader-types.d.ts.map +1 -0
  522. package/dist/wkb-loader-types.js +2 -0
  523. package/dist/wkb-loader-types.js.map +1 -0
  524. package/dist/wkb-loader.cjs +58 -0
  525. package/dist/wkb-loader.cjs.map +7 -0
  526. package/dist/wkb-loader.d.ts +2 -0
  527. package/dist/wkb-loader.d.ts.map +1 -0
  528. package/dist/wkb-loader.js +2 -0
  529. package/dist/wkb-loader.js.map +1 -0
  530. package/dist/wkb-writer.cjs +56 -0
  531. package/dist/wkb-writer.cjs.map +7 -0
  532. package/dist/wkb-writer.d.ts +2 -0
  533. package/dist/wkb-writer.d.ts.map +1 -0
  534. package/dist/wkb-writer.js +2 -0
  535. package/dist/wkb-writer.js.map +1 -0
  536. package/dist/wkb.cjs +34 -0
  537. package/dist/wkb.cjs.map +7 -0
  538. package/dist/wkb.d.ts +3 -0
  539. package/dist/wkb.d.ts.map +1 -0
  540. package/dist/wkb.js +6 -0
  541. package/dist/wkb.js.map +1 -0
  542. package/dist/wkt/bundled.cjs +47 -0
  543. package/dist/wkt/bundled.cjs.map +7 -0
  544. package/dist/wkt/bundled.d.ts +7 -0
  545. package/dist/wkt/bundled.d.ts.map +1 -0
  546. package/dist/wkt/bundled.js +9 -0
  547. package/dist/wkt/bundled.js.map +1 -0
  548. package/dist/wkt/hex-wkb-loader-types.cjs +72 -0
  549. package/dist/wkt/hex-wkb-loader-types.cjs.map +7 -0
  550. package/dist/wkt/hex-wkb-loader-types.d.ts +65 -0
  551. package/dist/wkt/hex-wkb-loader-types.d.ts.map +1 -0
  552. package/dist/wkt/hex-wkb-loader-types.js +51 -0
  553. package/dist/wkt/hex-wkb-loader-types.js.map +1 -0
  554. package/dist/wkt/hex-wkb-loader.cjs +67 -0
  555. package/dist/wkt/hex-wkb-loader.cjs.map +7 -0
  556. package/dist/wkt/hex-wkb-loader.d.ts +41 -0
  557. package/dist/wkt/hex-wkb-loader.d.ts.map +1 -0
  558. package/dist/wkt/hex-wkb-loader.js +54 -0
  559. package/dist/wkt/hex-wkb-loader.js.map +1 -0
  560. package/dist/wkt/index.cjs +66 -0
  561. package/dist/wkt/index.cjs.map +7 -0
  562. package/dist/wkt/index.d.ts +11 -0
  563. package/dist/wkt/index.d.ts.map +1 -0
  564. package/dist/wkt/index.js +14 -0
  565. package/dist/wkt/index.js.map +1 -0
  566. package/dist/wkt/lib/version.cjs +31 -0
  567. package/dist/wkt/lib/version.cjs.map +7 -0
  568. package/dist/wkt/lib/version.d.ts +2 -0
  569. package/dist/wkt/lib/version.d.ts.map +1 -0
  570. package/dist/wkt/lib/version.js +8 -0
  571. package/dist/wkt/lib/version.js.map +1 -0
  572. package/dist/wkt/twkb-loader-types.cjs +71 -0
  573. package/dist/wkt/twkb-loader-types.cjs.map +7 -0
  574. package/dist/wkt/twkb-loader-types.d.ts +61 -0
  575. package/dist/wkt/twkb-loader-types.d.ts.map +1 -0
  576. package/dist/wkt/twkb-loader-types.js +40 -0
  577. package/dist/wkt/twkb-loader-types.js.map +1 -0
  578. package/dist/wkt/twkb-loader.cjs +45 -0
  579. package/dist/wkt/twkb-loader.cjs.map +7 -0
  580. package/dist/wkt/twkb-loader.d.ts +59 -0
  581. package/dist/wkt/twkb-loader.d.ts.map +1 -0
  582. package/dist/wkt/twkb-loader.js +23 -0
  583. package/dist/wkt/twkb-loader.js.map +1 -0
  584. package/dist/wkt/twkb-writer.cjs +50 -0
  585. package/dist/wkt/twkb-writer.cjs.map +7 -0
  586. package/dist/wkt/twkb-writer.d.ts +32 -0
  587. package/dist/wkt/twkb-writer.d.ts.map +1 -0
  588. package/dist/wkt/twkb-writer.js +27 -0
  589. package/dist/wkt/twkb-writer.js.map +1 -0
  590. package/dist/wkt/unbundled.cjs +43 -0
  591. package/dist/wkt/unbundled.cjs.map +7 -0
  592. package/dist/wkt/unbundled.d.ts +6 -0
  593. package/dist/wkt/unbundled.d.ts.map +1 -0
  594. package/dist/wkt/unbundled.js +9 -0
  595. package/dist/wkt/unbundled.js.map +1 -0
  596. package/dist/wkt/wkb-loader-types.cjs +60 -0
  597. package/dist/wkt/wkb-loader-types.cjs.map +7 -0
  598. package/dist/wkt/wkb-loader-types.d.ts +65 -0
  599. package/dist/wkt/wkb-loader-types.d.ts.map +1 -0
  600. package/dist/wkt/wkb-loader-types.js +30 -0
  601. package/dist/wkt/wkb-loader-types.js.map +1 -0
  602. package/dist/wkt/wkb-loader.cjs +56 -0
  603. package/dist/wkt/wkb-loader.cjs.map +7 -0
  604. package/dist/wkt/wkb-loader.d.ts +66 -0
  605. package/dist/wkt/wkb-loader.d.ts.map +1 -0
  606. package/dist/wkt/wkb-loader.js +32 -0
  607. package/dist/wkt/wkb-loader.js.map +1 -0
  608. package/dist/wkt/wkb-writer.cjs +54 -0
  609. package/dist/wkt/wkb-writer.cjs.map +7 -0
  610. package/dist/wkt/wkb-writer.d.ts +37 -0
  611. package/dist/wkt/wkb-writer.d.ts.map +1 -0
  612. package/dist/wkt/wkb-writer.js +31 -0
  613. package/dist/wkt/wkb-writer.js.map +1 -0
  614. package/dist/wkt/wkt-crs-loader-types.cjs +64 -0
  615. package/dist/wkt/wkt-crs-loader-types.cjs.map +7 -0
  616. package/dist/wkt/wkt-crs-loader-types.d.ts +54 -0
  617. package/dist/wkt/wkt-crs-loader-types.d.ts.map +1 -0
  618. package/dist/wkt/wkt-crs-loader-types.js +36 -0
  619. package/dist/wkt/wkt-crs-loader-types.js.map +1 -0
  620. package/dist/wkt/wkt-crs-loader.cjs +38 -0
  621. package/dist/wkt/wkt-crs-loader.cjs.map +7 -0
  622. package/dist/wkt/wkt-crs-loader.d.ts +31 -0
  623. package/dist/wkt/wkt-crs-loader.d.ts.map +1 -0
  624. package/dist/wkt/wkt-crs-loader.js +17 -0
  625. package/dist/wkt/wkt-crs-loader.js.map +1 -0
  626. package/dist/wkt/wkt-crs-writer.cjs +52 -0
  627. package/dist/wkt/wkt-crs-writer.cjs.map +7 -0
  628. package/dist/wkt/wkt-crs-writer.d.ts +30 -0
  629. package/dist/wkt/wkt-crs-writer.d.ts.map +1 -0
  630. package/dist/wkt/wkt-crs-writer.js +31 -0
  631. package/dist/wkt/wkt-crs-writer.js.map +1 -0
  632. package/dist/wkt/wkt-format.cjs +119 -0
  633. package/dist/wkt/wkt-format.cjs.map +7 -0
  634. package/dist/wkt/wkt-format.d.ts +69 -0
  635. package/dist/wkt/wkt-format.d.ts.map +1 -0
  636. package/dist/wkt/wkt-format.js +91 -0
  637. package/dist/wkt/wkt-format.js.map +1 -0
  638. package/dist/wkt/wkt-loader-types.cjs +60 -0
  639. package/dist/wkt/wkt-loader-types.cjs.map +7 -0
  640. package/dist/wkt/wkt-loader-types.d.ts +70 -0
  641. package/dist/wkt/wkt-loader-types.d.ts.map +1 -0
  642. package/dist/wkt/wkt-loader-types.js +30 -0
  643. package/dist/wkt/wkt-loader-types.js.map +1 -0
  644. package/dist/wkt/wkt-loader.cjs +45 -0
  645. package/dist/wkt/wkt-loader.cjs.map +7 -0
  646. package/dist/wkt/wkt-loader.d.ts +68 -0
  647. package/dist/wkt/wkt-loader.d.ts.map +1 -0
  648. package/dist/wkt/wkt-loader.js +23 -0
  649. package/dist/wkt/wkt-loader.js.map +1 -0
  650. package/dist/wkt/wkt-writer.cjs +54 -0
  651. package/dist/wkt/wkt-writer.cjs.map +7 -0
  652. package/dist/wkt/wkt-writer.d.ts +31 -0
  653. package/dist/wkt/wkt-writer.d.ts.map +1 -0
  654. package/dist/wkt/wkt-writer.js +31 -0
  655. package/dist/wkt/wkt-writer.js.map +1 -0
  656. package/dist/wkt/workers/wkb-worker.cjs +7 -0
  657. package/dist/wkt/workers/wkb-worker.cjs.map +7 -0
  658. package/dist/wkt/workers/wkb-worker.d.ts +2 -0
  659. package/dist/wkt/workers/wkb-worker.d.ts.map +1 -0
  660. package/dist/wkt/workers/wkb-worker.js +7 -0
  661. package/dist/wkt/workers/wkb-worker.js.map +1 -0
  662. package/dist/wkt/workers/wkt-worker.cjs +11 -0
  663. package/dist/wkt/workers/wkt-worker.cjs.map +7 -0
  664. package/dist/wkt/workers/wkt-worker.d.ts +2 -0
  665. package/dist/wkt/workers/wkt-worker.d.ts.map +1 -0
  666. package/dist/wkt/workers/wkt-worker.js +8 -0
  667. package/dist/wkt/workers/wkt-worker.js.map +1 -0
  668. package/dist/wkt-crs-loader-types.cjs +66 -0
  669. package/dist/wkt-crs-loader-types.cjs.map +7 -0
  670. package/dist/wkt-crs-loader-types.d.ts +2 -0
  671. package/dist/wkt-crs-loader-types.d.ts.map +1 -0
  672. package/dist/wkt-crs-loader-types.js +2 -0
  673. package/dist/wkt-crs-loader-types.js.map +1 -0
  674. package/dist/wkt-crs-loader.cjs +40 -0
  675. package/dist/wkt-crs-loader.cjs.map +7 -0
  676. package/dist/wkt-crs-loader.d.ts +2 -0
  677. package/dist/wkt-crs-loader.d.ts.map +1 -0
  678. package/dist/wkt-crs-loader.js +2 -0
  679. package/dist/wkt-crs-loader.js.map +1 -0
  680. package/dist/wkt-crs-writer.cjs +54 -0
  681. package/dist/wkt-crs-writer.cjs.map +7 -0
  682. package/dist/wkt-crs-writer.d.ts +2 -0
  683. package/dist/wkt-crs-writer.d.ts.map +1 -0
  684. package/dist/wkt-crs-writer.js +2 -0
  685. package/dist/wkt-crs-writer.js.map +1 -0
  686. package/dist/wkt-loader-types.cjs +62 -0
  687. package/dist/wkt-loader-types.cjs.map +7 -0
  688. package/dist/wkt-loader-types.d.ts +2 -0
  689. package/dist/wkt-loader-types.d.ts.map +1 -0
  690. package/dist/wkt-loader-types.js +2 -0
  691. package/dist/wkt-loader-types.js.map +1 -0
  692. package/dist/wkt-loader.cjs +47 -0
  693. package/dist/wkt-loader.cjs.map +7 -0
  694. package/dist/wkt-loader.d.ts +2 -0
  695. package/dist/wkt-loader.d.ts.map +1 -0
  696. package/dist/wkt-loader.js +2 -0
  697. package/dist/wkt-loader.js.map +1 -0
  698. package/dist/wkt-worker.js +1895 -0
  699. package/dist/wkt-writer.cjs +56 -0
  700. package/dist/wkt-writer.cjs.map +7 -0
  701. package/dist/wkt-writer.d.ts +2 -0
  702. package/dist/wkt-writer.d.ts.map +1 -0
  703. package/dist/wkt-writer.js +2 -0
  704. package/dist/wkt-writer.js.map +1 -0
  705. package/dist/workers/dbf-worker.cjs +25 -0
  706. package/dist/workers/dbf-worker.cjs.map +7 -0
  707. package/dist/workers/dbf-worker.js +16 -2
  708. package/dist/workers/dbf-worker.js.map +1 -1
  709. package/dist/workers/flatgeobuf-worker.cjs +7 -0
  710. package/dist/workers/flatgeobuf-worker.cjs.map +7 -0
  711. package/dist/workers/geopackage-worker.cjs +7 -0
  712. package/dist/workers/geopackage-worker.cjs.map +7 -0
  713. package/dist/workers/shapefile-worker.cjs +71 -0
  714. package/dist/workers/shapefile-worker.cjs.map +7 -0
  715. package/dist/workers/shapefile-worker.d.ts +2 -0
  716. package/dist/workers/shapefile-worker.d.ts.map +1 -0
  717. package/dist/workers/shapefile-worker.js +61 -0
  718. package/dist/workers/shapefile-worker.js.map +1 -0
  719. package/dist/workers/shp-worker.cjs +7 -0
  720. package/dist/workers/shp-worker.cjs.map +7 -0
  721. package/dist/workers/shp-worker.js +2 -2
  722. package/dist/workers/shp-worker.js.map +1 -1
  723. package/package.json +218 -88
  724. package/src/dbf-loader-types.ts +1 -0
  725. package/src/dbf-loader.ts +1 -0
  726. package/src/flatgeobuf/flatgeobuf-loader-types.ts +18 -17
  727. package/src/flatgeobuf/flatgeobuf-loader.ts +9 -11
  728. package/src/flatgeobuf/flatgeobuf-source-loader.ts +19 -32
  729. package/src/flatgeobuf/index.ts +1 -9
  730. package/src/flatgeobuf/lib/flatgeobuf-reader.ts +2 -2
  731. package/src/flatgeobuf/lib/flatgeobuf-worker-transport.ts +12 -50
  732. package/src/flatgeobuf/lib/parse-flatgeobuf.ts +11 -11
  733. package/src/flatgeobuf/unbundled.ts +1 -1
  734. package/src/flatgeobuf-loader-types.ts +1 -0
  735. package/src/flatgeobuf-loader.ts +1 -0
  736. package/src/flatgeobuf-source-loader.ts +1 -0
  737. package/src/geopackage/geopackage-loader-types.ts +13 -8
  738. package/src/geopackage/geopackage-loader.ts +5 -2
  739. package/src/geopackage/geopackage-source-loader.ts +57 -58
  740. package/src/geopackage/index.ts +1 -1
  741. package/src/geopackage/lib/parse-geopackage.ts +15 -10
  742. package/src/geopackage-loader-types.ts +1 -0
  743. package/src/geopackage-loader.ts +1 -0
  744. package/src/geopackage-source-loader.ts +1 -0
  745. package/src/gpx-loader-types.ts +1 -0
  746. package/src/gpx-loader.ts +1 -0
  747. package/src/hex-wkb-loader-types.ts +1 -0
  748. package/src/hex-wkb-loader.ts +1 -0
  749. package/src/index.ts +4 -3
  750. package/src/kml/bundled.ts +1 -1
  751. package/src/kml/gpx-loader-types.ts +5 -3
  752. package/src/kml/gpx-loader.ts +9 -17
  753. package/src/kml/index.ts +1 -1
  754. package/src/kml/kml-loader-types.ts +7 -5
  755. package/src/kml/kml-loader.ts +8 -20
  756. package/src/kml/kml-parser.ts +3 -2
  757. package/src/kml/kmz-loader-types.ts +17 -4
  758. package/src/kml/kmz-loader.ts +7 -3
  759. package/src/kml/kmz-source.ts +12 -25
  760. package/src/kml/lib/feature-collection-to-arrow.ts +6 -12
  761. package/src/kml/sports-track-parser.ts +3 -2
  762. package/src/kml/tcx-loader-types.ts +5 -3
  763. package/src/kml/tcx-loader.ts +9 -17
  764. package/src/kml/unbundled.ts +1 -1
  765. package/src/kml-loader-types.ts +1 -0
  766. package/src/kml-loader.ts +1 -0
  767. package/src/kml-writer.ts +1 -0
  768. package/src/kmz-loader-types.ts +1 -0
  769. package/src/kmz-loader.ts +1 -0
  770. package/src/kmz-source.ts +1 -0
  771. package/src/shapefile/dbf-loader-types.ts +6 -7
  772. package/src/shapefile/dbf-loader.ts +52 -19
  773. package/src/shapefile/index.ts +0 -6
  774. package/src/shapefile/lib/parsers/build-geoarrow-geometry-arrow.ts +3 -3
  775. package/src/shapefile/lib/parsers/build-wkb-geometry-arrow.ts +3 -3
  776. package/src/shapefile/lib/parsers/parse-dbf-to-arrow.ts +21 -7
  777. package/src/shapefile/lib/parsers/parse-shapefile.ts +3 -3
  778. package/src/shapefile/lib/parsers/parse-shp-geometry.ts +1 -1
  779. package/src/shapefile/lib/parsers/parse-shp-header.ts +4 -5
  780. package/src/shapefile/lib/parsers/parse-shp-to-arrow.ts +5 -5
  781. package/src/shapefile/lib/parsers/parse-shp.ts +1 -1
  782. package/src/shapefile/lib/parsers/types.ts +3 -3
  783. package/src/shapefile/lib/shapefile-worker-transport.ts +50 -58
  784. package/src/shapefile/shapefile-arrow-loader.ts +76 -21
  785. package/src/shapefile/shapefile-loader-types.ts +15 -16
  786. package/src/shapefile/shapefile-loader.ts +106 -8
  787. package/src/shapefile/shp-loader-types.ts +7 -11
  788. package/src/shapefile/shp-loader.ts +73 -12
  789. package/src/shapefile/unbundled.ts +2 -2
  790. package/src/shapefile-arrow-loader.ts +1 -0
  791. package/src/shapefile-loader-types.ts +1 -0
  792. package/src/shapefile-loader.ts +1 -0
  793. package/src/shp-loader-types.ts +1 -0
  794. package/src/shp-loader.ts +1 -0
  795. package/src/tcx-loader-types.ts +1 -0
  796. package/src/tcx-loader.ts +1 -0
  797. package/src/twkb-loader-types.ts +1 -0
  798. package/src/twkb-loader.ts +1 -0
  799. package/src/twkb-writer.ts +1 -0
  800. package/src/twkb.ts +6 -0
  801. package/src/wkb-loader-types.ts +1 -0
  802. package/src/wkb-loader.ts +1 -0
  803. package/src/wkb-writer.ts +1 -0
  804. package/src/wkb.ts +6 -0
  805. package/src/wkt/bundled.ts +16 -0
  806. package/src/wkt/hex-wkb-loader-types.ts +60 -0
  807. package/src/wkt/hex-wkb-loader.ts +65 -0
  808. package/src/wkt/index.ts +19 -0
  809. package/src/wkt/lib/version.ts +8 -0
  810. package/src/wkt/twkb-loader-types.ts +51 -0
  811. package/src/wkt/twkb-loader.ts +35 -0
  812. package/src/wkt/twkb-writer.ts +39 -0
  813. package/src/wkt/unbundled.ts +9 -0
  814. package/src/wkt/wkb-loader-types.ts +43 -0
  815. package/src/wkt/wkb-loader.ts +51 -0
  816. package/src/wkt/wkb-writer.ts +47 -0
  817. package/src/wkt/wkt-crs-loader-types.ts +44 -0
  818. package/src/wkt/wkt-crs-loader.ts +25 -0
  819. package/src/wkt/wkt-crs-writer.ts +42 -0
  820. package/src/wkt/wkt-format.ts +101 -0
  821. package/src/wkt/wkt-loader-types.ts +47 -0
  822. package/src/wkt/wkt-loader.ts +42 -0
  823. package/src/wkt/wkt-writer.ts +39 -0
  824. package/src/wkt/workers/wkb-worker.ts +8 -0
  825. package/src/wkt/workers/wkt-worker.ts +11 -0
  826. package/src/wkt-crs-loader-types.ts +1 -0
  827. package/src/wkt-crs-loader.ts +1 -0
  828. package/src/wkt-crs-writer.ts +1 -0
  829. package/src/wkt-loader-types.ts +1 -0
  830. package/src/wkt-loader.ts +1 -0
  831. package/src/wkt-writer.ts +1 -0
  832. package/src/workers/dbf-worker.ts +21 -2
  833. package/src/workers/shapefile-worker.ts +85 -0
  834. package/src/workers/shp-worker.ts +2 -2
@@ -1,18 +1,8 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res, err) => function __init() {
9
- if (err) throw err[0];
10
- try {
11
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
- } catch (e) {
13
- throw err = [e], e;
14
- }
15
- };
16
6
  var __export = (target, all) => {
17
7
  for (var name in all)
18
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -25,4409 +15,23 @@ var __copyProps = (to, from, except, desc) => {
25
15
  }
26
16
  return to;
27
17
  };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
19
 
38
- // ../core/src/loader-utils/lib/env-utils/globals.ts
39
- var globals, self_, window_, global_, document_, isBrowser, matches, nodeVersion;
40
- var init_globals = __esm({
41
- "../core/src/loader-utils/lib/env-utils/globals.ts"() {
42
- "use strict";
43
- globals = {
44
- self: typeof self !== "undefined" && self,
45
- window: typeof window !== "undefined" && window,
46
- global: typeof global !== "undefined" && global,
47
- document: typeof document !== "undefined" && document
48
- };
49
- self_ = globals.self || globals.window || globals.global || {};
50
- window_ = globals.window || globals.self || globals.global || {};
51
- global_ = globals.global || globals.self || globals.window || {};
52
- document_ = globals.document || {};
53
- isBrowser = // @ts-ignore process does not exist on browser
54
- Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser);
55
- matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
56
- nodeVersion = matches && parseFloat(matches[1]) || 0;
57
- }
58
- });
59
-
60
- // ../core/src/loader-utils/lib/log-utils/log.ts
61
- function createLog() {
62
- const log2 = new import_log.Log({ id: "loaders.gl" });
63
- globalThis.loaders ||= {};
64
- globalThis.loaders.log = log2;
65
- globalThis.loaders.version = version;
66
- globalThis.probe ||= {};
67
- globalThis.probe.loaders = log2;
68
- return log2;
69
- }
70
- var import_log, VERSION, version, log;
71
- var init_log = __esm({
72
- "../core/src/loader-utils/lib/log-utils/log.ts"() {
73
- "use strict";
74
- import_log = require("probe.gl/log");
75
- VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
76
- version = VERSION[0] >= "0" && VERSION[0] <= "9" ? `v${VERSION}` : "";
77
- log = createLog();
78
- }
79
- });
80
-
81
- // ../core/src/loader-utils/lib/javascript-utils/is-type.ts
82
- var isObject, isPureObject;
83
- var init_is_type = __esm({
84
- "../core/src/loader-utils/lib/javascript-utils/is-type.ts"() {
85
- "use strict";
86
- isObject = (value) => value !== null && typeof value === "object";
87
- isPureObject = (value) => isObject(value) && value.constructor === {}.constructor;
88
- }
89
- });
90
-
91
- // ../core/src/loader-utils/lib/option-utils/merge-options.ts
92
- function mergeOptions(baseOptions, newOptions) {
93
- return mergeOptionsRecursively(baseOptions || {}, newOptions);
94
- }
95
- function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
96
- if (level > 3) {
97
- return newOptions;
98
- }
99
- const options = { ...baseOptions };
100
- for (const [key, newValue] of Object.entries(newOptions)) {
101
- if (isPureObject(newValue)) {
102
- options[key] = mergeOptionsRecursively(
103
- options[key] || {},
104
- newOptions[key],
105
- level + 1
106
- );
107
- } else {
108
- options[key] = newOptions[key];
109
- }
110
- }
111
- return options;
112
- }
113
- var init_merge_options = __esm({
114
- "../core/src/loader-utils/lib/option-utils/merge-options.ts"() {
115
- "use strict";
116
- init_is_type();
117
- }
118
- });
119
-
120
- // ../core/src/loader-utils/lib/request-utils/authentication.ts
121
- function resolveCredentials(credentials, authentications = []) {
122
- if (credentials.every(isAuthentication)) return credentials;
123
- return credentials.map((credential, index) => {
124
- if (isAuthentication(credential)) return credential;
125
- const AuthenticationClass = authentications.find(
126
- (authentication2) => authentication2.type === (credential == null ? void 0 : credential.type)
127
- );
128
- if (!AuthenticationClass) {
129
- throw new Error(`No authentication class registered for credential at index ${index}.`);
130
- }
131
- let authentication;
132
- try {
133
- authentication = new AuthenticationClass(credential);
134
- } catch {
135
- throw new Error(`Invalid authentication configuration at index ${index}.`);
136
- }
137
- if (!isAuthentication(authentication)) {
138
- throw new Error(`Authentication class returned an invalid credential at index ${index}.`);
139
- }
140
- return authentication;
141
- });
142
- }
143
- function resolveAuthenticationOptions(options) {
144
- var _a, _b;
145
- if (!((_b = (_a = options.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length)) return options;
146
- const credentials = resolveCredentials(options.core.credentials, options.core.authentications);
147
- if (credentials === options.core.credentials) return options;
148
- return { ...options, core: { ...options.core, credentials } };
149
- }
150
- function isAuthentication(credential) {
151
- if (!credential || typeof credential !== "object") return false;
152
- if (typeof credential.id !== "string" || !Array.isArray(credential.origins)) return false;
153
- if (credential.type === "request") return typeof credential.authenticate === "function";
154
- return (credential.type === "header" || credential.type === "query-parameter") && typeof credential.name === "string" && (typeof credential.token === "string" || typeof credential.token === "function") && Array.isArray(credential.refreshStatusCodes);
155
- }
156
- var init_authentication = __esm({
157
- "../core/src/loader-utils/lib/request-utils/authentication.ts"() {
158
- "use strict";
159
- }
160
- });
161
-
162
- // ../core/src/loader-utils/lib/request-utils/request-credentials.ts
163
- function createAuthenticatedFetch(options) {
164
- const suppliedFetch = options.fetch || ((url, requestOptions) => fetch(url, requestOptions));
165
- const existingMetadata = suppliedFetch[AUTHENTICATED_FETCH];
166
- const credentialResolutions = new Map(existingMetadata == null ? void 0 : existingMetadata.credentialResolutions);
167
- const resolvedCredentials = resolveCredentials(
168
- options.credentials.map((credential) => credentialResolutions.get(credential) || credential),
169
- options.authentications
170
- );
171
- options.credentials.forEach((credential, index) => {
172
- credentialResolutions.set(credential, resolvedCredentials[index]);
173
- });
174
- if (!options.fetchOptions && (!resolvedCredentials.length || (existingMetadata == null ? void 0 : existingMetadata.credentials.length) === resolvedCredentials.length && resolvedCredentials.every(
175
- (credential, index) => credential === existingMetadata.credentials[index]
176
- )))
177
- return suppliedFetch;
178
- const baseFetch = (existingMetadata == null ? void 0 : existingMetadata.fetch) || suppliedFetch;
179
- const credentials = existingMetadata ? [.../* @__PURE__ */ new Set([...resolvedCredentials, ...existingMetadata.credentials])] : resolvedCredentials;
180
- const fetchOptions = mergeFetchOptions(
181
- (existingMetadata == null ? void 0 : existingMetadata.fetchOptions) || {},
182
- options.fetchOptions
183
- );
184
- const tokenCredentials = credentials.filter(
185
- (credential) => credential.type !== "request"
186
- );
187
- const requestCredentials = credentials.filter(
188
- (credential) => credential.type === "request"
189
- );
190
- for (const credential of requestCredentials) normalizeRequestOrigins(credential.origins);
191
- const authenticatedFetch = async (url, requestOptions = {}) => {
192
- var _a, _b, _c, _d, _e, _f, _g;
193
- requestOptions = mergeFetchOptions(fetchOptions, requestOptions);
194
- (_a = requestOptions.signal) == null ? void 0 : _a.throwIfAborted();
195
- if (!credentials.length) return baseFetch(url, requestOptions);
196
- const resolvedURL = parseHTTPURL(url);
197
- const authorization = resolvedURL ? await authorizeRequest(resolvedURL, requestOptions, tokenCredentials) : { url, options: requestOptions, credentials: [] };
198
- const signedRequest = await authenticateRequest(authorization, requestCredentials, "request");
199
- const response = await baseFetch(signedRequest.url, signedRequest.options);
200
- const refreshableCredentials = [];
201
- for (const resolvedCredential of authorization.credentials) {
202
- const { credential } = resolvedCredential;
203
- if (typeof credential.token === "function" && (isReplayableRequest(requestOptions) || ((_b = credential.canReplayRequest) == null ? void 0 : _b.call(credential, url, requestOptions))) && (isReplayableRequest(signedRequest.options) || ((_c = credential.canReplayRequest) == null ? void 0 : _c.call(credential, signedRequest.url, signedRequest.options))) && (credential.refreshStatusCodes.includes(response.status) || await ((_d = credential.shouldRefresh) == null ? void 0 : _d.call(credential, response))))
204
- refreshableCredentials.push(resolvedCredential);
205
- }
206
- const shouldRetrySignature = isReplayableRequest(requestOptions) && isReplayableRequest(signedRequest.options) && signedRequest.credentials.some(
207
- (credential) => {
208
- var _a2;
209
- return (_a2 = credential.refreshStatusCodes) == null ? void 0 : _a2.includes(response.status);
210
- }
211
- );
212
- if (!refreshableCredentials.length && !shouldRetrySignature) return response;
213
- (_e = requestOptions.signal) == null ? void 0 : _e.throwIfAborted();
214
- const refreshedTokens = /* @__PURE__ */ new Map();
215
- await Promise.all(
216
- refreshableCredentials.map(async ({ credential }) => {
217
- const token = await refreshCredential(credential, url, response);
218
- if (token) refreshedTokens.set(credential, token);
219
- })
220
- );
221
- if (!refreshedTokens.size && !shouldRetrySignature) return response;
222
- await ((_f = response.body) == null ? void 0 : _f.cancel().catch(() => {
223
- }));
224
- (_g = requestOptions.signal) == null ? void 0 : _g.throwIfAborted();
225
- const replayAuthorization = resolvedURL ? await authorizeRequest(
226
- resolvedURL,
227
- requestOptions,
228
- tokenCredentials,
229
- refreshedTokens,
230
- authorization.credentials
231
- ) : { url, options: requestOptions };
232
- const replayRequest = await authenticateRequest(
233
- replayAuthorization,
234
- requestCredentials,
235
- "retry",
236
- response
237
- );
238
- return baseFetch(replayRequest.url, replayRequest.options);
239
- };
240
- Object.defineProperty(authenticatedFetch, AUTHENTICATED_FETCH, {
241
- value: {
242
- fetch: baseFetch,
243
- credentials,
244
- credentialResolutions,
245
- fetchOptions
246
- }
247
- });
248
- return authenticatedFetch;
249
- }
250
- function getAuthenticatedFetch(options = {}) {
251
- var _a, _b, _c;
252
- const fetchOption = options.fetch ?? ((_a = options.core) == null ? void 0 : _a.fetch);
253
- let fetchFunction;
254
- if (typeof fetchOption === "function") {
255
- fetchFunction = fetchOption;
256
- } else {
257
- fetchFunction = (url, requestOptions) => fetch(url, requestOptions);
258
- }
259
- const fetchOptions = typeof fetchOption === "object" && fetchOption ? fetchOption : void 0;
260
- return createAuthenticatedFetch({
261
- fetch: fetchFunction,
262
- fetchOptions: options.signal ? { ...fetchOptions, signal: options.signal } : fetchOptions,
263
- credentials: ((_b = options.core) == null ? void 0 : _b.credentials) || [],
264
- authentications: (_c = options.core) == null ? void 0 : _c.authentications
265
- });
266
- }
267
- function mergeFetchOptions(defaultOptions, requestOptions) {
268
- const mergedOptions = { ...defaultOptions, ...requestOptions };
269
- if (defaultOptions.headers || (requestOptions == null ? void 0 : requestOptions.headers)) {
270
- const headers = new Headers(defaultOptions.headers);
271
- new Headers(requestOptions == null ? void 0 : requestOptions.headers).forEach((value, key) => headers.set(key, value));
272
- mergedOptions.headers = headers;
273
- }
274
- return mergedOptions;
275
- }
276
- async function authenticateRequest(request, credentials, reason, response) {
277
- const appliedCredentials = [];
278
- const signal = request.options.signal;
279
- for (const credential of credentials) {
280
- const origin = getRequestOrigin(request.url);
281
- if (!origin || !normalizeRequestOrigins(credential.origins).includes(origin)) continue;
282
- signal == null ? void 0 : signal.throwIfAborted();
283
- const authenticatedRequest = await credential.authenticate({
284
- url: request.url,
285
- options: { ...request.options, headers: new Headers(request.options.headers) },
286
- reason,
287
- response: response ? { status: response.status, headers: new Headers(response.headers) } : void 0
288
- });
289
- if (!authenticatedRequest || typeof authenticatedRequest.url !== "string" || !authenticatedRequest.options || typeof authenticatedRequest.options !== "object") {
290
- throw new Error("Authentication callback returned an invalid request.");
291
- }
292
- request = {
293
- url: authenticatedRequest.url,
294
- options: { ...authenticatedRequest.options, ...signal ? { signal } : {} }
295
- };
296
- appliedCredentials.push(credential);
297
- }
298
- signal == null ? void 0 : signal.throwIfAborted();
299
- return { ...request, credentials: appliedCredentials };
300
- }
301
- function getRequestOrigin(url) {
302
- try {
303
- const parsedURL = new URL(url);
304
- if (!parsedURL.host || parsedURL.username || parsedURL.password) return null;
305
- return parsedURL.origin !== "null" ? parsedURL.origin : `${parsedURL.protocol}//${parsedURL.host}`;
306
- } catch {
307
- return null;
308
- }
309
- }
310
- function normalizeRequestOrigins(origins) {
311
- if (!origins.length)
312
- throw new Error("Request authentication requires at least one exact origin.");
313
- return origins.map((origin) => {
314
- const resolvedOrigin = getRequestOrigin(origin);
315
- let url;
316
- try {
317
- url = new URL(origin);
318
- } catch {
319
- throw new Error("Invalid request authentication origin.");
320
- }
321
- if (!resolvedOrigin || url.pathname && url.pathname !== "/" || url.search || url.hash) {
322
- throw new Error("Invalid request authentication origin.");
323
- }
324
- return resolvedOrigin;
325
- });
326
- }
327
- async function authorizeRequest(sourceURL, requestOptions, credentials, tokenOverrides = /* @__PURE__ */ new Map(), previousCredentials = []) {
328
- const url = new URL(sourceURL);
329
- const headers = new Headers(requestOptions.headers);
330
- const resolvedCredentials = [];
331
- const previousTokens = new Map(
332
- previousCredentials.map(({ credential, token }) => [credential, token])
333
- );
334
- for (const credential of credentials) {
335
- if (!credential.origins.includes(url.origin)) continue;
336
- const overrideToken = tokenOverrides.get(credential);
337
- const previousToken = previousTokens.get(credential);
338
- const ownsQueryParameter = credential.type === "query-parameter" && previousToken !== void 0;
339
- const ownsHeader = credential.type === "header" && previousToken !== void 0;
340
- if (credential.type === "query-parameter" && url.searchParams.has(credential.name) && !ownsQueryParameter || credential.type === "header" && headers.has(credential.name) && !ownsHeader) {
341
- continue;
342
- }
343
- const token = overrideToken ?? previousToken ?? await resolveToken(credential.token, { url: sourceURL.toString(), reason: "request" });
344
- if (!token) continue;
345
- if (credential.type === "query-parameter") {
346
- url.searchParams.set(credential.name, token);
347
- } else {
348
- headers.set(credential.name, `${credential.prefix || ""}${token}`);
349
- }
350
- resolvedCredentials.push({ credential, token });
351
- }
352
- return {
353
- url: url.toString(),
354
- options: { ...requestOptions, headers },
355
- credentials: resolvedCredentials
356
- };
357
- }
358
- async function refreshCredential(credential, url, response) {
359
- const existingPromise = refreshPromises.get(credential);
360
- if (existingPromise) return existingPromise;
361
- const tokenProvider = credential.token;
362
- const promise = Promise.resolve(
363
- tokenProvider({
364
- url,
365
- reason: "refresh",
366
- response: { status: response.status, headers: response.headers }
367
- })
368
- ).finally(() => refreshPromises.delete(credential));
369
- refreshPromises.set(credential, promise);
370
- return promise;
371
- }
372
- async function resolveToken(token, context) {
373
- return typeof token === "function" ? token(context) : token;
374
- }
375
- function parseHTTPURL(url) {
376
- try {
377
- const parsedURL = new URL(url);
378
- return ["http:", "https:"].includes(parsedURL.protocol) ? parsedURL : null;
379
- } catch {
380
- return null;
381
- }
382
- }
383
- function isReplayableRequest(options) {
384
- const method = (options.method || "GET").toUpperCase();
385
- if (!["GET", "HEAD", "OPTIONS", "PUT", "DELETE"].includes(method)) return false;
386
- return !(options.body && typeof ReadableStream !== "undefined" && options.body instanceof ReadableStream);
387
- }
388
- var AUTHENTICATED_FETCH, refreshPromises;
389
- var init_request_credentials = __esm({
390
- "../core/src/loader-utils/lib/request-utils/request-credentials.ts"() {
391
- "use strict";
392
- init_authentication();
393
- AUTHENTICATED_FETCH = /* @__PURE__ */ Symbol("loaders.gl.authenticated-fetch");
394
- refreshPromises = /* @__PURE__ */ new WeakMap();
395
- }
396
- });
397
-
398
- // ../core/src/loader-utils/lib/path-utils/file-aliases.ts
399
- function resolvePath(filename) {
400
- for (const alias in fileAliases) {
401
- if (filename.startsWith(alias)) {
402
- const replacement = fileAliases[alias];
403
- filename = filename.replace(alias, replacement);
404
- }
405
- }
406
- if (!filename.startsWith("http://") && !filename.startsWith("https://")) {
407
- filename = `${pathPrefix}${filename}`;
408
- }
409
- return filename;
410
- }
411
- var pathPrefix, fileAliases;
412
- var init_file_aliases = __esm({
413
- "../core/src/loader-utils/lib/path-utils/file-aliases.ts"() {
414
- "use strict";
415
- pathPrefix = "";
416
- fileAliases = {};
417
- }
418
- });
419
-
420
- // ../core/src/loader-utils/lib/sources/data-source.ts
421
- function getFetchFunction(options) {
422
- return getAuthenticatedFetch(options);
423
- }
424
- function getSourceLoaderOptions(options) {
425
- var _a;
426
- if (options.loadOptions !== void 0 || ((_a = options.core) == null ? void 0 : _a.loadOptions) !== void 0) {
427
- throw new Error(
428
- "Source loadOptions and core.loadOptions were removed. Use core and root loader namespaces directly."
429
- );
430
- }
431
- const loadOptions = { ...options };
432
- if (options == null ? void 0 : options.core) {
433
- loadOptions.core = { ...options.core };
434
- const parserCore = loadOptions.core;
435
- for (const key of ["type", "attributions", "loaders", "onError", "loadOptions"]) {
436
- delete parserCore[key];
437
- }
438
- if (Object.keys(parserCore).length === 0) {
439
- delete loadOptions.core;
440
- }
441
- }
442
- const topLevelBaseUri = typeof loadOptions.baseUri === "string" ? loadOptions.baseUri : void 0;
443
- const topLevelBaseUrl = typeof loadOptions.baseUrl === "string" ? loadOptions.baseUrl : void 0;
444
- if (topLevelBaseUri !== void 0 || topLevelBaseUrl !== void 0) {
445
- loadOptions.core ||= {};
446
- if (loadOptions.core.baseUrl === void 0) {
447
- loadOptions.core.baseUrl = topLevelBaseUrl ?? topLevelBaseUri;
448
- }
449
- delete loadOptions.baseUri;
450
- delete loadOptions.baseUrl;
451
- }
452
- return loadOptions;
453
- }
454
- function normalizeError(error, message) {
455
- if (error instanceof Error) {
456
- return error;
457
- }
458
- if (typeof error === "string") {
459
- return new Error(error);
460
- }
461
- return new Error(message);
462
- }
463
- function unavailableCoreApiMethod(methodName) {
464
- return () => {
465
- throw new Error(
466
- `CoreAPI.${methodName} is unavailable. Use @loaders.gl/core.createDataSource().`
467
- );
468
- };
469
- }
470
- var UNAVAILABLE_CORE_API, DataSource;
471
- var init_data_source = __esm({
472
- "../core/src/loader-utils/lib/sources/data-source.ts"() {
473
- "use strict";
474
- init_merge_options();
475
- init_file_aliases();
476
- init_log();
477
- init_request_credentials();
478
- init_authentication();
479
- UNAVAILABLE_CORE_API = {
480
- fetchFile: unavailableCoreApiMethod("fetchFile"),
481
- parse: unavailableCoreApiMethod("parse"),
482
- parseFile: unavailableCoreApiMethod("parseFile"),
483
- parseSync: unavailableCoreApiMethod("parseSync"),
484
- parseInBatches: unavailableCoreApiMethod("parseInBatches"),
485
- load: unavailableCoreApiMethod("load"),
486
- loadInBatches: unavailableCoreApiMethod("loadInBatches")
487
- };
488
- DataSource = class _DataSource {
489
- static defaultOptions = {
490
- core: {
491
- type: "auto",
492
- attributions: [],
493
- loaders: [],
494
- onError: void 0
495
- }
496
- };
497
- optionsType;
498
- options;
499
- data;
500
- url;
501
- /** Shared parser options derived from the source options, excluding source-only core controls. */
502
- loadOptions;
503
- /** A resolved fetch function extracted from the shared core options. */
504
- fetch;
505
- /** Shared source-level runtime hooks, when supplied by the source factory. */
506
- coreApi;
507
- /** Whether a real CoreAPI instance was injected by the integration layer. */
508
- hasCoreApi;
509
- _needsRefresh = true;
510
- constructor(data, options, defaultOptions, coreApi) {
511
- this.options = mergeOptions(
512
- mergeOptions(_DataSource.defaultOptions, defaultOptions || {}),
513
- options
514
- );
515
- this.data = data;
516
- this.url = typeof data === "string" ? resolvePath(data) : "";
517
- const loadOptions = resolveAuthenticationOptions(getSourceLoaderOptions(this.options));
518
- this.loadOptions = loadOptions;
519
- const fetch2 = getFetchFunction(loadOptions);
520
- this.coreApi = coreApi || UNAVAILABLE_CORE_API;
521
- this.hasCoreApi = Boolean(coreApi);
522
- this.fetch = fetch2;
523
- }
524
- setProps(options) {
525
- const mergedOptions = mergeOptions(this.options, options);
526
- const loadOptions = resolveAuthenticationOptions(getSourceLoaderOptions(mergedOptions));
527
- this.options = mergedOptions;
528
- this.loadOptions = loadOptions;
529
- this.fetch = getFetchFunction(loadOptions);
530
- this.setNeedsRefresh();
531
- }
532
- /** Mark this data source as needing a refresh (redraw) */
533
- setNeedsRefresh() {
534
- this._needsRefresh = true;
535
- }
536
- /**
537
- * Does this data source need refreshing?
538
- * @note The specifics of the refresh mechanism depends on type of data source
539
- */
540
- getNeedsRefresh(clear = true) {
541
- const needsRefresh = this._needsRefresh;
542
- if (clear) {
543
- this._needsRefresh = false;
544
- }
545
- return needsRefresh;
546
- }
547
- /** Reports a source-level failure through the configured callback or the shared logger. */
548
- reportError(error, message) {
549
- var _a;
550
- const normalizedError = normalizeError(error, message);
551
- const callback = (_a = this.options.core) == null ? void 0 : _a.onError;
552
- if (callback) {
553
- callback(normalizedError, this);
554
- } else {
555
- log.warn(`${this.constructor.name}: ${normalizedError.message}`)();
556
- }
557
- return normalizedError;
558
- }
559
- };
560
- }
561
- });
562
-
563
- // ../core/src/loader-utils/lib/scan-utils/columnar-predicate.ts
564
- function getColumnarPredicatePath(property) {
565
- return typeof property.property === "string" ? [property.property] : [...property.property];
566
- }
567
- function validateColumnarPredicate(predicate, availableColumns) {
568
- visitColumnarPredicate(predicate, (child) => {
569
- if (child.op === "and" || child.op === "or") {
570
- if (child.args.length < 2)
571
- throw new Error(`Columnar predicate ${child.op} requires at least two child predicates`);
572
- return;
573
- }
574
- if (child.op === "not") return;
575
- const leaf = child;
576
- const path = getColumnarPredicatePath(leaf.args[0]);
577
- if (!path.length || path.some((component) => !component)) {
578
- throw new Error("Columnar predicate property path must contain non-empty strings");
579
- }
580
- if (!availableColumns.has(path[0]))
581
- throw new Error(`Columnar predicate column not found: ${path.join(".")}`);
582
- if (leaf.op === "in" && leaf.args[1].length === 0) {
583
- throw new Error("Columnar predicate in requires at least one value");
584
- }
585
- });
586
- }
587
- function filterColumnarRowIndices(predicate, columns, rowCount) {
588
- if (!predicate) return Array.from({ length: rowCount }, (_, index) => index);
589
- const result = [];
590
- for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
591
- if (evaluateColumnarPredicate(predicate, columns, rowIndex) === true) result.push(rowIndex);
592
- }
593
- return result;
594
- }
595
- function evaluateColumnarPredicate(predicate, columns, rowIndex) {
596
- if (predicate.op === "and" || predicate.op === "or") {
597
- const results = predicate.args.map(
598
- (child) => evaluateColumnarPredicate(child, columns, rowIndex)
599
- );
600
- return predicate.op === "and" ? results.includes(false) ? false : results.includes(null) ? null : true : results.includes(true) ? true : results.includes(null) ? null : false;
601
- }
602
- if (predicate.op === "not") {
603
- const value2 = evaluateColumnarPredicate(predicate.args[0], columns, rowIndex);
604
- return value2 === null ? null : !value2;
605
- }
606
- const leaf = predicate;
607
- const value = getColumnarValue(columns, getColumnarPredicatePath(leaf.args[0]), rowIndex);
608
- if (leaf.op === "isNull") return value === null || value === void 0;
609
- if (value === null || value === void 0) return null;
610
- if (leaf.op === "in")
611
- return leaf.args[1].some((candidate) => compareColumnarValues(value, candidate) === 0);
612
- const comparison = compareColumnarValues(value, leaf.args[1]);
613
- return leaf.op === "=" ? comparison === 0 : leaf.op === "<>" ? comparison !== 0 : leaf.op === "<" ? comparison < 0 : leaf.op === "<=" ? comparison <= 0 : leaf.op === ">" ? comparison > 0 : comparison >= 0;
614
- }
615
- function visitColumnarPredicate(predicate, visitor) {
616
- visitor(predicate);
617
- if (predicate.op === "and" || predicate.op === "or")
618
- predicate.args.forEach((child) => visitColumnarPredicate(child, visitor));
619
- else if (predicate.op === "not") visitColumnarPredicate(predicate.args[0], visitor);
620
- }
621
- function getColumnarValue(columns, path, rowIndex) {
622
- var _a;
623
- let value = (_a = columns[path[0]]) == null ? void 0 : _a[rowIndex];
624
- for (let index = 1; index < path.length && value != null; index++) value = value[path[index]];
625
- return value;
626
- }
627
- function compareColumnarValues(left, right) {
628
- if (left instanceof Uint8Array && right instanceof Uint8Array) return compareBytes(left, right);
629
- if (left instanceof Uint8Array || right instanceof Uint8Array)
630
- throw new Error("Columnar binary predicates require binary values on both sides");
631
- if (left instanceof Date || right instanceof Date) {
632
- if (!(left instanceof Date) || !(right instanceof Date))
633
- throw new Error("Columnar date predicates require date values on both sides");
634
- return compareNumbers(left.getTime(), right.getTime());
635
- }
636
- const leftType = typeof left;
637
- const rightType = typeof right;
638
- const numeric = (leftType === "number" || leftType === "bigint") && (rightType === "number" || rightType === "bigint");
639
- if (!numeric && leftType !== rightType)
640
- throw new Error(`Columnar predicate cannot compare ${leftType} with ${rightType}`);
641
- if (!numeric && leftType !== "string" && leftType !== "boolean")
642
- throw new Error(`Columnar predicate does not support ${leftType} values`);
643
- return left < right ? -1 : left > right ? 1 : 0;
644
- }
645
- function compareNumbers(left, right) {
646
- if (!Number.isFinite(left) || !Number.isFinite(right))
647
- throw new Error("Non-finite values cannot be ordered by a columnar predicate");
648
- return left < right ? -1 : left > right ? 1 : 0;
649
- }
650
- function compareBytes(left, right) {
651
- const length = Math.min(left.length, right.length);
652
- for (let index = 0; index < length; index++)
653
- if (left[index] !== right[index]) return left[index] < right[index] ? -1 : 1;
654
- return left.length - right.length;
655
- }
656
- var init_columnar_predicate = __esm({
657
- "../core/src/loader-utils/lib/scan-utils/columnar-predicate.ts"() {
658
- "use strict";
659
- }
660
- });
661
-
662
- // ../core/src/loader-utils/lib/scan-utils/scan-query-metadata.ts
663
- function createScanQueryMetadata(options) {
664
- validateScanExecutionSupport(options.queryType, options.execution);
665
- const schema = Object.freeze({
666
- fields: Object.freeze(
667
- options.schema.fields.map(
668
- (field) => Object.freeze({ ...field, metadata: Object.freeze({ ...field.metadata }) })
669
- )
670
- ),
671
- metadata: Object.freeze({ ...options.schema.metadata })
672
- });
673
- const columns = schema.fields.map(
674
- (field) => {
675
- var _a;
676
- return Object.freeze({
677
- name: field.name,
678
- type: field.type,
679
- nullable: field.nullable !== false,
680
- role: ((_a = options.columnRoles) == null ? void 0 : _a[field.name]) || "attribute",
681
- title: getNonEmptyMetadataValue(field.metadata, "title"),
682
- description: getNonEmptyMetadataValue(field.metadata, "description"),
683
- metadata: field.metadata || Object.freeze({})
684
- });
685
- }
686
- );
687
- return Object.freeze({
688
- sourceType: options.sourceType,
689
- queryType: options.queryType,
690
- execution: Object.freeze({ ...options.execution }),
691
- name: options.name,
692
- description: options.description,
693
- schema,
694
- columns: Object.freeze(columns),
695
- capabilities: Object.freeze({ ...options.capabilities }),
696
- spatial: options.spatial ? Object.freeze({
697
- ...options.spatial,
698
- bounds: options.spatial.bounds ? Object.freeze({
699
- minimum: Object.freeze([...options.spatial.bounds.minimum]),
700
- maximum: Object.freeze([...options.spatial.bounds.maximum])
701
- }) : void 0,
702
- coordinateReferenceSystems: options.spatial.coordinateReferenceSystems ? Object.freeze([...options.spatial.coordinateReferenceSystems]) : void 0,
703
- spatialReference: options.spatial.spatialReference ? (0, import_crs.createSpatialReference)(options.spatial.spatialReference) : void 0
704
- }) : void 0,
705
- statistics: options.statistics ? Object.freeze({ ...options.statistics }) : void 0,
706
- levels: options.levels ? Object.freeze(
707
- options.levels.map(
708
- (level) => Object.freeze({
709
- ...level,
710
- scale: level.scale ? Object.freeze([...level.scale]) : void 0
711
- })
712
- )
713
- ) : void 0
714
- });
715
- }
716
- function validateScanExecutionSupport(queryType, execution) {
717
- if (execution.status === "metadata-only") {
718
- if (!execution.reason.trim()) {
719
- throw new Error("Metadata-only scan support requires a concrete reason");
720
- }
721
- return;
722
- }
723
- const validMethods = {
724
- table: ["read", "query"],
725
- raster: ["getRaster"],
726
- "point-cloud": ["scan"]
727
- };
728
- if (!validMethods[queryType].includes(execution.method)) {
729
- throw new Error(
730
- `Scan execution method "${execution.method}" is not valid for ${queryType} queries`
731
- );
732
- }
733
- }
734
- function getNonEmptyMetadataValue(metadata, key) {
735
- const value = metadata == null ? void 0 : metadata[key];
736
- return value || void 0;
737
- }
738
- var import_crs;
739
- var init_scan_query_metadata = __esm({
740
- "../core/src/loader-utils/lib/scan-utils/scan-query-metadata.ts"() {
741
- "use strict";
742
- import_crs = require("@math.gl/geospatial/crs");
743
- }
744
- });
745
-
746
- // ../core/src/loader-utils/lib/scan-utils/table-query.ts
747
- function validateTableQueryOptions(sourceColumnNames, options) {
748
- const availableColumnNames = new Set(sourceColumnNames);
749
- const outputColumnNames = options.columns ?? sourceColumnNames;
750
- const seenColumnNames = /* @__PURE__ */ new Set();
751
- for (const columnName of outputColumnNames) {
752
- if (!availableColumnNames.has(columnName)) {
753
- throw new Error(`Table query column not found: ${columnName}`);
754
- }
755
- if (seenColumnNames.has(columnName)) {
756
- throw new Error(`Table query column was selected more than once: ${columnName}`);
757
- }
758
- seenColumnNames.add(columnName);
759
- }
760
- validateTableQueryLimit(options.limit);
761
- if (options.predicate) {
762
- validateColumnarPredicate(options.predicate, availableColumnNames);
763
- }
764
- }
765
- function validateTableQueryLimit(limit) {
766
- if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 0)) {
767
- throw new Error("Table query limit must be a non-negative safe integer.");
768
- }
769
- }
770
- var init_table_query = __esm({
771
- "../core/src/loader-utils/lib/scan-utils/table-query.ts"() {
772
- "use strict";
773
- init_columnar_predicate();
774
- }
775
- });
776
-
777
- // ../core/src/loader-utils/lib/scan-utils/table-scan-batch.ts
778
- function makeTableScanBatch(table) {
779
- return { ...table, batchType: "data", length: table.data.numRows };
780
- }
781
- var init_table_scan_batch = __esm({
782
- "../core/src/loader-utils/lib/scan-utils/table-scan-batch.ts"() {
783
- "use strict";
784
- }
785
- });
786
-
787
- // ../core/src/loader-utils/lib/crs/crs-reprojection.ts
788
- var CRSReprojectionError;
789
- var init_crs_reprojection = __esm({
790
- "../core/src/loader-utils/lib/crs/crs-reprojection.ts"() {
791
- "use strict";
792
- CRSReprojectionError = class extends Error {
793
- /** Machine-readable reason for the failed transformation request. */
794
- code;
795
- /** Source CRS when it was discovered or supplied. */
796
- sourceCrs;
797
- /** Requested output CRS when it was supplied. */
798
- targetCrs;
799
- constructor(code, message, options = {}) {
800
- super(message, { cause: options.cause });
801
- this.name = "CRSReprojectionError";
802
- this.code = code;
803
- this.sourceCrs = options.sourceCrs;
804
- this.targetCrs = options.targetCrs;
805
- }
806
- };
807
- }
808
- });
809
-
810
- // ../core/src/loader-utils/lib/sources/tile-grid.ts
811
- function createTileGrid(crs, matrices) {
812
- var _a, _b, _c;
813
- const tileMatrixSet = getTileMatrixSet(crs, matrices);
814
- if (tileMatrixSet) {
815
- const levels = tileMatrixSet.matrices;
816
- return {
817
- crs,
818
- tileSize: [levels[0].tileSize[0], levels[0].tileSize[1]],
819
- // The grid-wide origin is documented as top-left, so a bottom-left origin is per-level only.
820
- origin: levels[0].cornerOfOrigin === "topLeft" ? [levels[0].origin[0], levels[0].origin[1]] : void 0,
821
- resolutions: levels.map((matrix) => matrix.resolution),
822
- matrixIds: levels.map((matrix) => matrix.id),
823
- matrixSizes: levels.map((matrix) => [matrix.matrixSize[0], matrix.matrixSize[1]]),
824
- tileMatrixSet,
825
- matrices
826
- };
827
- }
828
- return {
829
- crs,
830
- tileSize: (_a = matrices[0]) == null ? void 0 : _a.tileSize,
831
- // The grid-wide origin is documented as top-left, so a bottom-left origin is per-level only.
832
- origin: ((_b = matrices[0]) == null ? void 0 : _b.cornerOfOrigin) === "bottomLeft" ? void 0 : (_c = matrices[0]) == null ? void 0 : _c.origin,
833
- ...matrices.length && matrices.every((matrix) => matrix.resolution !== void 0) ? { resolutions: matrices.map((matrix) => matrix.resolution) } : {},
834
- matrixIds: matrices.map((matrix) => matrix.id),
835
- matrixSizes: matrices.every((matrix) => matrix.matrixSize) ? matrices.map((matrix) => matrix.matrixSize) : void 0,
836
- matrices
837
- };
838
- }
839
- function getTileMatrixSet(crs, matrices) {
840
- if (!crs || !matrices.length) return void 0;
841
- const tileMatrices = [];
842
- for (const matrix of matrices) {
843
- const tileMatrix = toTileMatrix(matrix);
844
- if (!tileMatrix) return void 0;
845
- tileMatrices.push(tileMatrix);
846
- }
847
- return { crs, matrices: tileMatrices };
848
- }
849
- function toTileMatrix(matrix) {
850
- const { id, resolution, resolutionY, origin, tileSize, matrixSize } = matrix;
851
- if (resolution === void 0 || !origin || !tileSize || !matrixSize) return null;
852
- const tileMatrix = {
853
- id,
854
- resolution,
855
- ...resolutionY !== void 0 ? { resolutionY } : {},
856
- origin: [origin[0], origin[1]],
857
- cornerOfOrigin: matrix.cornerOfOrigin ?? "topLeft",
858
- tileSize: [tileSize[0], tileSize[1]],
859
- matrixSize: [matrixSize[0], matrixSize[1]]
860
- };
861
- try {
862
- (0, import_geospatial.validateTileMatrix)(tileMatrix);
863
- } catch {
864
- return null;
865
- }
866
- return tileMatrix;
867
- }
868
- function createTileGridMatrix(fields) {
869
- const { point, tileWidth, tileHeight } = fields;
870
- const tileGridMatrix = { id: fields.id };
871
- if (fields.resolution !== void 0) tileGridMatrix.resolution = fields.resolution;
872
- if (fields.resolutionY !== void 0) tileGridMatrix.resolutionY = fields.resolutionY;
873
- if (point && point.length >= 2) {
874
- tileGridMatrix.origin = fields.swapAxes ? [point[1], point[0]] : [point[0], point[1]];
875
- }
876
- if (String(fields.cornerOfOrigin).toLowerCase() === "bottomleft") {
877
- tileGridMatrix.cornerOfOrigin = "bottomLeft";
878
- }
879
- if (tileWidth !== void 0 && tileHeight !== void 0) {
880
- tileGridMatrix.tileSize = [tileWidth, tileHeight];
881
- }
882
- if (fields.matrixWidth !== void 0 && fields.matrixHeight !== void 0) {
883
- tileGridMatrix.matrixSize = [fields.matrixWidth, fields.matrixHeight];
884
- }
885
- return tileGridMatrix;
886
- }
887
- function getRequestedTileMatrix(matrices, getId, parameters) {
888
- if (parameters.tileMatrix !== void 0) {
889
- const matrix = matrices.find((candidate) => getId(candidate) === parameters.tileMatrix);
890
- if (!matrix) throw new RangeError(`Unknown tile matrix "${parameters.tileMatrix}"`);
891
- return matrix;
892
- }
893
- return matrices.find((matrix) => getId(matrix) === String(parameters.z)) || matrices[parameters.z];
894
- }
895
- var import_geospatial;
896
- var init_tile_grid = __esm({
897
- "../core/src/loader-utils/lib/sources/tile-grid.ts"() {
898
- "use strict";
899
- import_geospatial = require("@math.gl/geospatial");
900
- }
901
- });
902
-
903
- // ../core/src/loader-utils/index.ts
904
- var init_loader_utils = __esm({
905
- "../core/src/loader-utils/index.ts"() {
906
- "use strict";
907
- init_globals();
908
- init_data_source();
909
- init_columnar_predicate();
910
- init_table_scan_batch();
911
- init_scan_query_metadata();
912
- init_table_query();
913
- init_crs_reprojection();
914
- init_tile_grid();
915
- }
916
- });
917
-
918
- // ../core/src/schema-utils/lib/schema/convert-arrow-schema.ts
919
- function convertArrowToSchema(arrowSchema) {
920
- return serializeArrowSchema(arrowSchema);
921
- }
922
- function convertSchemaToArrow(schema, options) {
923
- return deserializeArrowSchema(schema, options);
924
- }
925
- function serializeArrowSchema(arrowSchema) {
926
- return {
927
- fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
928
- metadata: serializeArrowMetadata(arrowSchema.metadata)
929
- };
930
- }
931
- function deserializeArrowSchema(schema, options) {
932
- return new arrow.Schema(
933
- schema.fields.map((field) => deserializeArrowField(field, options)),
934
- deserializeArrowMetadata(schema.metadata)
935
- );
936
- }
937
- function serializeArrowMetadata(arrowMetadata) {
938
- return Object.fromEntries(arrowMetadata);
939
- }
940
- function deserializeArrowMetadata(metadata) {
941
- return metadata ? new Map(Object.entries(metadata)) : /* @__PURE__ */ new Map();
942
- }
943
- function serializeArrowField(field) {
944
- return {
945
- name: field.name,
946
- type: serializeArrowType(field.type),
947
- nullable: field.nullable,
948
- metadata: serializeArrowMetadata(field.metadata)
949
- };
950
- }
951
- function deserializeArrowField(field, options) {
952
- return new arrow.Field(
953
- field.name,
954
- deserializeArrowType(field.type, options),
955
- field.nullable,
956
- deserializeArrowMetadata(field.metadata)
957
- );
958
- }
959
- function serializeArrowType(arrowType) {
960
- if (isArrowViewType(arrowType, "BinaryView")) {
961
- return "binary-view";
962
- }
963
- if (isArrowViewType(arrowType, "Utf8View")) {
964
- return "utf8-view";
965
- }
966
- if (isOptionalArrowType(arrowType, "LargeList")) {
967
- const largeListType = arrowType;
968
- return {
969
- type: "large-list",
970
- children: [serializeArrowField(largeListType.valueField)]
971
- };
972
- }
973
- switch (arrowType.constructor) {
974
- case arrow.Null:
975
- return "null";
976
- case arrow.Binary:
977
- return "binary";
978
- case arrow.FixedSizeBinary:
979
- return {
980
- type: "fixed-size-binary",
981
- byteWidth: arrowType.byteWidth
982
- };
983
- case arrow.Bool:
984
- return "bool";
985
- case arrow.Int:
986
- const intType = arrowType;
987
- return `${intType.isSigned ? "" : "u"}int${intType.bitWidth}`;
988
- case arrow.Int8:
989
- return "int8";
990
- case arrow.Int16:
991
- return "int16";
992
- case arrow.Int32:
993
- return "int32";
994
- case arrow.Int64:
995
- return "int64";
996
- case arrow.Uint8:
997
- return "uint8";
998
- case arrow.Uint16:
999
- return "uint16";
1000
- case arrow.Uint32:
1001
- return "uint32";
1002
- case arrow.Uint64:
1003
- return "uint64";
1004
- case arrow.Float:
1005
- const precision = arrowType.precision;
1006
- switch (precision) {
1007
- case arrow.Precision.HALF:
1008
- return "float16";
1009
- case arrow.Precision.SINGLE:
1010
- return "float32";
1011
- case arrow.Precision.DOUBLE:
1012
- return "float64";
1013
- default:
1014
- return "float16";
1015
- }
1016
- case arrow.Float16:
1017
- return "float16";
1018
- case arrow.Float32:
1019
- return "float32";
1020
- case arrow.Float64:
1021
- return "float64";
1022
- case arrow.Utf8:
1023
- return "utf8";
1024
- case arrow.Decimal:
1025
- const decimal = arrowType;
1026
- return {
1027
- type: "decimal",
1028
- bitWidth: decimal.bitWidth,
1029
- precision: decimal.precision,
1030
- scale: decimal.scale
1031
- };
1032
- case arrow.Date_:
1033
- const dateUnit = arrowType.unit;
1034
- return dateUnit === arrow.DateUnit.DAY ? "date-day" : "date-millisecond";
1035
- case arrow.DateDay:
1036
- return "date-day";
1037
- case arrow.DateMillisecond:
1038
- return "date-millisecond";
1039
- case arrow.Time:
1040
- const timeUnit = arrowType.unit;
1041
- switch (timeUnit) {
1042
- case arrow.TimeUnit.SECOND:
1043
- return "time-second";
1044
- case arrow.TimeUnit.MILLISECOND:
1045
- return "time-millisecond";
1046
- case arrow.TimeUnit.MICROSECOND:
1047
- return "time-microsecond";
1048
- case arrow.TimeUnit.NANOSECOND:
1049
- return "time-nanosecond";
1050
- default:
1051
- return "time-second";
1052
- }
1053
- case arrow.TimeMillisecond:
1054
- return "time-millisecond";
1055
- case arrow.TimeSecond:
1056
- return "time-second";
1057
- case arrow.TimeMicrosecond:
1058
- return "time-microsecond";
1059
- case arrow.TimeNanosecond:
1060
- return "time-nanosecond";
1061
- case arrow.Timestamp:
1062
- const timeStampUnit = arrowType.unit;
1063
- switch (timeStampUnit) {
1064
- case arrow.TimeUnit.SECOND:
1065
- return "timestamp-second";
1066
- case arrow.TimeUnit.MILLISECOND:
1067
- return "timestamp-millisecond";
1068
- case arrow.TimeUnit.MICROSECOND:
1069
- return "timestamp-microsecond";
1070
- case arrow.TimeUnit.NANOSECOND:
1071
- return "timestamp-nanosecond";
1072
- default:
1073
- return "timestamp-second";
1074
- }
1075
- case arrow.TimestampSecond:
1076
- return "timestamp-second";
1077
- case arrow.TimestampMillisecond:
1078
- return "timestamp-millisecond";
1079
- case arrow.TimestampMicrosecond:
1080
- return "timestamp-microsecond";
1081
- case arrow.TimestampNanosecond:
1082
- return "timestamp-nanosecond";
1083
- case arrow.Interval:
1084
- const intervalUnit = arrowType.unit;
1085
- switch (intervalUnit) {
1086
- case arrow.IntervalUnit.DAY_TIME:
1087
- return "interval-daytime";
1088
- case arrow.IntervalUnit.YEAR_MONTH:
1089
- return "interval-yearmonth";
1090
- default:
1091
- return "interval-daytime";
1092
- }
1093
- case arrow.IntervalDayTime:
1094
- return "interval-daytime";
1095
- case arrow.IntervalYearMonth:
1096
- return "interval-yearmonth";
1097
- case arrow.Map_:
1098
- const mapType = arrowType;
1099
- return {
1100
- type: "map",
1101
- keysSorted: mapType.keysSorted,
1102
- children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
1103
- };
1104
- case arrow.List:
1105
- const listType = arrowType;
1106
- const listField = listType.valueField;
1107
- return {
1108
- type: "list",
1109
- children: [serializeArrowField(listField)]
1110
- };
1111
- case arrow.FixedSizeList:
1112
- const fixedSizeList = arrowType;
1113
- return {
1114
- type: "fixed-size-list",
1115
- listSize: fixedSizeList.listSize,
1116
- children: [serializeArrowField(fixedSizeList.children[0])]
1117
- };
1118
- case arrow.Struct:
1119
- const structType = arrowType;
1120
- return {
1121
- type: "struct",
1122
- children: structType.children.map((arrowField) => serializeArrowField(arrowField))
1123
- };
1124
- case arrow.SparseUnion:
1125
- case arrow.DenseUnion:
1126
- const unionType = arrowType;
1127
- return {
1128
- type: unionType instanceof arrow.DenseUnion ? "dense-union" : "sparse-union",
1129
- typeIds: unionType.typeIds,
1130
- children: unionType.children.map((arrowField) => serializeArrowField(arrowField)),
1131
- typeIdToChildIndex: { ...unionType.typeIdToChildIndex }
1132
- };
1133
- case arrow.Dictionary:
1134
- const dictionaryType = arrowType;
1135
- return {
1136
- type: "dictionary",
1137
- id: dictionaryType.id,
1138
- indices: serializeArrowDictionaryKeyType(dictionaryType.indices),
1139
- dictionary: serializeArrowType(dictionaryType.dictionary),
1140
- isOrdered: dictionaryType.isOrdered
1141
- };
1142
- default:
1143
- throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
1144
- }
1145
- }
1146
- function deserializeArrowType(dataType, options) {
1147
- if (typeof dataType === "object") {
1148
- switch (dataType.type) {
1149
- case "decimal":
1150
- return new arrow.Decimal(dataType.scale, dataType.precision, dataType.bitWidth);
1151
- case "map": {
1152
- const children = dataType.children.map(
1153
- (arrowField) => deserializeArrowField(arrowField, options)
1154
- );
1155
- return new arrow.Map_(children[0], dataType.keysSorted);
1156
- }
1157
- case "list": {
1158
- const field = deserializeArrowField(dataType.children[0], options);
1159
- return new arrow.List(field);
1160
- }
1161
- case "large-list": {
1162
- const field = deserializeArrowField(dataType.children[0], options);
1163
- const LargeList = getOptionalArrowConstructor("LargeList");
1164
- if (!LargeList) {
1165
- throw new Error(
1166
- "LargeList requires an Apache Arrow runtime that exports the LargeList constructor"
1167
- );
1168
- }
1169
- return new LargeList(field);
1170
- }
1171
- case "fixed-size-list": {
1172
- const child = deserializeArrowField(dataType.children[0], options);
1173
- return new arrow.FixedSizeList(dataType.listSize, child);
1174
- }
1175
- case "fixed-size-binary":
1176
- return new arrow.FixedSizeBinary(dataType.byteWidth);
1177
- case "struct": {
1178
- const children = dataType.children.map(
1179
- (arrowField) => deserializeArrowField(arrowField, options)
1180
- );
1181
- return new arrow.Struct(children);
1182
- }
1183
- case "sparse-union":
1184
- case "dense-union": {
1185
- const children = dataType.children.map(
1186
- (arrowField) => deserializeArrowField(arrowField, options)
1187
- );
1188
- return dataType.type === "dense-union" ? new arrow.DenseUnion(dataType.typeIds, children) : new arrow.SparseUnion(dataType.typeIds, children);
1189
- }
1190
- case "dictionary": {
1191
- return new arrow.Dictionary(
1192
- deserializeArrowType(dataType.dictionary, options),
1193
- deserializeArrowDictionaryKeyType(dataType.indices),
1194
- dataType.id,
1195
- dataType.isOrdered
1196
- );
1197
- }
1198
- default:
1199
- throw new Error("array type not supported");
1200
- }
1201
- }
1202
- switch (dataType) {
1203
- case "null":
1204
- return new arrow.Null();
1205
- case "binary":
1206
- return makeVariableWidthArrowType("BinaryView", new arrow.Binary(), options);
1207
- case "binary-view":
1208
- return makeRequiredArrowViewType("BinaryView");
1209
- case "bool":
1210
- return new arrow.Bool();
1211
- case "int8":
1212
- return new arrow.Int8();
1213
- case "int16":
1214
- return new arrow.Int16();
1215
- case "int32":
1216
- return new arrow.Int32();
1217
- case "int64":
1218
- return new arrow.Int64();
1219
- case "uint8":
1220
- return new arrow.Uint8();
1221
- case "uint16":
1222
- return new arrow.Uint16();
1223
- case "uint32":
1224
- return new arrow.Uint32();
1225
- case "uint64":
1226
- return new arrow.Uint64();
1227
- case "float16":
1228
- return new arrow.Float16();
1229
- case "float32":
1230
- return new arrow.Float32();
1231
- case "float64":
1232
- return new arrow.Float64();
1233
- case "utf8":
1234
- return makeVariableWidthArrowType("Utf8View", new arrow.Utf8(), options);
1235
- case "utf8-view":
1236
- return makeRequiredArrowViewType("Utf8View");
1237
- case "date-day":
1238
- return new arrow.DateDay();
1239
- case "date-millisecond":
1240
- return new arrow.DateMillisecond();
1241
- case "time-second":
1242
- return new arrow.TimeSecond();
1243
- case "time-millisecond":
1244
- return new arrow.TimeMillisecond();
1245
- case "time-microsecond":
1246
- return new arrow.TimeMicrosecond();
1247
- case "time-nanosecond":
1248
- return new arrow.TimeNanosecond();
1249
- case "timestamp-second":
1250
- return new arrow.TimestampSecond();
1251
- case "timestamp-millisecond":
1252
- return new arrow.TimestampMillisecond();
1253
- case "timestamp-microsecond":
1254
- return new arrow.TimestampMicrosecond();
1255
- case "timestamp-nanosecond":
1256
- return new arrow.TimestampNanosecond();
1257
- case "interval-daytime":
1258
- return new arrow.IntervalDayTime();
1259
- case "interval-yearmonth":
1260
- return new arrow.IntervalYearMonth();
1261
- default:
1262
- throw new Error("array type not supported");
1263
- }
1264
- }
1265
- function getOptionalArrowConstructor(typeName) {
1266
- return arrow[typeName];
1267
- }
1268
- function isArrowViewType(arrowType, viewTypeName) {
1269
- const constructor = getOptionalArrowConstructor(viewTypeName);
1270
- if (constructor && arrowType instanceof constructor) {
1271
- return true;
1272
- }
1273
- const guards = arrow.DataType;
1274
- const guard = viewTypeName === "BinaryView" ? guards.isBinaryView : guards.isUtf8View;
1275
- return Boolean(guard == null ? void 0 : guard(arrowType));
1276
- }
1277
- function isOptionalArrowType(arrowType, typeName) {
1278
- const constructor = getOptionalArrowConstructor(typeName);
1279
- return Boolean(constructor && arrowType instanceof constructor);
1280
- }
1281
- function makeVariableWidthArrowType(viewTypeName, fallbackType, options) {
1282
- const viewTypeMode = (options == null ? void 0 : options.viewTypes) || "never";
1283
- if (viewTypeMode === "never") {
1284
- return fallbackType;
1285
- }
1286
- const constructor = getOptionalArrowConstructor(viewTypeName);
1287
- if (constructor) {
1288
- return new constructor();
1289
- }
1290
- if (viewTypeMode === "require") {
1291
- throw new Error(
1292
- `${viewTypeName} requires apache-arrow 21.2.0 or later; the installed runtime does not support it`
1293
- );
1294
- }
1295
- return fallbackType;
1296
- }
1297
- function makeRequiredArrowViewType(viewTypeName) {
1298
- const constructor = getOptionalArrowConstructor(viewTypeName);
1299
- if (!constructor) {
1300
- throw new Error(
1301
- `${viewTypeName} requires apache-arrow 21.2.0 or later; the installed runtime does not support it`
1302
- );
1303
- }
1304
- return new constructor();
1305
- }
1306
- function serializeArrowDictionaryKeyType(arrowType) {
1307
- if (arrowType instanceof arrow.Int) {
1308
- const prefix = arrowType.isSigned ? "int" : "uint";
1309
- const keyType = `${prefix}${arrowType.bitWidth}`;
1310
- if (isSchemaDictionaryKeyType(keyType)) {
1311
- return keyType;
1312
- }
1313
- }
1314
- switch (arrowType.constructor) {
1315
- case arrow.Int8:
1316
- return "int8";
1317
- case arrow.Int16:
1318
- return "int16";
1319
- case arrow.Int32:
1320
- return "int32";
1321
- case arrow.Uint8:
1322
- return "uint8";
1323
- case arrow.Uint16:
1324
- return "uint16";
1325
- case arrow.Uint32:
1326
- return "uint32";
1327
- default:
1328
- throw new Error(`arrow dictionary index type not supported: ${arrowType.constructor.name}`);
1329
- }
1330
- }
1331
- function isSchemaDictionaryKeyType(keyType) {
1332
- return ["int8", "int16", "int32", "uint8", "uint16", "uint32"].includes(keyType);
1333
- }
1334
- function deserializeArrowDictionaryKeyType(keyType) {
1335
- switch (keyType) {
1336
- case "int8":
1337
- return new arrow.Int8();
1338
- case "int16":
1339
- return new arrow.Int16();
1340
- case "int32":
1341
- return new arrow.Int32();
1342
- case "uint8":
1343
- return new arrow.Uint8();
1344
- case "uint16":
1345
- return new arrow.Uint16();
1346
- case "uint32":
1347
- return new arrow.Uint32();
1348
- default:
1349
- throw new Error(`schema dictionary index type not supported: ${keyType}`);
1350
- }
1351
- }
1352
- var arrow;
1353
- var init_convert_arrow_schema = __esm({
1354
- "../core/src/schema-utils/lib/schema/convert-arrow-schema.ts"() {
1355
- "use strict";
1356
- arrow = __toESM(require("apache-arrow"), 1);
1357
- }
1358
- });
1359
-
1360
- // ../core/src/schema-utils/lib/table/query-arrow-table.ts
1361
- function queryArrowTable(table, options = {}, filterRows) {
1362
- const availableColumns = table.data.schema.fields.map((field) => field.name);
1363
- const selectedColumns = options.columns ? [...options.columns] : availableColumns;
1364
- for (const columnName of selectedColumns) {
1365
- if (!availableColumns.includes(columnName)) {
1366
- throw new Error(`Arrow table query could not read column "${columnName}".`);
1367
- }
1368
- }
1369
- let rowIndices;
1370
- if (options.predicate !== void 0) {
1371
- if (!filterRows) throw new Error("Arrow table query requires a predicate evaluator.");
1372
- const columns = Object.fromEntries(
1373
- availableColumns.map((name) => [name, [...table.data.getChild(name) || []]])
1374
- );
1375
- rowIndices = filterRows(options.predicate, columns, table.data.numRows);
1376
- }
1377
- const limitedRowIndices = rowIndices ? rowIndices.slice(0, options.limit ?? Number.POSITIVE_INFINITY) : void 0;
1378
- const data = limitedRowIndices ? createArrowTableFromRowIndices(table.data, selectedColumns, limitedRowIndices) : table.data.select(selectedColumns).slice(0, options.limit ?? Number.POSITIVE_INFINITY);
1379
- const schema = table.schema ? {
1380
- ...table.schema,
1381
- fields: selectedColumns.flatMap(
1382
- (columnName) => {
1383
- var _a;
1384
- return ((_a = table.schema) == null ? void 0 : _a.fields.filter((field) => field.name === columnName)) || [];
1385
- }
1386
- )
1387
- } : void 0;
1388
- return schema ? { shape: "arrow-table", schema, data } : { shape: "arrow-table", data };
1389
- }
1390
- function createArrowTableFromRowIndices(sourceData, selectedColumns, rowIndices) {
1391
- const schema = new arrow2.Schema(
1392
- selectedColumns.map(
1393
- (columnName) => sourceData.schema.fields.find((field) => field.name === columnName)
1394
- )
1395
- );
1396
- const vectors = Object.fromEntries(
1397
- selectedColumns.map((columnName) => {
1398
- const sourceVector = sourceData.getChild(columnName);
1399
- return [
1400
- columnName,
1401
- arrow2.vectorFromArray(
1402
- rowIndices.map((rowIndex) => sourceVector == null ? void 0 : sourceVector.get(rowIndex)),
1403
- sourceVector == null ? void 0 : sourceVector.type
1404
- )
1405
- ];
1406
- })
1407
- );
1408
- const children = selectedColumns.map((columnName) => vectors[columnName].data[0]);
1409
- const data = new arrow2.Data(
1410
- new arrow2.Struct(schema.fields),
1411
- 0,
1412
- rowIndices.length,
1413
- 0,
1414
- void 0,
1415
- children
1416
- );
1417
- return new arrow2.Table(schema, new arrow2.RecordBatch(schema, data));
1418
- }
1419
- var arrow2;
1420
- var init_query_arrow_table = __esm({
1421
- "../core/src/schema-utils/lib/table/query-arrow-table.ts"() {
1422
- "use strict";
1423
- arrow2 = __toESM(require("apache-arrow"), 1);
1424
- }
1425
- });
1426
-
1427
- // ../core/src/schema/metadata.ts
1428
- function getMetadataValue(metadata, key) {
1429
- return metadata instanceof Map ? metadata.get(key) || null : metadata[key] || null;
1430
- }
1431
- function setMetadataValue(metadata, key, value) {
1432
- if (metadata instanceof Map) {
1433
- metadata.set(key, value);
1434
- } else {
1435
- metadata[key] = value;
1436
- }
1437
- }
1438
- function getGeoMetadata(metadata) {
1439
- if (!metadata) {
1440
- return null;
1441
- }
1442
- const stringifiedGeoMetadata = getMetadataValue(metadata, "geo");
1443
- const geoMetadata = stringifiedGeoMetadata && parseJSONStringMetadata(stringifiedGeoMetadata);
1444
- if (!geoMetadata) {
1445
- return null;
1446
- }
1447
- for (const column of Object.values(geoMetadata.columns || {})) {
1448
- if (column && typeof column === "object" && typeof column.encoding === "string") {
1449
- column.encoding = column.encoding.toLowerCase();
1450
- }
1451
- }
1452
- return geoMetadata;
1453
- }
1454
- function setGeoMetadata(metadata, geoMetadata) {
1455
- setMetadataValue(metadata, "geo", JSON.stringify(geoMetadata));
1456
- }
1457
- function parseJSONStringMetadata(stringifiedMetadata) {
1458
- if (!stringifiedMetadata) {
1459
- return null;
1460
- }
1461
- try {
1462
- const metadata = JSON.parse(stringifiedMetadata);
1463
- return metadata && typeof metadata === "object" ? metadata : null;
1464
- } catch {
1465
- return null;
1466
- }
1467
- }
1468
- var init_metadata = __esm({
1469
- "../core/src/schema/metadata.ts"() {
1470
- "use strict";
1471
- }
1472
- });
1473
-
1474
- // ../core/src/schema/index.ts
1475
- var init_schema = __esm({
1476
- "../core/src/schema/index.ts"() {
1477
- "use strict";
1478
- init_metadata();
1479
- }
1480
- });
1481
-
1482
- // ../core/src/schema-utils/lib/table/batch-builder/arrow-table-builder.ts
1483
- var arrow3, ArrowTableBuilder;
1484
- var init_arrow_table_builder = __esm({
1485
- "../core/src/schema-utils/lib/table/batch-builder/arrow-table-builder.ts"() {
1486
- "use strict";
1487
- arrow3 = __toESM(require("apache-arrow"), 1);
1488
- init_convert_arrow_schema();
1489
- ArrowTableBuilder = class {
1490
- schema;
1491
- arrowSchema;
1492
- arrowBuilders;
1493
- length;
1494
- constructor(schema, options) {
1495
- this.arrowSchema = convertSchemaToArrow(schema, options);
1496
- this.schema = (options == null ? void 0 : options.viewTypes) && options.viewTypes !== "never" ? convertArrowToSchema(this.arrowSchema) : schema;
1497
- this.arrowBuilders = this.arrowSchema.fields.map(
1498
- (field) => arrow3.makeBuilder({ type: field.type, nullValues: [null] })
1499
- );
1500
- this.length = 0;
1501
- }
1502
- addObjectRow(row) {
1503
- for (let i = 0; i < this.arrowBuilders.length; i++) {
1504
- const columnName = this.schema.fields[i].name;
1505
- const value = row[columnName];
1506
- this.arrowBuilders[i].append(value);
1507
- }
1508
- this.length++;
1509
- }
1510
- addArrayRow(row) {
1511
- for (let i = 0; i < this.arrowBuilders.length; i++) {
1512
- this.arrowBuilders[i].append(row[i]);
1513
- }
1514
- this.length++;
1515
- }
1516
- /** Makes sure that a first batch with schema is sent even if no rows */
1517
- firstBatch() {
1518
- const arrowRecordBatch = this._getArrowRecordBatch();
1519
- if (arrowRecordBatch.numCols !== 0) {
1520
- return null;
1521
- }
1522
- return {
1523
- shape: "arrow-table",
1524
- batchType: "data",
1525
- length: arrowRecordBatch.numRows,
1526
- schema: this.schema,
1527
- data: new arrow3.Table(arrowRecordBatch)
1528
- };
1529
- }
1530
- /** Flush the current batch if conditions are right */
1531
- flushBatch() {
1532
- const arrowRecordBatch = this._getArrowRecordBatch();
1533
- if (arrowRecordBatch.numCols === 0) {
1534
- return null;
1535
- }
1536
- return {
1537
- shape: "arrow-table",
1538
- batchType: "data",
1539
- length: arrowRecordBatch.numRows,
1540
- schema: this.schema,
1541
- data: new arrow3.Table(arrowRecordBatch)
1542
- };
1543
- }
1544
- /** Get a last batch if any data is left */
1545
- finishBatch() {
1546
- const arrowRecordBatch = this._getArrowRecordBatch();
1547
- this.arrowBuilders.forEach((builder) => builder.finish());
1548
- if (arrowRecordBatch.numCols === 0 && arrowRecordBatch.numRows === 0) {
1549
- return null;
1550
- }
1551
- return {
1552
- shape: "arrow-table",
1553
- batchType: "data",
1554
- length: arrowRecordBatch.numRows,
1555
- schema: this.schema,
1556
- data: new arrow3.Table(arrowRecordBatch)
1557
- };
1558
- }
1559
- /** Return a table with all the accumulated data */
1560
- finishTable() {
1561
- const arrowRecordBatch = this._getArrowRecordBatch();
1562
- this.arrowBuilders.forEach((builder) => builder.finish());
1563
- return {
1564
- shape: "arrow-table",
1565
- schema: this.schema,
1566
- data: new arrow3.Table(arrowRecordBatch)
1567
- };
1568
- }
1569
- /** Extract a record batch flushing the currently accumulated data in the builders */
1570
- _getArrowRecordBatch() {
1571
- var _a;
1572
- const { arrowBuilders, arrowSchema } = this;
1573
- const arrowDatas = arrowBuilders.map((builder) => builder.flush());
1574
- const length = ((_a = arrowDatas[0]) == null ? void 0 : _a.length) || this.length;
1575
- this.length = 0;
1576
- const structField = new arrow3.Struct(arrowSchema.fields);
1577
- const arrowStructData = new arrow3.Data(structField, 0, length, 0, void 0, arrowDatas);
1578
- const arrowRecordBatch = new arrow3.RecordBatch(arrowSchema, arrowStructData);
1579
- return arrowRecordBatch;
1580
- }
1581
- };
1582
- }
1583
- });
1584
-
1585
- // ../core/src/schema-utils/index.ts
1586
- var init_schema_utils = __esm({
1587
- "../core/src/schema-utils/index.ts"() {
1588
- "use strict";
1589
- init_convert_arrow_schema();
1590
- init_query_arrow_table();
1591
- init_arrow_table_builder();
1592
- }
1593
- });
1594
-
1595
- // ../arrow-geometry/src/geometry-utils.ts
1596
- function normalizeEmptyPoints(geometry) {
1597
- if (geometry.type === "Point") {
1598
- return geometry.coordinates.length > 0 && geometry.coordinates.every(Number.isNaN) ? { ...geometry, coordinates: [] } : geometry;
1599
- }
1600
- if (geometry.type === "MultiPoint") {
1601
- const coordinates = geometry.coordinates.map(
1602
- (coordinate) => coordinate.length > 0 && coordinate.every(Number.isNaN) ? [] : coordinate
1603
- );
1604
- return coordinates.some((coordinate, index) => coordinate !== geometry.coordinates[index]) ? { ...geometry, coordinates } : geometry;
1605
- }
1606
- if (geometry.type === "GeometryCollection") {
1607
- const geometries = geometry.geometries.map(normalizeEmptyPoints);
1608
- return geometries.some((child, index) => child !== geometry.geometries[index]) ? { ...geometry, geometries } : geometry;
1609
- }
1610
- return geometry;
1611
- }
1612
- var init_geometry_utils = __esm({
1613
- "../arrow-geometry/src/geometry-utils.ts"() {
1614
- "use strict";
1615
- }
1616
- });
1617
-
1618
- // ../arrow-geometry/src/geometry-to-wkt.ts
1619
- function convertGeometryToWKT(geometry, options) {
1620
- const dimension = getWKTDimension(geometry, options);
1621
- if (geometry.type === "GeometryCollection" && !(options == null ? void 0 : options.dimension) && !(options == null ? void 0 : options.hasZ) && !(options == null ? void 0 : options.hasM) && (hasMixedChildDimensions(geometry) || hasDeclaredChildDimensions(geometry))) {
1622
- if (geometry.geometries.length === 0) return "GEOMETRYCOLLECTION EMPTY";
1623
- return `GEOMETRYCOLLECTION (${geometry.geometries.map((child) => convertGeometryToWKT(child)).join(", ")})`;
1624
- }
1625
- return (0, import_wkb.formatWKT)(normalizeGeometryDimension(geometry, dimension), dimension);
1626
- }
1627
- function normalizeGeometryDimension(geometry, dimension) {
1628
- if (geometry.type === "GeometryCollection") {
1629
- return {
1630
- type: "GeometryCollection",
1631
- geometries: geometry.geometries.map((child) => normalizeGeometryDimension(child, dimension))
1632
- };
1633
- }
1634
- return {
1635
- ...geometry,
1636
- coordinates: normalizeCoordinateNesting(geometry.coordinates, getDimensionSize(dimension))
1637
- };
1638
- }
1639
- function normalizeCoordinateNesting(value, dimensionSize) {
1640
- if (value.length === 0) return value;
1641
- if (typeof value[0] === "number") {
1642
- const coordinate = value.slice(0, dimensionSize);
1643
- while (coordinate.length < dimensionSize) coordinate.push(0);
1644
- return coordinate;
1645
- }
1646
- return value.map((child) => normalizeCoordinateNesting(child, dimensionSize));
1647
- }
1648
- function hasMixedChildDimensions(geometry) {
1649
- const dimensions = geometry.geometries.map((child) => getCoordinateDimension(child));
1650
- return dimensions.some((dimension) => dimension !== dimensions[0]);
1651
- }
1652
- function hasDeclaredChildDimensions(geometry) {
1653
- return geometry.geometries.some(
1654
- (child) => Boolean(child.__geoarrowDimension)
1655
- );
1656
- }
1657
- function getCoordinateDimension(geometry) {
1658
- const declaredDimension = geometry.__geoarrowDimension;
1659
- if (declaredDimension) return declaredDimension;
1660
- if (geometry.type === "GeometryCollection") {
1661
- const childDimensions = geometry.geometries.map(getCoordinateDimension);
1662
- return childDimensions.length > 0 && childDimensions.every((dimension) => dimension === childDimensions[0]) ? childDimensions[0] : "xy";
1663
- }
1664
- const coordinate = getFirstCoordinate(geometry);
1665
- return coordinate && coordinate.length >= 4 ? "xyzm" : coordinate && coordinate.length >= 3 ? "xyz" : "xy";
1666
- }
1667
- function getWKTDimension(geometry, options) {
1668
- if (options == null ? void 0 : options.dimension) return options.dimension;
1669
- if ((options == null ? void 0 : options.hasZ) && (options == null ? void 0 : options.hasM)) return "xyzm";
1670
- if (options == null ? void 0 : options.hasZ) return "xyz";
1671
- if (options == null ? void 0 : options.hasM) return "xym";
1672
- return getCoordinateDimension(geometry);
1673
- }
1674
- function getFirstCoordinate(geometry) {
1675
- if (geometry.type === "Point") return geometry.coordinates;
1676
- if (geometry.type === "GeometryCollection") return null;
1677
- let value = geometry.coordinates;
1678
- while (Array.isArray(value) && Array.isArray(value[0])) value = value[0];
1679
- return Array.isArray(value) ? value : null;
1680
- }
1681
- function getDimensionSize(dimension) {
1682
- return dimension === "xy" ? 2 : dimension === "xyzm" ? 4 : 3;
1683
- }
1684
- var import_wkb;
1685
- var init_geometry_to_wkt = __esm({
1686
- "../arrow-geometry/src/geometry-to-wkt.ts"() {
1687
- "use strict";
1688
- import_wkb = require("@math.gl/geospatial/wkb");
1689
- }
1690
- });
1691
-
1692
- // ../arrow-geometry/src/geometry-codecs.ts
1693
- function convertWKBToGeometry(input) {
1694
- const bytes = ArrayBuffer.isView(input) ? new Uint8Array(input.buffer, input.byteOffset, input.byteLength) : new Uint8Array(input);
1695
- return normalizeEmptyPoints((0, import_wkb2.parseWKB)(bytes).geometry);
1696
- }
1697
- function convertGeometryToWKB(input, options = {}) {
1698
- const geometry = input.type === "Feature" ? input.geometry : input;
1699
- if (!geometry) throw new Error("WKB writer does not support null feature geometry");
1700
- const dimension = options.hasZ ? options.hasM ? "xyzm" : "xyz" : options.hasM ? "xym" : "xy";
1701
- const bytes = encodeGeometry(geometry, dimension);
1702
- return bytes.buffer;
1703
- }
1704
- function encodeGeometry(geometry, dimension) {
1705
- if (geometry.type !== "GeometryCollection") {
1706
- return (0, import_wkb2.writeWKB)(geometry, dimension);
1707
- }
1708
- const children = geometry.geometries.map(
1709
- (child) => encodeGeometry(
1710
- child,
1711
- child.__geoarrowDimension ?? dimension
1712
- )
1713
- );
1714
- const headerBuilder = new import_wkb2.WKBBuilder({ mode: "measure", dimension });
1715
- headerBuilder.beginGeometry("GeometryCollection", children.length);
1716
- const headerLength = headerBuilder.finishGeometry();
1717
- const bytes = new Uint8Array(
1718
- headerLength + children.reduce((total, child) => total + child.length, 0)
1719
- );
1720
- const writer = new import_wkb2.WKBBuilder({ mode: "write", target: bytes, dimension });
1721
- writer.beginGeometry("GeometryCollection", children.length);
1722
- let byteOffset = writer.finishGeometry();
1723
- for (const child of children) {
1724
- bytes.set(child, byteOffset);
1725
- byteOffset += child.length;
1726
- }
1727
- return bytes;
1728
- }
1729
- var import_wkb2;
1730
- var init_geometry_codecs = __esm({
1731
- "../arrow-geometry/src/geometry-codecs.ts"() {
1732
- "use strict";
1733
- import_wkb2 = require("@math.gl/geospatial/wkb");
1734
- init_geometry_utils();
1735
- init_geometry_to_wkt();
1736
- }
1737
- });
1738
-
1739
- // ../arrow-geometry/src/geometry-field.ts
1740
- function makeWKBGeometryField(geometryColumnName = "geometry", nullable = true) {
1741
- return {
1742
- name: geometryColumnName,
1743
- type: "binary",
1744
- nullable,
1745
- metadata: {
1746
- "ARROW:extension:name": "geoarrow.wkb"
1747
- }
1748
- };
1749
- }
1750
- function setWKBGeometryColumnMetadata(metadata, options = {}) {
1751
- const geometryColumnName = options.geometryColumnName || "geometry";
1752
- const primaryColumnName = options.primaryColumnName || geometryColumnName;
1753
- const geometryTypes = options.geometryTypes || [];
1754
- const nextGeoMetadata = getGeoMetadata(metadata) || { columns: {} };
1755
- nextGeoMetadata.version = options.version || nextGeoMetadata.version || DEFAULT_GEO_METADATA_VERSION;
1756
- nextGeoMetadata.primary_column = primaryColumnName;
1757
- nextGeoMetadata.columns ||= {};
1758
- nextGeoMetadata.columns[geometryColumnName] = {
1759
- ...nextGeoMetadata.columns[geometryColumnName],
1760
- ...options.columnMetadata,
1761
- encoding: "wkb",
1762
- geometry_types: geometryTypes
1763
- };
1764
- setGeoMetadata(metadata, nextGeoMetadata);
1765
- }
1766
- function setWKBGeometrySchemaMetadata(schema, options = {}) {
1767
- schema.metadata ||= {};
1768
- setWKBGeometryColumnMetadata(schema.metadata, options);
1769
- return schema;
1770
- }
1771
- function encodeWKBGeometryValue(value) {
1772
- if (value === null || value === void 0) {
1773
- return null;
1774
- }
1775
- if (isGeometry(value)) {
1776
- return new Uint8Array(convertGeometryToWKB(value, getGeometryWKBOptions(value)));
1777
- }
1778
- if (value instanceof ArrayBuffer) {
1779
- return new Uint8Array(value.slice(0));
1780
- }
1781
- if (ArrayBuffer.isView(value)) {
1782
- return new Uint8Array(
1783
- value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength)
1784
- );
1785
- }
1786
- throw new Error("Expected a Geometry, ArrayBuffer, ArrayBufferView, or null for WKB encoding.");
1787
- }
1788
- function getGeometryWKBOptions(geometry) {
1789
- const dimension = getGeometryDimension(geometry);
1790
- return {
1791
- hasZ: dimension === "xyz" || dimension === "xyzm",
1792
- hasM: dimension === "xym" || dimension === "xyzm"
1793
- };
1794
- }
1795
- function getGeometryDimension(geometry) {
1796
- const declaredDimension = geometry.__geoarrowDimension;
1797
- if (declaredDimension) return declaredDimension;
1798
- if ("geometries" in geometry) {
1799
- let hasZ = false;
1800
- let hasM = false;
1801
- for (const child of geometry.geometries) {
1802
- const childDimension = getGeometryDimension(child);
1803
- hasZ ||= childDimension === "xyz" || childDimension === "xyzm";
1804
- hasM ||= childDimension === "xym" || childDimension === "xyzm";
1805
- }
1806
- return hasZ && hasM ? "xyzm" : hasZ ? "xyz" : hasM ? "xym" : "xy";
1807
- }
1808
- const dimensions = getCoordinateDimensions(getGeometrySampleCoordinates(geometry));
1809
- return dimensions > 3 ? "xyzm" : dimensions > 2 ? "xyz" : "xy";
1810
- }
1811
- function inferGeoParquetGeometryTypes(geometries) {
1812
- const geometryTypes = /* @__PURE__ */ new Set();
1813
- for (const geometry of geometries) {
1814
- if (!geometry) {
1815
- continue;
1816
- }
1817
- const dimension = getGeometryDimension(geometry);
1818
- geometryTypes.add(`${geometry.type}${getDimensionSuffix(dimension)}`);
1819
- }
1820
- return [...geometryTypes];
1821
- }
1822
- function getDimensionSuffix(dimension) {
1823
- return dimension === "xy" ? "" : ` ${dimension === "xyzm" ? "ZM" : dimension.slice(2).toUpperCase()}`;
1824
- }
1825
- function getCoordinateDimensions(coordinates) {
1826
- if (!Array.isArray(coordinates)) {
1827
- return 2;
1828
- }
1829
- if (typeof coordinates[0] === "number") {
1830
- return coordinates.length;
1831
- }
1832
- if (coordinates.length === 0) {
1833
- return 2;
1834
- }
1835
- return getCoordinateDimensions(coordinates[0]);
1836
- }
1837
- function getGeometrySampleCoordinates(geometry) {
1838
- if ("coordinates" in geometry) {
1839
- return geometry.coordinates;
1840
- }
1841
- if ("geometries" in geometry && geometry.geometries.length > 0) {
1842
- return getGeometrySampleCoordinates(geometry.geometries[0]);
1843
- }
1844
- return void 0;
1845
- }
1846
- function isGeometry(value) {
1847
- if (!value || typeof value !== "object") {
1848
- return false;
1849
- }
1850
- return "type" in value && ("coordinates" in value || "geometries" in value);
1851
- }
1852
- var DEFAULT_GEO_METADATA_VERSION;
1853
- var init_geometry_field = __esm({
1854
- "../arrow-geometry/src/geometry-field.ts"() {
1855
- "use strict";
1856
- init_geometry_codecs();
1857
- init_schema();
1858
- DEFAULT_GEO_METADATA_VERSION = "1.1.0";
1859
- }
1860
- });
1861
-
1862
- // ../arrow-geometry/src/binary-geometry-to-wkb.ts
1863
- function reprojectWKBInPlace(wkb, transform) {
1864
- const dataView = new DataView(wkb.buffer, wkb.byteOffset, wkb.byteLength);
1865
- let littleEndian = true;
1866
- (0, import_wkb3.visitWKB)(wkb, {
1867
- geometry(header) {
1868
- littleEndian = header.littleEndian;
1869
- },
1870
- coordinate(coordinateX, coordinateY, _elevation, _measure, _dimension, byteOffset) {
1871
- const projected = transform([coordinateX, coordinateY]);
1872
- dataView.setFloat64(byteOffset, projected[0], littleEndian);
1873
- dataView.setFloat64(byteOffset + 8, projected[1], littleEndian);
1874
- }
1875
- });
1876
- return wkb;
1877
- }
1878
- var import_wkb3;
1879
- var init_binary_geometry_to_wkb = __esm({
1880
- "../arrow-geometry/src/binary-geometry-to-wkb.ts"() {
1881
- "use strict";
1882
- import_wkb3 = require("@math.gl/geospatial/wkb");
1883
- }
1884
- });
1885
-
1886
- // ../arrow-geometry/src/legacy-binary/transform-coordinates.ts
1887
- function transformGeoJsonCoords(features, fn) {
1888
- for (const feature of features) {
1889
- feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);
1890
- }
1891
- return features;
1892
- }
1893
- function coordMap(array, fn) {
1894
- if (isCoord(array)) {
1895
- return fn(array);
1896
- }
1897
- return array.map((item) => {
1898
- return coordMap(item, fn);
1899
- });
1900
- }
1901
- function isCoord(array) {
1902
- return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);
1903
- }
1904
- var init_transform_coordinates = __esm({
1905
- "../arrow-geometry/src/legacy-binary/transform-coordinates.ts"() {
1906
- "use strict";
1907
- }
1908
- });
1909
-
1910
- // ../arrow-geometry/src/legacy-binary.ts
1911
- var init_legacy_binary = __esm({
1912
- "../arrow-geometry/src/legacy-binary.ts"() {
1913
- "use strict";
1914
- init_transform_coordinates();
1915
- }
1916
- });
1917
-
1918
- // ../arrow-geometry/src/geoarrow-builder.ts
1919
- function makePrimitiveData(values) {
1920
- return arrow4.makeData({ type: new arrow4.Float64(), data: values });
1921
- }
1922
- function getBoxFieldNames(dimension) {
1923
- const minimumNames = dimension === "xy" ? ["xmin", "ymin"] : dimension === "xyz" ? ["xmin", "ymin", "zmin"] : dimension === "xym" ? ["xmin", "ymin", "mmin"] : ["xmin", "ymin", "zmin", "mmin"];
1924
- const maximumNames = dimension === "xy" ? ["xmax", "ymax"] : dimension === "xyz" ? ["xmax", "ymax", "zmax"] : dimension === "xym" ? ["xmax", "ymax", "mmax"] : ["xmax", "ymax", "zmax", "mmax"];
1925
- return [...minimumNames, ...maximumNames];
1926
- }
1927
- function getCoordinateSize(dimension) {
1928
- return dimension === "xy" ? 2 : dimension === "xyzm" ? 4 : 3;
1929
- }
1930
- function makeCoordinateData(values, dimension, coordinateLayout) {
1931
- if (coordinateLayout === "separated") {
1932
- const coordinateBuffers = values;
1933
- const coordinateNames = getCoordinateNames(dimension);
1934
- return arrow4.makeData({
1935
- type: new arrow4.Struct(
1936
- coordinateNames.map((name) => new arrow4.Field(name, new arrow4.Float64(), false))
1937
- ),
1938
- children: coordinateNames.map((name) => makePrimitiveData(coordinateBuffers[name]))
1939
- });
1940
- }
1941
- return arrow4.makeData({
1942
- type: new arrow4.FixedSizeList(
1943
- getCoordinateSize(dimension),
1944
- new arrow4.Field(dimension, new arrow4.Float64(), false)
1945
- ),
1946
- child: makePrimitiveData(values)
1947
- });
1948
- }
1949
- function makeBoxData(values, dimension) {
1950
- const names = getBoxFieldNames(dimension);
1951
- const children = names.map((name, index) => {
1952
- if (values instanceof Float64Array) {
1953
- const boxSize = names.length;
1954
- return makePrimitiveData(
1955
- Float64Array.from(
1956
- { length: values.length / boxSize },
1957
- (_, rowIndex) => values[rowIndex * boxSize + index]
1958
- )
1959
- );
1960
- }
1961
- return makePrimitiveData(values[name]);
1962
- });
1963
- return arrow4.makeData({
1964
- type: new arrow4.Struct(names.map((name) => new arrow4.Field(name, new arrow4.Float64(), false))),
1965
- children
1966
- });
1967
- }
1968
- function makeListData(child, offsets, fieldName, offsetType) {
1969
- return arrow4.makeData({
1970
- type: offsetType === "int64" ? makeLargeListType(new arrow4.Field(fieldName, child.type, false)) : new arrow4.List(new arrow4.Field(fieldName, child.type, false)),
1971
- valueOffsets: offsets,
1972
- child
1973
- });
1974
- }
1975
- function makeLargeListType(field) {
1976
- const LargeList = getOptionalArrowConstructor2("LargeList");
1977
- if (!LargeList) {
1978
- throw new Error(
1979
- "64-bit GeoArrow offsets require an Apache Arrow runtime that exports LargeList"
1980
- );
1981
- }
1982
- return new LargeList(field);
1983
- }
1984
- function getOptionalArrowConstructor2(typeName) {
1985
- return arrow4[typeName];
1986
- }
1987
- function makeCoordinateBuffers(coordinateCount, dimension, coordinateLayout) {
1988
- if (coordinateLayout === "interleaved") {
1989
- return new Float64Array(coordinateCount * getCoordinateSize(dimension));
1990
- }
1991
- const coordinateNames = getCoordinateNames(dimension);
1992
- const buffers = {
1993
- x: new Float64Array(coordinateCount),
1994
- y: new Float64Array(coordinateCount)
1995
- };
1996
- for (const name of coordinateNames.slice(2)) buffers[name] = new Float64Array(coordinateCount);
1997
- return buffers;
1998
- }
1999
- function makeBoxBuffers(boxCount, dimension, coordinateLayout) {
2000
- const names = getBoxFieldNames(dimension);
2001
- if (coordinateLayout === "interleaved") {
2002
- return new Float64Array(boxCount * names.length);
2003
- }
2004
- const buffers = {};
2005
- for (const name of names) {
2006
- buffers[name] = new Float64Array(boxCount);
2007
- }
2008
- return buffers;
2009
- }
2010
- function getBoxValues(dimension, xmin, ymin, xmax, ymax, zmin, zmax, mmin, mmax) {
2011
- switch (dimension) {
2012
- case "xy":
2013
- return [xmin, ymin, xmax, ymax];
2014
- case "xyz":
2015
- return [xmin, ymin, zmin ?? Number.NaN, xmax, ymax, zmax ?? Number.NaN];
2016
- case "xym":
2017
- return [xmin, ymin, mmin ?? Number.NaN, xmax, ymax, mmax ?? Number.NaN];
2018
- case "xyzm":
2019
- return [
2020
- xmin,
2021
- ymin,
2022
- zmin ?? Number.NaN,
2023
- mmin ?? Number.NaN,
2024
- xmax,
2025
- ymax,
2026
- zmax ?? Number.NaN,
2027
- mmax ?? Number.NaN
2028
- ];
2029
- }
2030
- }
2031
- function getCoordinateNames(dimension) {
2032
- switch (dimension) {
2033
- case "xy":
2034
- return ["x", "y"];
2035
- case "xyz":
2036
- return ["x", "y", "z"];
2037
- case "xym":
2038
- return ["x", "y", "m"];
2039
- case "xyzm":
2040
- return ["x", "y", "z", "m"];
2041
- }
2042
- }
2043
- function withNulls(data, geometryArray) {
2044
- return new arrow4.Data(
2045
- data.type,
2046
- 0,
2047
- geometryArray.length,
2048
- geometryArray.nullCount,
2049
- [
2050
- data.valueOffsets,
2051
- data.values,
2052
- geometryArray.nullCount > 0 ? geometryArray.nullBitmap : void 0
2053
- ],
2054
- data.children
2055
- );
2056
- }
2057
- var arrow4, GeoArrowBuilder;
2058
- var init_geoarrow_builder = __esm({
2059
- "../arrow-geometry/src/geoarrow-builder.ts"() {
2060
- "use strict";
2061
- arrow4 = __toESM(require("apache-arrow"), 1);
2062
- GeoArrowBuilder = class _GeoArrowBuilder {
2063
- /** GeoArrow extension encoding emitted by this builder. */
2064
- encoding;
2065
- /** Whether coordinate tuples include Z. */
2066
- hasZ;
2067
- /** Whether coordinate tuples include M. */
2068
- hasM;
2069
- /** Exact coordinate dimension emitted by this builder. */
2070
- dimension;
2071
- state;
2072
- /** Creates a GeoArrow builder in measure or write mode. */
2073
- constructor(options) {
2074
- this.encoding = options.encoding;
2075
- this.dimension = options.dimension || (options.hasZ && options.hasM ? "xyzm" : options.hasZ ? "xyz" : options.hasM ? "xym" : "xy");
2076
- this.hasZ = this.dimension === "xyz" || this.dimension === "xyzm";
2077
- this.hasM = this.dimension === "xym" || this.dimension === "xyzm";
2078
- const coordinateLayout = options.coordinateLayout || "interleaved";
2079
- const offsetType = options.offsetType || "int32";
2080
- this.state = {
2081
- mode: options.mode,
2082
- encoding: options.encoding,
2083
- coordinateSize: getCoordinateSize(this.dimension),
2084
- coordinateLayout,
2085
- offsetType,
2086
- transform: options.transform,
2087
- length: 0,
2088
- nullCount: 0,
2089
- coordinateCount: 0,
2090
- geometryChildCount: 0,
2091
- partChildCount: 0,
2092
- geometryOffsetCount: 1,
2093
- partOffsetCount: 1,
2094
- ringOffsetCount: 1,
2095
- target: options.mode === "write" ? options.target : void 0
2096
- };
2097
- this.initializeOffsets();
2098
- }
2099
- /** Emits one null geometry row. */
2100
- writeNullGeometry() {
2101
- this.state.length++;
2102
- this.state.nullCount++;
2103
- if (this.encoding !== "geoarrow.point" && this.encoding !== "geoarrow.box") {
2104
- this.writeGeometryOffset();
2105
- }
2106
- if (this.encoding === "geoarrow.point") this.state.coordinateCount++;
2107
- }
2108
- /** Begins one top-level geometry. */
2109
- beginGeometry(_type, _count) {
2110
- this.setValid(this.state.length);
2111
- this.state.length++;
2112
- }
2113
- /** Begins one point geometry or nested point. */
2114
- beginPoint() {
2115
- if (this.encoding === "geoarrow.point") this.beginGeometry();
2116
- }
2117
- /** Begins one axis-aligned GeoArrow box row. */
2118
- beginBox() {
2119
- if (this.encoding !== "geoarrow.box") {
2120
- throw new Error(`Cannot write Box into ${this.encoding}`);
2121
- }
2122
- this.beginGeometry();
2123
- }
2124
- /** Writes one axis-aligned box in canonical minimum-then-maximum ordinate order. */
2125
- writeBox(xmin, ymin, xmax, ymax, zmin, zmax, mmin, mmax) {
2126
- if (this.encoding !== "geoarrow.box") {
2127
- throw new Error(`Cannot write Box into ${this.encoding}`);
2128
- }
2129
- const coordinateIndex = this.state.coordinateCount;
2130
- const values = getBoxValues(this.dimension, xmin, ymin, xmax, ymax, zmin, zmax, mmin, mmax);
2131
- if (this.state.mode === "write") {
2132
- this.writeBoxValues(this.getTarget().coordinates, coordinateIndex, values);
2133
- }
2134
- this.state.coordinateCount++;
2135
- }
2136
- /** Begins one line string geometry or nested line string. */
2137
- beginLineString(pointCount) {
2138
- if (this.encoding === "geoarrow.linestring") {
2139
- this.beginGeometry();
2140
- this.writeGeometryOffset(pointCount);
2141
- return;
2142
- }
2143
- if (this.encoding === "geoarrow.multilinestring") {
2144
- this.writePartOffset(pointCount);
2145
- return;
2146
- }
2147
- throw new Error(`Cannot write LineString into ${this.encoding}`);
2148
- }
2149
- /** Begins one polygon geometry or nested polygon. */
2150
- beginPolygon(ringCount) {
2151
- if (this.encoding === "geoarrow.polygon") {
2152
- this.beginGeometry();
2153
- this.writeGeometryOffset(ringCount);
2154
- return;
2155
- }
2156
- if (this.encoding === "geoarrow.multipolygon") {
2157
- this.writePartOffset(ringCount);
2158
- return;
2159
- }
2160
- throw new Error(`Cannot write Polygon into ${this.encoding}`);
2161
- }
2162
- /** Begins one polygon linear ring. */
2163
- beginLinearRing(pointCount) {
2164
- if (this.encoding === "geoarrow.polygon") {
2165
- this.writePartOffset(pointCount);
2166
- return;
2167
- }
2168
- if (this.encoding === "geoarrow.multipolygon") {
2169
- this.writeRingOffset(pointCount);
2170
- return;
2171
- }
2172
- throw new Error(`Cannot write LinearRing into ${this.encoding}`);
2173
- }
2174
- /** Begins one multipoint geometry. */
2175
- beginMultiPoint(pointCount) {
2176
- if (this.encoding !== "geoarrow.multipoint") {
2177
- throw new Error(`Cannot write MultiPoint into ${this.encoding}`);
2178
- }
2179
- this.beginGeometry();
2180
- this.writeGeometryOffset(pointCount);
2181
- }
2182
- /** Begins one multilinestring geometry. */
2183
- beginMultiLineString(lineCount) {
2184
- if (this.encoding !== "geoarrow.multilinestring") {
2185
- throw new Error(`Cannot write MultiLineString into ${this.encoding}`);
2186
- }
2187
- this.beginGeometry();
2188
- this.writeGeometryOffset(lineCount);
2189
- }
2190
- /** Begins one multipolygon geometry. */
2191
- beginMultiPolygon(polygonCount) {
2192
- if (this.encoding !== "geoarrow.multipolygon") {
2193
- throw new Error(`Cannot write MultiPolygon into ${this.encoding}`);
2194
- }
2195
- this.beginGeometry();
2196
- this.writeGeometryOffset(polygonCount);
2197
- }
2198
- /** Writes one coordinate tuple. The third ordinate is M for an XYM builder. */
2199
- writeCoordinate(x, y, z, m) {
2200
- const coordinateIndex = this.state.coordinateCount;
2201
- if (this.state.mode === "write") {
2202
- const target = this.getTarget();
2203
- const coordinate = this.getCoordinateValuesForWrite(x, y, z, m);
2204
- const transformedCoordinate = this.state.transform ? this.state.transform(coordinate) : coordinate;
2205
- this.writeCoordinateValues(
2206
- target.coordinates,
2207
- coordinateIndex,
2208
- transformedCoordinate,
2209
- coordinate
2210
- );
2211
- }
2212
- this.state.coordinateCount++;
2213
- }
2214
- /** Completes the current geometry array and returns its row count. */
2215
- finishGeometry() {
2216
- return this.state.length;
2217
- }
2218
- /** Returns current measured or written array metadata. */
2219
- getGeometryArray() {
2220
- return {
2221
- encoding: this.encoding,
2222
- coordinateSize: this.state.coordinateSize,
2223
- dimension: this.dimension,
2224
- coordinateLayout: this.state.coordinateLayout,
2225
- offsetType: this.state.offsetType,
2226
- length: this.state.length,
2227
- nullCount: this.state.nullCount,
2228
- nullBitmap: this.getNullBitmap(),
2229
- coordinates: this.getCoordinateValues(),
2230
- geometryOffsets: this.getGeometryOffsets(),
2231
- partOffsets: this.getPartOffsets(),
2232
- ringOffsets: this.getRingOffsets()
2233
- };
2234
- }
2235
- /** Measures geometry callbacks and returns allocated offsets. */
2236
- static measureGeometryArray(writers, options) {
2237
- const builder = new _GeoArrowBuilder({ mode: "measure", ...options });
2238
- for (const writer of writers) writer ? writer(builder) : builder.writeNullGeometry();
2239
- builder.finishGeometry();
2240
- return builder.getGeometryArray();
2241
- }
2242
- /** Writes geometry callbacks into a measured target. */
2243
- static writeGeometryArray(writers, measured, options) {
2244
- const builder = new _GeoArrowBuilder({ mode: "write", target: measured, ...options });
2245
- for (const writer of writers) writer ? writer(builder) : builder.writeNullGeometry();
2246
- builder.finishGeometry();
2247
- return builder.getGeometryArray();
2248
- }
2249
- /** Builds GeoArrow buffers from callbacks in two passes. */
2250
- static buildGeometryArray(writers, options) {
2251
- const measured = _GeoArrowBuilder.measureGeometryArray(writers, options);
2252
- return _GeoArrowBuilder.writeGeometryArray(writers, measured, options);
2253
- }
2254
- /** Wraps GeoArrow buffers in an Apache Arrow Data instance. */
2255
- static makeGeometryData(geometryArray) {
2256
- if (geometryArray.encoding === "geoarrow.box") {
2257
- return withNulls(
2258
- makeBoxData(geometryArray.coordinates, geometryArray.dimension),
2259
- geometryArray
2260
- );
2261
- }
2262
- const coordinateData = makeCoordinateData(
2263
- geometryArray.coordinates,
2264
- geometryArray.dimension,
2265
- geometryArray.coordinateLayout
2266
- );
2267
- let data = coordinateData;
2268
- switch (geometryArray.encoding) {
2269
- case "geoarrow.point":
2270
- return withNulls(data, geometryArray);
2271
- case "geoarrow.linestring":
2272
- case "geoarrow.multipoint":
2273
- data = makeListData(
2274
- coordinateData,
2275
- geometryArray.geometryOffsets,
2276
- "vertices",
2277
- geometryArray.offsetType
2278
- );
2279
- return withNulls(data, geometryArray);
2280
- case "geoarrow.polygon":
2281
- case "geoarrow.multilinestring":
2282
- data = makeListData(
2283
- coordinateData,
2284
- geometryArray.partOffsets,
2285
- "vertices",
2286
- geometryArray.offsetType
2287
- );
2288
- data = makeListData(
2289
- data,
2290
- geometryArray.geometryOffsets,
2291
- "rings",
2292
- geometryArray.offsetType
2293
- );
2294
- return withNulls(data, geometryArray);
2295
- case "geoarrow.multipolygon":
2296
- data = makeListData(
2297
- coordinateData,
2298
- geometryArray.ringOffsets,
2299
- "vertices",
2300
- geometryArray.offsetType
2301
- );
2302
- data = makeListData(data, geometryArray.partOffsets, "rings", geometryArray.offsetType);
2303
- data = makeListData(
2304
- data,
2305
- geometryArray.geometryOffsets,
2306
- "polygons",
2307
- geometryArray.offsetType
2308
- );
2309
- return withNulls(data, geometryArray);
2310
- default:
2311
- throw new Error(`Unsupported GeoArrow encoding ${geometryArray.encoding}`);
2312
- }
2313
- }
2314
- initializeOffsets() {
2315
- if (this.state.mode !== "measure") return;
2316
- const target = {
2317
- nullBitmap: new Uint8Array(0),
2318
- coordinates: makeCoordinateBuffers(0, this.dimension, this.state.coordinateLayout)
2319
- };
2320
- if (this.encoding !== "geoarrow.point" && this.encoding !== "geoarrow.box") {
2321
- target.geometryOffsets = this.makeOffsets(1);
2322
- }
2323
- if (this.encoding === "geoarrow.polygon" || this.encoding === "geoarrow.multilinestring" || this.encoding === "geoarrow.multipolygon") {
2324
- target.partOffsets = this.makeOffsets(1);
2325
- }
2326
- if (this.encoding === "geoarrow.multipolygon") target.ringOffsets = this.makeOffsets(1);
2327
- this.state.target = target;
2328
- }
2329
- getCoordinateValuesForWrite(x, y, z, m) {
2330
- if (this.dimension === "xy") return [x, y];
2331
- if (this.dimension === "xyz") return [x, y, z ?? Number.NaN];
2332
- if (this.dimension === "xym") return [x, y, m ?? z ?? Number.NaN];
2333
- return [x, y, z ?? Number.NaN, m ?? Number.NaN];
2334
- }
2335
- writeGeometryOffset(childCount = 0) {
2336
- if (this.encoding === "geoarrow.point") return;
2337
- this.state.geometryChildCount += childCount;
2338
- this.appendOffset("geometryOffsets", this.state.geometryChildCount);
2339
- }
2340
- writePartOffset(childCount = 0) {
2341
- this.state.partChildCount += childCount;
2342
- this.appendOffset("partOffsets", this.state.partChildCount);
2343
- }
2344
- writeRingOffset(childCount = 0) {
2345
- this.appendOffset("ringOffsets", this.state.coordinateCount + childCount);
2346
- }
2347
- appendOffset(name, value) {
2348
- const target = this.getTarget();
2349
- const offsets = target[name];
2350
- if (!offsets) return;
2351
- if (this.state.mode === "measure") {
2352
- this.incrementOffsetCount(name);
2353
- return;
2354
- }
2355
- const index = this.getOffsetCount(name);
2356
- if (index >= offsets.length) throw new Error(`GeoArrowBuilder target ${name} overflow`);
2357
- offsets[index] = offsets instanceof BigInt64Array ? BigInt(value) : value;
2358
- this.incrementOffsetCount(name);
2359
- }
2360
- getOffsetCount(name) {
2361
- switch (name) {
2362
- case "geometryOffsets":
2363
- return this.state.geometryOffsetCount;
2364
- case "partOffsets":
2365
- return this.state.partOffsetCount;
2366
- case "ringOffsets":
2367
- return this.state.ringOffsetCount;
2368
- default:
2369
- throw new Error(`Unexpected offset buffer ${name}`);
2370
- }
2371
- }
2372
- incrementOffsetCount(name) {
2373
- switch (name) {
2374
- case "geometryOffsets":
2375
- this.state.geometryOffsetCount++;
2376
- return;
2377
- case "partOffsets":
2378
- this.state.partOffsetCount++;
2379
- return;
2380
- case "ringOffsets":
2381
- this.state.ringOffsetCount++;
2382
- return;
2383
- default:
2384
- throw new Error(`Unexpected offset buffer ${name}`);
2385
- }
2386
- }
2387
- setValid(rowIndex) {
2388
- if (this.state.mode !== "write") return;
2389
- const bitmap = this.getTarget().nullBitmap;
2390
- bitmap[rowIndex >> 3] |= 1 << (rowIndex & 7);
2391
- }
2392
- getTarget() {
2393
- if (!this.state.target) throw new Error("GeoArrowBuilder target is not initialized");
2394
- return this.state.target;
2395
- }
2396
- getNullBitmap() {
2397
- return this.state.mode === "measure" ? new Uint8Array(Math.ceil(this.state.length / 8)) : this.getTarget().nullBitmap;
2398
- }
2399
- getCoordinateValues() {
2400
- return this.state.mode === "measure" ? this.encoding === "geoarrow.box" ? makeBoxBuffers(this.state.coordinateCount, this.dimension, this.state.coordinateLayout) : makeCoordinateBuffers(
2401
- this.state.coordinateCount,
2402
- this.dimension,
2403
- this.state.coordinateLayout
2404
- ) : this.getTarget().coordinates;
2405
- }
2406
- getGeometryOffsets() {
2407
- return this.state.mode === "measure" && this.encoding !== "geoarrow.point" && this.encoding !== "geoarrow.box" ? this.makeOffsets(this.state.geometryOffsetCount) : this.getTarget().geometryOffsets;
2408
- }
2409
- getPartOffsets() {
2410
- return this.state.mode === "measure" && (this.encoding === "geoarrow.polygon" || this.encoding === "geoarrow.multilinestring" || this.encoding === "geoarrow.multipolygon") ? this.makeOffsets(this.state.partOffsetCount) : this.getTarget().partOffsets;
2411
- }
2412
- getRingOffsets() {
2413
- return this.state.mode === "measure" && this.encoding === "geoarrow.multipolygon" ? this.makeOffsets(this.state.ringOffsetCount) : this.getTarget().ringOffsets;
2414
- }
2415
- makeOffsets(length) {
2416
- return this.state.offsetType === "int64" ? new BigInt64Array(length) : new Int32Array(length);
2417
- }
2418
- writeCoordinateValues(coordinates, coordinateIndex, transformedCoordinate, originalCoordinate) {
2419
- if (coordinates instanceof Float64Array) {
2420
- if (coordinateIndex >= coordinates.length / this.state.coordinateSize) {
2421
- throw new Error("GeoArrowBuilder target coordinate buffer overflow");
2422
- }
2423
- const valueOffset = coordinateIndex * this.state.coordinateSize;
2424
- for (let dimensionIndex = 0; dimensionIndex < this.state.coordinateSize; dimensionIndex++) {
2425
- coordinates[valueOffset + dimensionIndex] = transformedCoordinate[dimensionIndex] ?? originalCoordinate[dimensionIndex] ?? Number.NaN;
2426
- }
2427
- return;
2428
- }
2429
- const coordinateNames = getCoordinateNames(this.dimension);
2430
- for (let dimensionIndex = 0; dimensionIndex < coordinateNames.length; dimensionIndex++) {
2431
- const coordinateValues = coordinates[coordinateNames[dimensionIndex]];
2432
- if (!coordinateValues || coordinateIndex >= coordinateValues.length) {
2433
- throw new Error("GeoArrowBuilder target coordinate buffer overflow");
2434
- }
2435
- coordinateValues[coordinateIndex] = transformedCoordinate[dimensionIndex] ?? originalCoordinate[dimensionIndex] ?? Number.NaN;
2436
- }
2437
- }
2438
- writeBoxValues(coordinates, coordinateIndex, values) {
2439
- if (coordinates instanceof Float64Array) {
2440
- const valueOffset = coordinateIndex * values.length;
2441
- if (valueOffset + values.length > coordinates.length) {
2442
- throw new Error("GeoArrowBuilder target box buffer overflow");
2443
- }
2444
- coordinates.set(values, valueOffset);
2445
- return;
2446
- }
2447
- const boxCoordinates = coordinates;
2448
- const names = getBoxFieldNames(this.dimension);
2449
- for (let index = 0; index < names.length; index++) {
2450
- const valuesBuffer = boxCoordinates[names[index]];
2451
- if (!(valuesBuffer instanceof Float64Array) || coordinateIndex >= valuesBuffer.length) {
2452
- throw new Error("GeoArrowBuilder target box buffer overflow");
2453
- }
2454
- valuesBuffer[coordinateIndex] = values[index];
2455
- }
2456
- }
2457
- };
2458
- }
2459
- });
2460
-
2461
- // ../arrow-geometry/src/feature-table.ts
2462
- function convertFeaturesToGeoArrowTable(features, options) {
2463
- const preference = resolveGeoArrowEncodingPreference(options);
2464
- if (preference === "geoarrow.geometry" || preference === "optimized") {
2465
- return convertFeaturesToNativeGeoArrowTable(features, options, preference);
2466
- }
2467
- const rows = makeGeoArrowFeatureRows(features, options);
2468
- const schema = makeGeoArrowFeatureSchema(features, options);
2469
- const arrowTableBuilder = new ArrowTableBuilder(schema);
2470
- for (const row of rows) {
2471
- arrowTableBuilder.addObjectRow(row);
2472
- }
2473
- return arrowTableBuilder.finishTable();
2474
- }
2475
- function convertFeaturesToNativeGeoArrowTable(features, options, preference) {
2476
- const geometries = features.map((feature) => feature.geometry || null);
2477
- const dimension = getFeatureDimension(geometries);
2478
- const encoding = preference === "geoarrow.geometry" ? preference : selectOptimizedEncoding(geometries);
2479
- const geometryVector = encoding === "geoarrow.geometry" ? makeGeometryUnionVector(geometries, dimension) : makeNativeGeometryVector(geometries, encoding, dimension);
2480
- const geometryColumnName = (options == null ? void 0 : options.geometryColumnName) || DEFAULT_GEOMETRY_COLUMN_NAME;
2481
- const propertyRows = features.map((feature) => {
2482
- const properties = normalizeProperties(feature.properties);
2483
- assertNoGeometryPropertyCollision(properties, geometryColumnName);
2484
- return properties;
2485
- });
2486
- const propertySchema = (options == null ? void 0 : options.propertySchema) || getPropertySchema(propertyRows);
2487
- const schema = convertSchemaToArrow(propertySchema);
2488
- const dimensionSuffix = dimension === "xy" ? "" : ` ${dimension.slice(2).toUpperCase()}`;
2489
- const inferredGeometryColumnMetadata = {
2490
- encoding,
2491
- geometry_types: [
2492
- ...new Set(
2493
- inferGeoParquetGeometryTypes(geometries).map(
2494
- (type) => `${type.split(" ")[0]}${dimensionSuffix}`
2495
- )
2496
- )
2497
- ]
2498
- };
2499
- const existingGeoMetadata = getGeoMetadata(schema.metadata);
2500
- const existingGeometryColumnMetadata = existingGeoMetadata == null ? void 0 : existingGeoMetadata.columns[geometryColumnName];
2501
- const geometryColumnMetadata = existingGeometryColumnMetadata ? { ...existingGeometryColumnMetadata } : inferredGeometryColumnMetadata;
2502
- const extensionMetadata = existingGeometryColumnMetadata ? { ...existingGeometryColumnMetadata } : inferredGeometryColumnMetadata;
2503
- if (isLegacyGeoJSONCRS(options == null ? void 0 : options.crs)) {
2504
- const normalizedCRS = normalizeLegacyGeoJSONCRS(options.crs);
2505
- geometryColumnMetadata.geojson_crs = options.crs;
2506
- extensionMetadata.geojson_crs = options.crs;
2507
- if (normalizedCRS) {
2508
- geometryColumnMetadata.crs = normalizedCRS.projjson;
2509
- extensionMetadata.crs = normalizedCRS.projjson;
2510
- extensionMetadata.crs_type = "projjson";
2511
- }
2512
- }
2513
- const geometryField = new arrow5.Field(
2514
- geometryColumnName,
2515
- geometryVector.type,
2516
- true,
2517
- /* @__PURE__ */ new Map([
2518
- ["ARROW:extension:name", encoding],
2519
- ["ARROW:extension:metadata", JSON.stringify(extensionMetadata)]
2520
- ])
2521
- );
2522
- const nextFields = [...schema.fields, geometryField];
2523
- const nextMetadata = new Map(schema.metadata || []);
2524
- nextMetadata.set(
2525
- "geo",
2526
- JSON.stringify({
2527
- version: DEFAULT_GEO_METADATA_VERSION2,
2528
- primary_column: geometryColumnName,
2529
- columns: {
2530
- [geometryColumnName]: geometryColumnMetadata
2531
- }
2532
- })
2533
- );
2534
- const nextSchema = new arrow5.Schema(nextFields, nextMetadata);
2535
- const propertyTableBuilder = new ArrowTableBuilder(propertySchema);
2536
- for (const row of propertyRows) {
2537
- propertyTableBuilder.addObjectRow(row);
2538
- }
2539
- const propertyTable = propertyTableBuilder.finishTable().data;
2540
- const propertyBatch = propertyTable.batches[0];
2541
- const children = nextFields.map(
2542
- (field, fieldIndex) => {
2543
- var _a;
2544
- return fieldIndex < schema.fields.length ? (_a = propertyBatch == null ? void 0 : propertyBatch.getChildAt(fieldIndex)) == null ? void 0 : _a.data[0] : geometryVector.data[0];
2545
- }
2546
- );
2547
- const data = arrow5.makeData({
2548
- type: new arrow5.Struct(nextFields),
2549
- length: features.length,
2550
- nullCount: 0,
2551
- children
2552
- });
2553
- return {
2554
- shape: "arrow-table",
2555
- schema: convertArrowToSchema(nextSchema),
2556
- data: new arrow5.Table(nextSchema, [new arrow5.RecordBatch(nextSchema, data)])
2557
- };
2558
- }
2559
- function resolveGeoArrowEncodingPreference(options) {
2560
- var _a;
2561
- return ((_a = options == null ? void 0 : options.geoarrow) == null ? void 0 : _a.encodingPreference) ?? (options == null ? void 0 : options.encodingPreference);
2562
- }
2563
- function selectOptimizedEncoding(geometries) {
2564
- const geometryKinds = new Set(
2565
- geometries.filter(Boolean).map((geometry) => geometry.type)
2566
- );
2567
- if (geometryKinds.size === 0 || geometryKinds.has("GeometryCollection")) {
2568
- return "geoarrow.geometry";
2569
- }
2570
- if (geometryKinds.size === 1) {
2571
- return getNativeEncoding([...geometryKinds][0]);
2572
- }
2573
- if (geometryKinds.size === 2) {
2574
- if (geometryKinds.has("Point") && geometryKinds.has("MultiPoint")) {
2575
- return "geoarrow.multipoint";
2576
- }
2577
- if (geometryKinds.has("LineString") && geometryKinds.has("MultiLineString")) {
2578
- return "geoarrow.multilinestring";
2579
- }
2580
- if (geometryKinds.has("Polygon") && geometryKinds.has("MultiPolygon")) {
2581
- return "geoarrow.multipolygon";
2582
- }
2583
- }
2584
- return "geoarrow.geometry";
2585
- }
2586
- function getFeatureDimension(geometries) {
2587
- let hasZ = false;
2588
- let hasM = false;
2589
- for (const geometry of geometries) {
2590
- if (!geometry) continue;
2591
- const dimensions = getGeometryWKBOptions(geometry);
2592
- hasZ ||= Boolean(dimensions.hasZ);
2593
- hasM ||= Boolean(dimensions.hasM);
2594
- if (geometry.type === "GeometryCollection") {
2595
- const childDimension = getFeatureDimension(geometry.geometries);
2596
- hasZ ||= childDimension === "xyz" || childDimension === "xyzm";
2597
- hasM ||= childDimension === "xym" || childDimension === "xyzm";
2598
- }
2599
- }
2600
- return hasZ ? hasM ? "xyzm" : "xyz" : hasM ? "xym" : "xy";
2601
- }
2602
- function makeNativeGeometryVector(geometries, encoding, dimension) {
2603
- const writers = geometries.map(
2604
- (geometry) => geometry ? (builder) => writeGeometryToBuilder(builder, geometry, encoding) : null
2605
- );
2606
- const geometryArray = GeoArrowBuilder.buildGeometryArray(writers, { encoding, dimension });
2607
- return arrow5.makeVector(GeoArrowBuilder.makeGeometryData(geometryArray));
2608
- }
2609
- function makeGeometryUnionVector(geometries, dimension, includeGeometryCollections = true) {
2610
- const childRows = /* @__PURE__ */ new Map();
2611
- const typeIds = [];
2612
- const valueOffsets = [];
2613
- const nullCarrierKind = "Point";
2614
- const allGeometryKinds = [
2615
- "Point",
2616
- "LineString",
2617
- "Polygon",
2618
- "MultiPoint",
2619
- "MultiLineString",
2620
- "MultiPolygon",
2621
- ...includeGeometryCollections ? ["GeometryCollection"] : []
2622
- ];
2623
- for (const geometryKind of allGeometryKinds) {
2624
- childRows.set(geometryKind, []);
2625
- }
2626
- for (const geometry of geometries) {
2627
- const kind = (geometry == null ? void 0 : geometry.type) || nullCarrierKind;
2628
- const rows = childRows.get(kind) || [];
2629
- valueOffsets.push(rows.length);
2630
- typeIds.push(getUnionTypeId(kind, dimension));
2631
- rows.push(geometry);
2632
- childRows.set(kind, rows);
2633
- }
2634
- const orderedKinds = [...childRows.keys()].sort(
2635
- (left, right) => getUnionTypeId(left, dimension) - getUnionTypeId(right, dimension)
2636
- );
2637
- const fields = orderedKinds.map(
2638
- (kind) => new arrow5.Field(
2639
- getUnionFieldName(kind, dimension),
2640
- kind === "GeometryCollection" ? makeGeometryCollectionVector(childRows.get(kind), dimension).type : makeNativeGeometryVector(childRows.get(kind), getNativeEncoding(kind), dimension).type,
2641
- true
2642
- )
2643
- );
2644
- const children = orderedKinds.map((kind) => {
2645
- if (kind === "GeometryCollection") {
2646
- return makeGeometryCollectionVector(childRows.get(kind), dimension).data[0];
2647
- }
2648
- return makeNativeGeometryVector(childRows.get(kind), getNativeEncoding(kind), dimension).data[0];
2649
- });
2650
- const unionType = new arrow5.DenseUnion(
2651
- orderedKinds.map((kind) => getUnionTypeId(kind, dimension)),
2652
- fields
2653
- );
2654
- return arrow5.makeVector(
2655
- arrow5.makeData({
2656
- type: unionType,
2657
- length: geometries.length,
2658
- nullCount: 0,
2659
- typeIds: Int8Array.from(typeIds),
2660
- valueOffsets: Int32Array.from(valueOffsets),
2661
- children
2662
- })
2663
- );
2664
- }
2665
- function makeGeometryCollectionVector(geometries, dimension) {
2666
- const flattenedGeometries = [];
2667
- const offsets = [0];
2668
- for (const geometry of geometries) {
2669
- if ((geometry == null ? void 0 : geometry.type) === "GeometryCollection") {
2670
- appendGeometryCollectionMembers(flattenedGeometries, geometry.geometries);
2671
- }
2672
- offsets.push(flattenedGeometries.length);
2673
- }
2674
- const memberUnion = makeGeometryUnionVector(flattenedGeometries, dimension, false);
2675
- const listType = new arrow5.List(new arrow5.Field("geometries", memberUnion.type, true));
2676
- return arrow5.makeVector(
2677
- arrow5.makeData({
2678
- type: listType,
2679
- length: geometries.length,
2680
- nullCount: 0,
2681
- valueOffsets: Int32Array.from(offsets),
2682
- child: memberUnion.data[0]
2683
- })
2684
- );
2685
- }
2686
- function appendGeometryCollectionMembers(target, geometries) {
2687
- for (const geometry of geometries) {
2688
- if ((geometry == null ? void 0 : geometry.type) === "GeometryCollection") {
2689
- appendGeometryCollectionMembers(target, geometry.geometries);
2690
- } else {
2691
- target.push(geometry);
2692
- }
2693
- }
2694
- }
2695
- function writeGeometryToBuilder(builder, geometry, encoding) {
2696
- const dimensions = getGeometryWKBOptions(geometry);
2697
- switch (geometry.type) {
2698
- case "Point":
2699
- if (encoding === "geoarrow.multipoint") builder.beginMultiPoint(1);
2700
- builder.beginPoint();
2701
- writeCoordinateToBuilder(builder, geometry.coordinates, dimensions);
2702
- return;
2703
- case "MultiPoint":
2704
- builder.beginMultiPoint(geometry.coordinates.length);
2705
- for (const coordinate of geometry.coordinates) {
2706
- builder.beginPoint();
2707
- writeCoordinateToBuilder(builder, coordinate, dimensions);
2708
- }
2709
- return;
2710
- case "LineString":
2711
- if (encoding === "geoarrow.multilinestring") builder.beginMultiLineString(1);
2712
- writeLineStringToBuilder(builder, geometry.coordinates, dimensions);
2713
- return;
2714
- case "MultiLineString":
2715
- builder.beginMultiLineString(geometry.coordinates.length);
2716
- for (const line of geometry.coordinates) writeLineStringToBuilder(builder, line, dimensions);
2717
- return;
2718
- case "Polygon":
2719
- if (encoding === "geoarrow.multipolygon") builder.beginMultiPolygon(1);
2720
- writePolygonToBuilder(builder, geometry.coordinates, dimensions);
2721
- return;
2722
- case "MultiPolygon":
2723
- builder.beginMultiPolygon(geometry.coordinates.length);
2724
- for (const polygon of geometry.coordinates)
2725
- writePolygonToBuilder(builder, polygon, dimensions);
2726
- return;
2727
- case "GeometryCollection":
2728
- throw new Error("GeometryCollection must be written through the dense union builder.");
2729
- }
2730
- }
2731
- function writeLineStringToBuilder(builder, coordinates, dimensions) {
2732
- builder.beginLineString(coordinates.length);
2733
- for (const coordinate of coordinates) writeCoordinateToBuilder(builder, coordinate, dimensions);
2734
- }
2735
- function writePolygonToBuilder(builder, coordinates, dimensions) {
2736
- builder.beginPolygon(coordinates.length);
2737
- for (const ring of coordinates) {
2738
- builder.beginLinearRing(ring.length);
2739
- for (const coordinate of ring) writeCoordinateToBuilder(builder, coordinate, dimensions);
2740
- }
2741
- }
2742
- function writeCoordinateToBuilder(builder, coordinate, dimensions) {
2743
- builder.writeCoordinate(
2744
- coordinate[0] ?? Number.NaN,
2745
- coordinate[1] ?? Number.NaN,
2746
- dimensions.hasZ ? coordinate[2] : void 0,
2747
- dimensions.hasM ? coordinate[dimensions.hasZ ? 3 : 2] : void 0
2748
- );
2749
- }
2750
- function getNativeEncoding(kind) {
2751
- switch (kind) {
2752
- case "Point":
2753
- return "geoarrow.point";
2754
- case "LineString":
2755
- return "geoarrow.linestring";
2756
- case "Polygon":
2757
- return "geoarrow.polygon";
2758
- case "MultiPoint":
2759
- return "geoarrow.multipoint";
2760
- case "MultiLineString":
2761
- return "geoarrow.multilinestring";
2762
- case "MultiPolygon":
2763
- return "geoarrow.multipolygon";
2764
- default:
2765
- throw new Error(`No native GeoArrow encoding exists for ${kind}.`);
2766
- }
2767
- }
2768
- function getUnionTypeId(kind, dimension) {
2769
- const baseTypeId = {
2770
- Point: 1,
2771
- LineString: 2,
2772
- Polygon: 3,
2773
- MultiPoint: 4,
2774
- MultiLineString: 5,
2775
- MultiPolygon: 6,
2776
- GeometryCollection: 7
2777
- };
2778
- const dimensionOffset = dimension === "xyz" ? 10 : dimension === "xym" ? 20 : dimension === "xyzm" ? 30 : 0;
2779
- return baseTypeId[kind] + dimensionOffset;
2780
- }
2781
- function getUnionFieldName(kind, dimension) {
2782
- return dimension === "xy" ? kind : `${kind} ${dimension.slice(2).toUpperCase()}`;
2783
- }
2784
- function makeGeoArrowFeatureRows(features, options) {
2785
- const geometryColumnName = (options == null ? void 0 : options.geometryColumnName) || DEFAULT_GEOMETRY_COLUMN_NAME;
2786
- const encoding = (options == null ? void 0 : options.encoding) || "wkb";
2787
- return features.map((feature) => {
2788
- const properties = normalizeProperties(feature.properties);
2789
- assertNoGeometryPropertyCollision(properties, geometryColumnName);
2790
- return {
2791
- ...properties,
2792
- [geometryColumnName]: encodeGeoArrowGeometry(feature.geometry, encoding)
2793
- };
2794
- });
2795
- }
2796
- function makeGeoArrowFeatureSchema(features, options) {
2797
- const geometryColumnName = (options == null ? void 0 : options.geometryColumnName) || DEFAULT_GEOMETRY_COLUMN_NAME;
2798
- const encoding = (options == null ? void 0 : options.encoding) || "wkb";
2799
- const propertyRows = features.map((feature) => {
2800
- const properties = normalizeProperties(feature.properties);
2801
- assertNoGeometryPropertyCollision(properties, geometryColumnName);
2802
- return properties;
2803
- });
2804
- const propertySchema = getPropertySchema(propertyRows);
2805
- const geometryField = encoding === "wkb" ? makeWKBGeometryField(geometryColumnName, true) : {
2806
- name: geometryColumnName,
2807
- type: "utf8",
2808
- nullable: true,
2809
- metadata: {}
2810
- };
2811
- const schema = {
2812
- fields: [...propertySchema.fields, geometryField],
2813
- metadata: { ...propertySchema.metadata || {} }
2814
- };
2815
- if (encoding === "wkb") {
2816
- setWKBGeometrySchemaMetadata(schema, {
2817
- geometryColumnName,
2818
- primaryColumnName: geometryColumnName,
2819
- geometryTypes: inferGeoParquetGeometryTypes(features.map((feature) => feature.geometry))
2820
- });
2821
- } else {
2822
- schema.metadata.geo = JSON.stringify({
2823
- version: DEFAULT_GEO_METADATA_VERSION2,
2824
- primary_column: geometryColumnName,
2825
- columns: {
2826
- [geometryColumnName]: {
2827
- encoding,
2828
- geometry_types: inferGeoParquetGeometryTypes(features.map((feature) => feature.geometry))
2829
- }
2830
- }
2831
- });
2832
- }
2833
- applyLegacyGeoJSONCRSToSchema(schema, geometryColumnName, options == null ? void 0 : options.crs);
2834
- return schema;
2835
- }
2836
- function applyLegacyGeoJSONCRSToSchema(schema, geometryColumnName, crs) {
2837
- if (!isLegacyGeoJSONCRS(crs)) {
2838
- return schema;
2839
- }
2840
- const geometryField = schema.fields.find((field) => field.name === geometryColumnName);
2841
- if (!geometryField) {
2842
- return schema;
2843
- }
2844
- const normalizedCRS = normalizeLegacyGeoJSONCRS(crs);
2845
- const columnMetadata = {
2846
- [GEOJSON_CRS_METADATA_KEY]: crs
2847
- };
2848
- if (normalizedCRS) {
2849
- columnMetadata.crs = normalizedCRS.projjson;
2850
- }
2851
- schema.metadata ||= {};
2852
- const geoMetadata = getGeoMetadata(schema.metadata) || {
2853
- version: DEFAULT_GEO_METADATA_VERSION2,
2854
- primary_column: geometryColumnName,
2855
- columns: {}
2856
- };
2857
- geoMetadata.version ||= DEFAULT_GEO_METADATA_VERSION2;
2858
- geoMetadata.primary_column ||= geometryColumnName;
2859
- geoMetadata.columns ||= {};
2860
- const existingColumnMetadata = geoMetadata.columns[geometryColumnName] || {
2861
- encoding: geometryField.type === "utf8" ? "wkt" : "wkb",
2862
- geometry_types: []
2863
- };
2864
- geoMetadata.columns[geometryColumnName] = {
2865
- ...existingColumnMetadata,
2866
- ...columnMetadata
2867
- };
2868
- setGeoMetadata(schema.metadata, geoMetadata);
2869
- geometryField.metadata ||= {};
2870
- const extensionMetadata = parseExtensionMetadata(
2871
- geometryField.metadata[GEOARROW_EXTENSION_METADATA_KEY]
2872
- );
2873
- extensionMetadata[GEOJSON_CRS_METADATA_KEY] = crs;
2874
- if (normalizedCRS) {
2875
- extensionMetadata.crs = normalizedCRS.projjson;
2876
- extensionMetadata.crs_type = "projjson";
2877
- }
2878
- geometryField.metadata[GEOARROW_EXTENSION_METADATA_KEY] = JSON.stringify(extensionMetadata);
2879
- return schema;
2880
- }
2881
- function encodeGeoArrowGeometry(geometry, encoding) {
2882
- if (!geometry) {
2883
- return null;
2884
- }
2885
- return encoding === "wkt" ? convertGeometryToWKT(geometry) : encodeWKBGeometryValue(geometry);
2886
- }
2887
- function normalizeProperties(properties) {
2888
- if (!properties || typeof properties !== "object") {
2889
- return {};
2890
- }
2891
- const normalizedProperties = {};
2892
- for (const [propertyName, propertyValue] of Object.entries(properties)) {
2893
- normalizedProperties[propertyName] = normalizePropertyValue(propertyValue);
2894
- }
2895
- return normalizedProperties;
2896
- }
2897
- function normalizePropertyValue(propertyValue) {
2898
- if (propertyValue === null || propertyValue === void 0 || typeof propertyValue === "string" || typeof propertyValue === "number" || typeof propertyValue === "boolean") {
2899
- return propertyValue ?? null;
2900
- }
2901
- if (propertyValue instanceof Date) {
2902
- return propertyValue.toISOString();
2903
- }
2904
- return JSON.stringify(propertyValue);
2905
- }
2906
- function getPropertySchema(propertyRows) {
2907
- if (propertyRows.length === 0) {
2908
- return { fields: [], metadata: {} };
2909
- }
2910
- const fieldNames = getFieldNames(propertyRows);
2911
- return {
2912
- metadata: {},
2913
- fields: fieldNames.map((fieldName) => {
2914
- const inferredType = getPropertyFieldType(
2915
- propertyRows.map((propertyRow) => propertyRow[fieldName])
2916
- );
2917
- return {
2918
- name: fieldName,
2919
- type: inferredType.type === "float32" ? "float64" : inferredType.type,
2920
- nullable: inferredType.nullable
2921
- };
2922
- })
2923
- };
2924
- }
2925
- function getPropertyFieldType(values) {
2926
- let type = "null";
2927
- let nullable = false;
2928
- for (const value of values) {
2929
- if (value === null || value === void 0) {
2930
- nullable = true;
2931
- continue;
2932
- }
2933
- const valueType = getPropertyValueType(value);
2934
- if (type === "null") {
2935
- type = valueType;
2936
- continue;
2937
- }
2938
- if (type !== valueType) {
2939
- throw new Error(`GeoJSONLoader: incompatible property types ${type} and ${valueType}`);
2940
- }
2941
- }
2942
- return { type, nullable };
2943
- }
2944
- function getPropertyValueType(value) {
2945
- switch (typeof value) {
2946
- case "boolean":
2947
- return "bool";
2948
- case "number":
2949
- return "float64";
2950
- case "string":
2951
- return "utf8";
2952
- default:
2953
- return "null";
2954
- }
2955
- }
2956
- function isLegacyGeoJSONCRS(value) {
2957
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
2958
- }
2959
- function normalizeLegacyGeoJSONCRS(crs) {
2960
- const name = getLegacyGeoJSONCRSName(crs);
2961
- if (!name) {
2962
- return null;
2963
- }
2964
- const normalizedName = name.toLowerCase();
2965
- if (normalizedName === "crs84" || normalizedName === "ogc:crs84" || normalizedName === "urn:ogc:def:crs:ogc:1.3:crs84" || normalizedName === "urn:ogc:def:crs:ogc::crs84" || normalizedName === "http://www.opengis.net/def/crs/ogc/1.3/crs84") {
2966
- return { name, projjson: cloneJSON(CRS84_PROJJSON) };
2967
- }
2968
- if (normalizedName === "epsg:4326" || normalizedName === "urn:ogc:def:crs:epsg::4326" || normalizedName === "urn:ogc:def:crs:epsg:6.6:4326" || normalizedName === "http://www.opengis.net/def/crs/epsg/0/4326") {
2969
- return { name, projjson: cloneJSON(EPSG_4326_PROJJSON) };
2970
- }
2971
- return null;
2972
- }
2973
- function getLegacyGeoJSONCRSName(crs) {
2974
- var _a;
2975
- if (typeof ((_a = crs.properties) == null ? void 0 : _a.name) === "string") {
2976
- return crs.properties.name;
2977
- }
2978
- if (typeof crs.name === "string") {
2979
- return crs.name;
2980
- }
2981
- return null;
2982
- }
2983
- function parseExtensionMetadata(metadata) {
2984
- if (!metadata) {
2985
- return {};
2986
- }
2987
- try {
2988
- const parsedMetadata = JSON.parse(metadata);
2989
- return parsedMetadata && typeof parsedMetadata === "object" && !Array.isArray(parsedMetadata) ? parsedMetadata : {};
2990
- } catch {
2991
- return {};
2992
- }
2993
- }
2994
- function cloneJSON(value) {
2995
- return JSON.parse(JSON.stringify(value));
2996
- }
2997
- function getFieldNames(propertyRows) {
2998
- const fieldNames = /* @__PURE__ */ new Set();
2999
- for (const propertyRow of propertyRows) {
3000
- for (const fieldName of Object.keys(propertyRow)) {
3001
- fieldNames.add(fieldName);
3002
- }
3003
- }
3004
- return [...fieldNames];
3005
- }
3006
- function assertNoGeometryPropertyCollision(properties, geometryColumnName) {
3007
- if (Object.prototype.hasOwnProperty.call(properties, geometryColumnName)) {
3008
- throw new Error(
3009
- `GeoArrow conversion: GeoJSON property "${geometryColumnName}" conflicts with the geometry column name`
3010
- );
3011
- }
3012
- }
3013
- var arrow5, DEFAULT_GEOMETRY_COLUMN_NAME, DEFAULT_GEO_METADATA_VERSION2, GEOJSON_CRS_METADATA_KEY, GEOARROW_EXTENSION_METADATA_KEY, CRS84_PROJJSON, EPSG_4326_PROJJSON;
3014
- var init_feature_table = __esm({
3015
- "../arrow-geometry/src/feature-table.ts"() {
3016
- "use strict";
3017
- arrow5 = __toESM(require("apache-arrow"), 1);
3018
- init_schema_utils();
3019
- init_geometry_codecs();
3020
- init_geometry_field();
3021
- init_schema();
3022
- init_geoarrow_builder();
3023
- DEFAULT_GEOMETRY_COLUMN_NAME = "geometry";
3024
- DEFAULT_GEO_METADATA_VERSION2 = "1.1.0";
3025
- GEOJSON_CRS_METADATA_KEY = "geojson_crs";
3026
- GEOARROW_EXTENSION_METADATA_KEY = "ARROW:extension:metadata";
3027
- CRS84_PROJJSON = {
3028
- $schema: "https://proj.org/schemas/v0.7/projjson.schema.json",
3029
- type: "GeographicCRS",
3030
- name: "WGS 84 longitude-latitude",
3031
- datum_ensemble: {
3032
- name: "World Geodetic System 1984 ensemble",
3033
- members: [
3034
- { name: "World Geodetic System 1984 (Transit)" },
3035
- { name: "World Geodetic System 1984 (G730)" },
3036
- { name: "World Geodetic System 1984 (G873)" },
3037
- { name: "World Geodetic System 1984 (G1150)" },
3038
- { name: "World Geodetic System 1984 (G1674)" },
3039
- { name: "World Geodetic System 1984 (G1762)" },
3040
- { name: "World Geodetic System 1984 (G2139)" }
3041
- ],
3042
- ellipsoid: {
3043
- name: "WGS 84",
3044
- semi_major_axis: 6378137,
3045
- inverse_flattening: 298.257223563
3046
- },
3047
- accuracy: "2.0",
3048
- id: {
3049
- authority: "EPSG",
3050
- code: 6326
3051
- }
3052
- },
3053
- coordinate_system: {
3054
- subtype: "ellipsoidal",
3055
- axis: [
3056
- {
3057
- name: "Geodetic longitude",
3058
- abbreviation: "Lon",
3059
- direction: "east",
3060
- unit: "degree"
3061
- },
3062
- {
3063
- name: "Geodetic latitude",
3064
- abbreviation: "Lat",
3065
- direction: "north",
3066
- unit: "degree"
3067
- }
3068
- ]
3069
- },
3070
- id: {
3071
- authority: "OGC",
3072
- code: "CRS84"
3073
- }
3074
- };
3075
- EPSG_4326_PROJJSON = {
3076
- ...CRS84_PROJJSON,
3077
- name: "WGS 84",
3078
- coordinate_system: {
3079
- subtype: "ellipsoidal",
3080
- axis: [
3081
- {
3082
- name: "Geodetic latitude",
3083
- abbreviation: "Lat",
3084
- direction: "north",
3085
- unit: "degree"
3086
- },
3087
- {
3088
- name: "Geodetic longitude",
3089
- abbreviation: "Lon",
3090
- direction: "east",
3091
- unit: "degree"
3092
- }
3093
- ]
3094
- },
3095
- id: {
3096
- authority: "EPSG",
3097
- code: 4326
3098
- }
3099
- };
3100
- }
3101
- });
3102
-
3103
- // src/geopackage/geopackage-loader-options.ts
3104
- var SQL_JS_VERSION2, DEFAULT_SQLJS_CDN2;
3105
- var init_geopackage_loader_options = __esm({
3106
- "src/geopackage/geopackage-loader-options.ts"() {
3107
- "use strict";
3108
- init_loader_utils();
3109
- SQL_JS_VERSION2 = "1.14.1";
3110
- DEFAULT_SQLJS_CDN2 = isBrowser ? `https://cdn.jsdelivr.net/npm/sql.js@${SQL_JS_VERSION2}/dist/` : null;
3111
- }
3112
- });
3113
-
3114
- // src/geopackage/lib/parse-geopackage.ts
3115
- async function parseGeoPackage(arrayBuffer, options) {
3116
- var _a, _b, _c;
3117
- const shape = ((_a = options == null ? void 0 : options.geopackage) == null ? void 0 : _a.shape) || "arrow-table";
3118
- if (shape === "arrow-table") {
3119
- return parseGeoPackageToArrow(arrayBuffer, options);
3120
- }
3121
- const database = await loadGeoPackageDatabase(
3122
- arrayBuffer,
3123
- ((_b = options == null ? void 0 : options.geopackage) == null ? void 0 : _b.sqlJsCDN) ?? DEFAULT_SQLJS_CDN2
3124
- );
3125
- const vectorTables = listGeoPackageVectorTables(database);
3126
- const projections = getProjections(database);
3127
- const { reproject = false, targetCrs = "WGS84" } = (options == null ? void 0 : options.gis) || {};
3128
- switch (shape) {
3129
- case "geojson-table": {
3130
- const selectedTable = selectGeoPackageVectorTable(vectorTables, (_c = options == null ? void 0 : options.geopackage) == null ? void 0 : _c.table);
3131
- return getGeoPackageGeoJSONTable(database, selectedTable, projections, {
3132
- reproject,
3133
- targetCrs
3134
- });
3135
- }
3136
- default:
3137
- throw new Error(`Unsupported GeoPackage output shape: ${shape}`);
3138
- }
3139
- }
3140
- async function parseGeoPackageToArrow(arrayBuffer, options) {
3141
- var _a, _b, _c, _d, _e;
3142
- const database = await loadGeoPackageDatabase(
3143
- arrayBuffer,
3144
- ((_a = options == null ? void 0 : options.geopackage) == null ? void 0 : _a.sqlJsCDN) ?? DEFAULT_SQLJS_CDN2
3145
- );
3146
- const vectorTables = listGeoPackageVectorTables(database);
3147
- const selectedTable = selectGeoPackageVectorTable(vectorTables, (_b = options == null ? void 0 : options.geopackage) == null ? void 0 : _b.table);
3148
- const projections = getProjections(database);
3149
- const { reproject = false, targetCrs = "WGS84" } = (options == null ? void 0 : options.gis) || {};
3150
- const preference = ((_c = options == null ? void 0 : options.geoarrow) == null ? void 0 : _c.encodingPreference) || ((_e = (_d = options == null ? void 0 : options.geopackage) == null ? void 0 : _d.geoarrow) == null ? void 0 : _e.encodingPreference);
3151
- if (preference && preference !== "geoarrow.wkb") {
3152
- const geoJSONTable = getGeoPackageGeoJSONTable(database, selectedTable, projections, {
3153
- reproject,
3154
- targetCrs
3155
- });
3156
- return convertFeaturesToGeoArrowTable(geoJSONTable.features, {
3157
- encodingPreference: preference
3158
- });
3159
- }
3160
- return getGeoPackageArrowTable(database, selectedTable, projections, {
3161
- reproject,
3162
- targetCrs
3163
- });
3164
- }
3165
- async function loadGeoPackageDatabase(arrayBuffer, sqlJsCDN) {
3166
- let sql;
3167
- if (sqlJsCDN) {
3168
- sql = await (0, import_sql.default)({
3169
- locateFile: (fileName) => `${sqlJsCDN}${fileName}`
3170
- });
3171
- } else {
3172
- sql = await (0, import_sql.default)();
3173
- }
3174
- return new sql.Database(new Uint8Array(arrayBuffer));
3175
- }
3176
- function listGeoPackageVectorTables(database) {
3177
- if (!database.exec(
3178
- "SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'gpkg_geometry_columns'"
3179
- ).length)
3180
- return [];
3181
- const statement = database.prepare(`
3182
- SELECT
3183
- gpkg_contents.table_name,
3184
- gpkg_contents.identifier,
3185
- gpkg_contents.description,
3186
- gpkg_contents.last_change,
3187
- gpkg_contents.min_x,
3188
- gpkg_contents.min_y,
3189
- gpkg_contents.max_x,
3190
- gpkg_contents.max_y,
3191
- gpkg_contents.srs_id,
3192
- gpkg_geometry_columns.column_name,
3193
- gpkg_geometry_columns.geometry_type_name,
3194
- gpkg_geometry_columns.z,
3195
- gpkg_geometry_columns.m
3196
- FROM gpkg_contents
3197
- INNER JOIN gpkg_geometry_columns
3198
- ON gpkg_contents.table_name = gpkg_geometry_columns.table_name
3199
- WHERE gpkg_contents.data_type='features';
3200
- `);
3201
- const vectorTables = [];
3202
- while (statement.step()) {
3203
- const row = statement.getAsObject();
3204
- const bounds = getGeoPackageBounds(row);
3205
- vectorTables.push({
3206
- name: String(row.table_name),
3207
- identifier: normalizeOptionalString(row.identifier),
3208
- description: normalizeOptionalString(row.description),
3209
- lastChange: String(row.last_change),
3210
- srsId: normalizeOptionalNumber(row.srs_id),
3211
- geometryColumnName: String(row.column_name),
3212
- geometryTypeName: String(row.geometry_type_name),
3213
- z: Number(row.z),
3214
- m: Number(row.m),
3215
- bounds
3216
- });
3217
- }
3218
- return vectorTables;
3219
- }
3220
- function selectGeoPackageVectorTable(vectorTables, tableName) {
3221
- if (!vectorTables.length) {
3222
- throw new Error("GeoPackage contains no vector feature tables.");
3223
- }
3224
- if (tableName) {
3225
- const selectedTable = vectorTables.find((vectorTable) => vectorTable.name === tableName);
3226
- if (!selectedTable) {
3227
- throw new Error(`GeoPackage table not found: ${tableName}`);
3228
- }
3229
- return selectedTable;
3230
- }
3231
- if (vectorTables.length === 1) {
3232
- return vectorTables[0];
3233
- }
3234
- const preferredTable = vectorTables.find(
3235
- (vectorTable) => isDefaultTableMarker(vectorTable.identifier) || isDefaultTableMarker(vectorTable.name)
3236
- );
3237
- return preferredTable || vectorTables[0];
3238
- }
3239
- function getGeoPackageGeoJSONTable(database, vectorTable, projections, options) {
3240
- const dataColumns = getDataColumns(database, vectorTable.name);
3241
- const featureIdColumn = getFeatureIdName(database, vectorTable.name);
3242
- const queryResult = database.exec(`SELECT * FROM \`${vectorTable.name}\`;`)[0];
3243
- const columns = (queryResult == null ? void 0 : queryResult.columns) || [];
3244
- const values = (queryResult == null ? void 0 : queryResult.values) || [];
3245
- const projection = getProjection(vectorTable, projections, options);
3246
- const geojsonFeatures = values.map(
3247
- (row) => constructGeoJsonFeature(columns, row, vectorTable, dataColumns, featureIdColumn, projection)
3248
- );
3249
- return {
3250
- shape: "geojson-table",
3251
- schema: getSchema(database, vectorTable.name),
3252
- type: "FeatureCollection",
3253
- // @ts-expect-error TODO - null geometries causing problems...
3254
- features: geojsonFeatures
3255
- };
3256
- }
3257
- function getGeoPackageArrowTable(database, vectorTable, projections, options) {
3258
- const queryResult = database.exec(`SELECT * FROM \`${vectorTable.name}\`;`)[0];
3259
- const columns = (queryResult == null ? void 0 : queryResult.columns) || [];
3260
- const values = (queryResult == null ? void 0 : queryResult.values) || [];
3261
- const projection = getProjection(vectorTable, projections, options);
3262
- const outputCrs = options.reproject ? options.targetCrs : vectorTable.srsId === void 0 ? void 0 : projections[vectorTable.srsId];
3263
- const schema = getGeoPackageArrowSchema(database, vectorTable, outputCrs);
3264
- const tableBuilder = new ArrowTableBuilder(schema);
3265
- for (const row of values) {
3266
- tableBuilder.addObjectRow(
3267
- constructArrowRow(columns, row, vectorTable.geometryColumnName, projection)
3268
- );
3269
- }
3270
- return tableBuilder.finishTable();
3271
- }
3272
- function getProjections(database) {
3273
- const statement = database.prepare("SELECT * FROM gpkg_spatial_ref_sys;");
3274
- const projectionMapping = {};
3275
- while (statement.step()) {
3276
- const projectionRow = statement.getAsObject();
3277
- const definition = getSpatialReferenceSystemDefinition(projectionRow);
3278
- if (definition) {
3279
- projectionMapping[projectionRow.srs_id] = definition;
3280
- }
3281
- }
3282
- return projectionMapping;
3283
- }
3284
- function getSpatialReferenceSystemDefinition(spatialReferenceSystem) {
3285
- const definition = spatialReferenceSystem.definition_12_063 || spatialReferenceSystem.definition;
3286
- return definition && definition.trim().toLowerCase() !== "undefined" ? definition : void 0;
3287
- }
3288
- function constructGeoJsonFeature(columns, row, vectorTable, dataColumns, featureIdColumn, projection) {
3289
- const featureIdIndex = featureIdColumn ? columns.indexOf(featureIdColumn) : -1;
3290
- const geometryColumnIndex = columns.indexOf(vectorTable.geometryColumnName);
3291
- const rawGeometry = parseGeometry(row[geometryColumnIndex]);
3292
- const geometry = projection ? reprojectGeometry(rawGeometry, projection) : rawGeometry;
3293
- const properties = {};
3294
- if (dataColumns) {
3295
- for (const [columnName, propertyName] of Object.entries(dataColumns)) {
3296
- const columnIndex = columns.indexOf(columnName);
3297
- const outputName = propertyName || columnName;
3298
- properties[outputName] = row[columnIndex];
3299
- }
3300
- } else {
3301
- for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
3302
- if (columnIndex === featureIdIndex || columnIndex === geometryColumnIndex) {
3303
- continue;
3304
- }
3305
- properties[columns[columnIndex]] = row[columnIndex];
3306
- }
3307
- }
3308
- return {
3309
- id: featureIdIndex >= 0 && (typeof row[featureIdIndex] === "string" || typeof row[featureIdIndex] === "number") ? row[featureIdIndex] : void 0,
3310
- type: "Feature",
3311
- geometry,
3312
- properties
3313
- };
3314
- }
3315
- function constructArrowRow(columns, row, geometryColumnName, projection) {
3316
- const arrowRow = {};
3317
- for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
3318
- const columnName = columns[columnIndex];
3319
- const value = row[columnIndex];
3320
- if (columnName === geometryColumnName) {
3321
- const wkb = parseGeometryWKB(value);
3322
- if (wkb && projection) {
3323
- reprojectWKBInPlace(wkb, (coordinate) => projection.projectSync(coordinate));
3324
- }
3325
- arrowRow[GEOMETRY_OUTPUT_COLUMN_NAME] = wkb;
3326
- continue;
3327
- }
3328
- arrowRow[columnName] = value;
3329
- }
3330
- return arrowRow;
3331
- }
3332
- function getProjection(vectorTable, projections, options) {
3333
- if (!options.reproject) {
3334
- return null;
3335
- }
3336
- if (vectorTable.srsId === void 0) {
3337
- throw new CRSReprojectionError(
3338
- "missing-source-crs",
3339
- `GeoPackage reprojection requires a source CRS identifier for table "${vectorTable.name}"`,
3340
- { targetCrs: options.targetCrs }
3341
- );
3342
- }
3343
- const sourceProjection = projections[vectorTable.srsId];
3344
- if (!sourceProjection) {
3345
- throw new CRSReprojectionError(
3346
- "missing-source-crs",
3347
- `GeoPackage reprojection requires a defined source CRS for SRS ${vectorTable.srsId}`,
3348
- { targetCrs: options.targetCrs }
3349
- );
3350
- }
3351
- try {
3352
- return import_projection.projectionEngine.createProjection({
3353
- from: getProjectionDefinition(sourceProjection),
3354
- to: options.targetCrs
3355
- });
3356
- } catch (error) {
3357
- const message = error instanceof Error ? error.message : String(error);
3358
- throw new CRSReprojectionError(
3359
- "transformation-failed",
3360
- `GeoPackage reprojection failed: ${message}`,
3361
- { sourceCrs: sourceProjection, targetCrs: options.targetCrs, cause: error }
3362
- );
3363
- }
3364
- }
3365
- function getProjectionDefinition(definition) {
3366
- var _a, _b;
3367
- if (/^\s*PROJCS\s*\[/i.test(definition) && /EXTENSION\s*\[\s*"PROJ4"/i.test(definition)) {
3368
- const { root } = (0, import_crs2.parseWKTCRS)(definition);
3369
- const authority = root.values.find(
3370
- (value) => value.type === "node" && value.keyword.toUpperCase() === "AUTHORITY"
3371
- );
3372
- if ((authority == null ? void 0 : authority.type) === "node" && ((_a = authority.values[0]) == null ? void 0 : _a.type) === "string" && authority.values[0].value.toUpperCase() === "EPSG" && ((_b = authority.values[1]) == null ? void 0 : _b.type) === "string" && authority.values[1].value === "3857") {
3373
- return "EPSG:3857";
3374
- }
3375
- }
3376
- return definition;
3377
- }
3378
- function reprojectGeometry(geometry, projection) {
3379
- if (!geometry) {
3380
- return null;
3381
- }
3382
- const feature = { type: "Feature", geometry, properties: {} };
3383
- return transformGeoJsonCoords([feature], (coordinate) => projection.projectSync(coordinate))[0].geometry;
3384
- }
3385
- function parseGeometry(geometryValue) {
3386
- const wkb = parseGeometryWKB(geometryValue);
3387
- return wkb ? convertWKBToGeometry(wkb.buffer.slice(wkb.byteOffset, wkb.byteOffset + wkb.byteLength)) : null;
3388
- }
3389
- function parseGeometryWKB(geometryValue) {
3390
- if (!geometryValue) {
3391
- return null;
3392
- }
3393
- const arrayBuffer = getArrayBufferFromValue(geometryValue);
3394
- const view = new DataView(arrayBuffer);
3395
- const { envelopeLength, emptyGeometry } = parseGeometryBitFlags(view.getUint8(3));
3396
- if (emptyGeometry) {
3397
- return null;
3398
- }
3399
- const wkbOffset = 8 + envelopeLength;
3400
- return new Uint8Array(arrayBuffer, wkbOffset);
3401
- }
3402
- function parseGeometryBitFlags(byte) {
3403
- const envelopeValue = (byte & 14) / 2;
3404
- const envelopeLength = ENVELOPE_BYTE_LENGTHS[envelopeValue];
3405
- return {
3406
- littleEndian: Boolean(byte & 1),
3407
- envelopeLength,
3408
- emptyGeometry: Boolean(byte & 16),
3409
- extendedGeometryType: Boolean(byte & 32)
3410
- };
3411
- }
3412
- function getFeatureIdName(database, tableName) {
3413
- const statement = database.prepare(`PRAGMA table_info(\`${tableName}\`)`);
3414
- while (statement.step()) {
3415
- const pragmaTableInfo = statement.getAsObject();
3416
- if (pragmaTableInfo.pk) {
3417
- return pragmaTableInfo.name;
3418
- }
3419
- }
3420
- return null;
3421
- }
3422
- function getDataColumns(database, tableName) {
3423
- let statement;
3424
- try {
3425
- statement = database.prepare("SELECT * FROM gpkg_data_columns WHERE table_name=:tableName;");
3426
- } catch (error) {
3427
- if (error.message.includes("no such table")) {
3428
- return null;
3429
- }
3430
- throw error;
3431
- }
3432
- statement.bind({ ":tableName": tableName });
3433
- const dataColumns = {};
3434
- while (statement.step()) {
3435
- const column = statement.getAsObject();
3436
- dataColumns[column.column_name] = column.name || null;
3437
- }
3438
- return dataColumns;
3439
- }
3440
- function getSchema(database, tableName) {
3441
- const statement = database.prepare(`PRAGMA table_info(\`${tableName}\`)`);
3442
- const fields = [];
3443
- while (statement.step()) {
3444
- const pragmaTableInfo = statement.getAsObject();
3445
- fields.push({
3446
- name: pragmaTableInfo.name,
3447
- type: getSqliteFieldType(pragmaTableInfo.type),
3448
- nullable: !pragmaTableInfo.notnull
3449
- });
3450
- }
3451
- return { fields, metadata: {} };
3452
- }
3453
- function getGeoPackageArrowSchema(database, vectorTable, crs) {
3454
- const statement = database.prepare(`PRAGMA table_info(\`${vectorTable.name}\`)`);
3455
- const fields = [];
3456
- while (statement.step()) {
3457
- const pragmaTableInfo = statement.getAsObject();
3458
- if (pragmaTableInfo.name === vectorTable.geometryColumnName) {
3459
- continue;
3460
- }
3461
- fields.push({
3462
- name: pragmaTableInfo.name,
3463
- type: getSqliteFieldType(pragmaTableInfo.type),
3464
- nullable: !pragmaTableInfo.notnull
3465
- });
3466
- }
3467
- const geometryField = makeWKBGeometryField(GEOMETRY_OUTPUT_COLUMN_NAME);
3468
- if (crs) {
3469
- geometryField.metadata["ARROW:extension:metadata"] = JSON.stringify(
3470
- getGeoArrowCrsMetadata(crs)
3471
- );
3472
- }
3473
- fields.push(geometryField);
3474
- const schema = { fields, metadata: {} };
3475
- setWKBGeometrySchemaMetadata(schema, {
3476
- geometryColumnName: GEOMETRY_OUTPUT_COLUMN_NAME,
3477
- geometryTypes: [getGeoMetadataGeometryType(vectorTable)]
3478
- });
3479
- return schema;
3480
- }
3481
- function getGeoArrowCrsMetadata(crs) {
3482
- if (typeof crs !== "string") {
3483
- return { crs, crs_type: "projjson" };
3484
- }
3485
- if (/^[A-Za-z][A-Za-z0-9_.-]*:[^\s]+$/.test(crs)) {
3486
- return { crs, crs_type: "authority_code" };
3487
- }
3488
- return { crs };
3489
- }
3490
- function getGeoMetadataGeometryType(vectorTable) {
3491
- const geometryTypeNameMap = {
3492
- GEOMETRY: "Geometry",
3493
- POINT: "Point",
3494
- LINESTRING: "LineString",
3495
- POLYGON: "Polygon",
3496
- MULTIPOINT: "MultiPoint",
3497
- MULTILINESTRING: "MultiLineString",
3498
- MULTIPOLYGON: "MultiPolygon",
3499
- GEOMETRYCOLLECTION: "GeometryCollection"
3500
- };
3501
- const geometryType = geometryTypeNameMap[vectorTable.geometryTypeName] || "Geometry";
3502
- return vectorTable.z > 0 ? `${geometryType} Z` : geometryType;
3503
- }
3504
- function getSqliteFieldType(sqliteType) {
3505
- const normalizedType = (sqliteType || "TEXT").toUpperCase();
3506
- return SQL_TYPE_MAPPING[normalizedType] || "utf8";
3507
- }
3508
- function getGeoPackageBounds(row) {
3509
- const minX = normalizeOptionalNumber(row.min_x);
3510
- const minY = normalizeOptionalNumber(row.min_y);
3511
- const maxX = normalizeOptionalNumber(row.max_x);
3512
- const maxY = normalizeOptionalNumber(row.max_y);
3513
- if (minX === void 0 || minY === void 0 || maxX === void 0 || maxY === void 0) {
3514
- return void 0;
3515
- }
3516
- return { minX, minY, maxX, maxY };
3517
- }
3518
- function isDefaultTableMarker(value) {
3519
- if (!value) {
3520
- return false;
3521
- }
3522
- const normalizedValue = value.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
3523
- return DEFAULT_TABLE_MARKERS.has(normalizedValue);
3524
- }
3525
- function getArrayBufferFromValue(value) {
3526
- if (value instanceof ArrayBuffer) {
3527
- return value;
3528
- }
3529
- if (ArrayBuffer.isView(value)) {
3530
- return value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
3531
- }
3532
- throw new Error("Expected GeoPackage geometry column to contain binary data.");
3533
- }
3534
- function normalizeOptionalString(value) {
3535
- return typeof value === "string" && value.length ? value : void 0;
3536
- }
3537
- function normalizeOptionalNumber(value) {
3538
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
3539
- }
3540
- var import_projection, import_crs2, import_sql, GEOMETRY_OUTPUT_COLUMN_NAME, ENVELOPE_BYTE_LENGTHS, SQL_TYPE_MAPPING, DEFAULT_TABLE_MARKERS;
3541
- var init_parse_geopackage = __esm({
3542
- "src/geopackage/lib/parse-geopackage.ts"() {
3543
- "use strict";
3544
- init_loader_utils();
3545
- init_schema_utils();
3546
- init_geometry_field();
3547
- init_geometry_codecs();
3548
- init_binary_geometry_to_wkb();
3549
- init_legacy_binary();
3550
- init_feature_table();
3551
- import_projection = require("@math.gl/geospatial/projection");
3552
- import_crs2 = require("@math.gl/geospatial/crs");
3553
- import_sql = __toESM(require("sql.js"), 1);
3554
- init_geopackage_loader_options();
3555
- GEOMETRY_OUTPUT_COLUMN_NAME = "geometry";
3556
- ENVELOPE_BYTE_LENGTHS = {
3557
- 0: 0,
3558
- 1: 32,
3559
- 2: 48,
3560
- 3: 48,
3561
- 4: 64,
3562
- 5: 0,
3563
- 6: 0,
3564
- 7: 0
3565
- };
3566
- SQL_TYPE_MAPPING = {
3567
- BOOLEAN: "bool",
3568
- TINYINT: "int8",
3569
- SMALLINT: "int16",
3570
- MEDIUMINT: "int32",
3571
- INT: "int32",
3572
- INTEGER: "int32",
3573
- FLOAT: "float32",
3574
- DOUBLE: "float64",
3575
- REAL: "float64",
3576
- TEXT: "utf8",
3577
- BLOB: "binary",
3578
- DATE: "utf8",
3579
- DATETIME: "utf8",
3580
- GEOMETRY: "binary",
3581
- POINT: "binary",
3582
- LINESTRING: "binary",
3583
- POLYGON: "binary",
3584
- MULTIPOINT: "binary",
3585
- MULTILINESTRING: "binary",
3586
- MULTIPOLYGON: "binary",
3587
- GEOMETRYCOLLECTION: "binary"
3588
- };
3589
- DEFAULT_TABLE_MARKERS = /* @__PURE__ */ new Set(["default", "default table", "main", "primary"]);
3590
- }
3591
- });
3592
-
3593
- // src/geopackage/geopackage-format.ts
3594
- var GeoPackageFormat2;
3595
- var init_geopackage_format = __esm({
3596
- "src/geopackage/geopackage-format.ts"() {
3597
- "use strict";
3598
- GeoPackageFormat2 = {
3599
- id: "geopackage",
3600
- name: "GeoPackage",
3601
- module: "geospatial",
3602
- encoding: "sqlite",
3603
- format: "geopackage",
3604
- extensions: ["gpkg"],
3605
- mimeTypes: ["application/geopackage+sqlite3"],
3606
- category: "geometry"
3607
- };
3608
- }
3609
- });
3610
-
3611
- // src/geopackage/geopackage-loader-types.ts
3612
- async function preload() {
3613
- const { GeoPackageLoaderWithParser: GeoPackageLoaderWithParser2 } = await Promise.resolve().then(() => (init_geopackage_loader(), geopackage_loader_exports));
3614
- return GeoPackageLoaderWithParser2;
3615
- }
3616
- var VERSION2, GeoPackageLoader;
3617
- var init_geopackage_loader_types = __esm({
3618
- "src/geopackage/geopackage-loader-types.ts"() {
3619
- "use strict";
3620
- init_geopackage_loader_options();
3621
- init_geopackage_format();
3622
- VERSION2 = "latest";
3623
- GeoPackageLoader = {
3624
- ...GeoPackageFormat2,
3625
- dataType: null,
3626
- batchType: null,
3627
- version: VERSION2,
3628
- options: {
3629
- geopackage: {
3630
- sqlJsCDN: DEFAULT_SQLJS_CDN2,
3631
- shape: "arrow-table"
3632
- },
3633
- gis: {}
3634
- },
3635
- preload
3636
- };
3637
- }
3638
- });
3639
-
3640
- // src/geopackage/geopackage-loader.ts
3641
- var geopackage_loader_exports = {};
3642
- __export(geopackage_loader_exports, {
3643
- GeoPackageLoaderWithParser: () => GeoPackageLoaderWithParser
20
+ // src/geopackage/index.ts
21
+ var geopackage_exports = {};
22
+ __export(geopackage_exports, {
23
+ GeoPackageDataSource: () => import_geopackage_source_loader.GeoPackageDataSource,
24
+ GeoPackageFormat: () => import_geopackage_format.GeoPackageFormat,
25
+ GeoPackageLoader: () => import_geopackage_loader_types.GeoPackageLoader
26
+ });
27
+ module.exports = __toCommonJS(geopackage_exports);
28
+ var import_geopackage_format = require("./geopackage-format.cjs");
29
+ var import_geopackage_loader_types = require("./geopackage-loader-types.cjs");
30
+ var import_geopackage_source_loader = require("./geopackage-source-loader.cjs");
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ GeoPackageDataSource,
34
+ GeoPackageFormat,
35
+ GeoPackageLoader
3644
36
  });
3645
- var _GeoPackageLoaderPreload, GeoPackageLoaderMetadataWithoutPreload, GeoPackageLoaderWithParser;
3646
- var init_geopackage_loader = __esm({
3647
- "src/geopackage/geopackage-loader.ts"() {
3648
- "use strict";
3649
- init_parse_geopackage();
3650
- init_geopackage_loader_types();
3651
- ({ preload: _GeoPackageLoaderPreload, ...GeoPackageLoaderMetadataWithoutPreload } = GeoPackageLoader);
3652
- GeoPackageLoaderWithParser = {
3653
- ...GeoPackageLoaderMetadataWithoutPreload,
3654
- parse: parseGeoPackage
3655
- };
3656
- }
3657
- });
3658
-
3659
- // dist/geopackage/index.js
3660
- var index_exports = {};
3661
- __export(index_exports, {
3662
- GeoPackageDataSource: () => GeoPackageDataSource,
3663
- GeoPackageFormat: () => GeoPackageFormat,
3664
- GeoPackageLoader: () => GeoPackageLoader2,
3665
- GeoPackageSource: () => GeoPackageSource
3666
- });
3667
- module.exports = __toCommonJS(index_exports);
3668
-
3669
- // dist/geopackage/geopackage-format.js
3670
- var GeoPackageFormat = {
3671
- id: "geopackage",
3672
- name: "GeoPackage",
3673
- module: "geospatial",
3674
- encoding: "sqlite",
3675
- format: "geopackage",
3676
- extensions: ["gpkg"],
3677
- mimeTypes: ["application/geopackage+sqlite3"],
3678
- category: "geometry"
3679
- };
3680
-
3681
- // dist/geopackage/geopackage-loader-options.js
3682
- init_loader_utils();
3683
- var SQL_JS_VERSION = "1.14.1";
3684
- var DEFAULT_SQLJS_CDN = isBrowser ? `https://cdn.jsdelivr.net/npm/sql.js@${SQL_JS_VERSION}/dist/` : null;
3685
-
3686
- // dist/geopackage/geopackage-loader-types.js
3687
- var VERSION3 = "latest";
3688
- async function preload2() {
3689
- const { GeoPackageLoaderWithParser: GeoPackageLoaderWithParser2 } = await Promise.resolve().then(() => (init_geopackage_loader(), geopackage_loader_exports));
3690
- return GeoPackageLoaderWithParser2;
3691
- }
3692
- var GeoPackageLoader2 = {
3693
- ...GeoPackageFormat,
3694
- dataType: null,
3695
- batchType: null,
3696
- version: VERSION3,
3697
- options: {
3698
- geopackage: {
3699
- sqlJsCDN: DEFAULT_SQLJS_CDN,
3700
- shape: "arrow-table"
3701
- },
3702
- gis: {}
3703
- },
3704
- preload: preload2
3705
- };
3706
-
3707
- // dist/geopackage/geopackage-source-loader.js
3708
- init_loader_utils();
3709
- init_schema_utils();
3710
-
3711
- // dist/geopackage/lib/parse-geopackage.js
3712
- init_loader_utils();
3713
- init_schema_utils();
3714
- init_geometry_field();
3715
- init_geometry_codecs();
3716
- init_binary_geometry_to_wkb();
3717
- init_legacy_binary();
3718
- init_feature_table();
3719
- var import_projection2 = require("@math.gl/geospatial/projection");
3720
- var import_crs3 = require("@math.gl/geospatial/crs");
3721
- var import_sql2 = __toESM(require("sql.js"), 1);
3722
- var GEOMETRY_OUTPUT_COLUMN_NAME2 = "geometry";
3723
- var ENVELOPE_BYTE_LENGTHS2 = {
3724
- 0: 0,
3725
- 1: 32,
3726
- 2: 48,
3727
- 3: 48,
3728
- 4: 64,
3729
- 5: 0,
3730
- 6: 0,
3731
- 7: 0
3732
- };
3733
- var SQL_TYPE_MAPPING2 = {
3734
- BOOLEAN: "bool",
3735
- TINYINT: "int8",
3736
- SMALLINT: "int16",
3737
- MEDIUMINT: "int32",
3738
- INT: "int32",
3739
- INTEGER: "int32",
3740
- FLOAT: "float32",
3741
- DOUBLE: "float64",
3742
- REAL: "float64",
3743
- TEXT: "utf8",
3744
- BLOB: "binary",
3745
- DATE: "utf8",
3746
- DATETIME: "utf8",
3747
- GEOMETRY: "binary",
3748
- POINT: "binary",
3749
- LINESTRING: "binary",
3750
- POLYGON: "binary",
3751
- MULTIPOINT: "binary",
3752
- MULTILINESTRING: "binary",
3753
- MULTIPOLYGON: "binary",
3754
- GEOMETRYCOLLECTION: "binary"
3755
- };
3756
- var DEFAULT_TABLE_MARKERS2 = /* @__PURE__ */ new Set(["default", "default table", "main", "primary"]);
3757
- async function parseGeoPackageToArrow2(arrayBuffer, options) {
3758
- var _a, _b, _c, _d, _e;
3759
- const database = await loadGeoPackageDatabase2(arrayBuffer, ((_a = options == null ? void 0 : options.geopackage) == null ? void 0 : _a.sqlJsCDN) ?? DEFAULT_SQLJS_CDN);
3760
- const vectorTables = listGeoPackageVectorTables2(database);
3761
- const selectedTable = selectGeoPackageVectorTable2(vectorTables, (_b = options == null ? void 0 : options.geopackage) == null ? void 0 : _b.table);
3762
- const projections = getProjections2(database);
3763
- const { reproject = false, targetCrs = "WGS84" } = (options == null ? void 0 : options.gis) || {};
3764
- const preference = ((_c = options == null ? void 0 : options.geoarrow) == null ? void 0 : _c.encodingPreference) || ((_e = (_d = options == null ? void 0 : options.geopackage) == null ? void 0 : _d.geoarrow) == null ? void 0 : _e.encodingPreference);
3765
- if (preference && preference !== "geoarrow.wkb") {
3766
- const geoJSONTable = getGeoPackageGeoJSONTable2(database, selectedTable, projections, {
3767
- reproject,
3768
- targetCrs
3769
- });
3770
- return convertFeaturesToGeoArrowTable(geoJSONTable.features, {
3771
- encodingPreference: preference
3772
- });
3773
- }
3774
- return getGeoPackageArrowTable2(database, selectedTable, projections, {
3775
- reproject,
3776
- targetCrs
3777
- });
3778
- }
3779
- async function loadGeoPackageDatabase2(arrayBuffer, sqlJsCDN) {
3780
- let sql;
3781
- if (sqlJsCDN) {
3782
- sql = await (0, import_sql2.default)({
3783
- locateFile: (fileName) => `${sqlJsCDN}${fileName}`
3784
- });
3785
- } else {
3786
- sql = await (0, import_sql2.default)();
3787
- }
3788
- return new sql.Database(new Uint8Array(arrayBuffer));
3789
- }
3790
- function listGeoPackageVectorTables2(database) {
3791
- if (!database.exec("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'gpkg_geometry_columns'").length)
3792
- return [];
3793
- const statement = database.prepare(`
3794
- SELECT
3795
- gpkg_contents.table_name,
3796
- gpkg_contents.identifier,
3797
- gpkg_contents.description,
3798
- gpkg_contents.last_change,
3799
- gpkg_contents.min_x,
3800
- gpkg_contents.min_y,
3801
- gpkg_contents.max_x,
3802
- gpkg_contents.max_y,
3803
- gpkg_contents.srs_id,
3804
- gpkg_geometry_columns.column_name,
3805
- gpkg_geometry_columns.geometry_type_name,
3806
- gpkg_geometry_columns.z,
3807
- gpkg_geometry_columns.m
3808
- FROM gpkg_contents
3809
- INNER JOIN gpkg_geometry_columns
3810
- ON gpkg_contents.table_name = gpkg_geometry_columns.table_name
3811
- WHERE gpkg_contents.data_type='features';
3812
- `);
3813
- const vectorTables = [];
3814
- while (statement.step()) {
3815
- const row = statement.getAsObject();
3816
- const bounds = getGeoPackageBounds2(row);
3817
- vectorTables.push({
3818
- name: String(row.table_name),
3819
- identifier: normalizeOptionalString2(row.identifier),
3820
- description: normalizeOptionalString2(row.description),
3821
- lastChange: String(row.last_change),
3822
- srsId: normalizeOptionalNumber2(row.srs_id),
3823
- geometryColumnName: String(row.column_name),
3824
- geometryTypeName: String(row.geometry_type_name),
3825
- z: Number(row.z),
3826
- m: Number(row.m),
3827
- bounds
3828
- });
3829
- }
3830
- return vectorTables;
3831
- }
3832
- function selectGeoPackageVectorTable2(vectorTables, tableName) {
3833
- if (!vectorTables.length) {
3834
- throw new Error("GeoPackage contains no vector feature tables.");
3835
- }
3836
- if (tableName) {
3837
- const selectedTable = vectorTables.find((vectorTable) => vectorTable.name === tableName);
3838
- if (!selectedTable) {
3839
- throw new Error(`GeoPackage table not found: ${tableName}`);
3840
- }
3841
- return selectedTable;
3842
- }
3843
- if (vectorTables.length === 1) {
3844
- return vectorTables[0];
3845
- }
3846
- const preferredTable = vectorTables.find((vectorTable) => isDefaultTableMarker2(vectorTable.identifier) || isDefaultTableMarker2(vectorTable.name));
3847
- return preferredTable || vectorTables[0];
3848
- }
3849
- function getGeoPackageGeoJSONTable2(database, vectorTable, projections, options) {
3850
- const dataColumns = getDataColumns2(database, vectorTable.name);
3851
- const featureIdColumn = getFeatureIdName2(database, vectorTable.name);
3852
- const queryResult = database.exec(`SELECT * FROM \`${vectorTable.name}\`;`)[0];
3853
- const columns = (queryResult == null ? void 0 : queryResult.columns) || [];
3854
- const values = (queryResult == null ? void 0 : queryResult.values) || [];
3855
- const projection = getProjection2(vectorTable, projections, options);
3856
- const geojsonFeatures = values.map((row) => constructGeoJsonFeature2(columns, row, vectorTable, dataColumns, featureIdColumn, projection));
3857
- return {
3858
- shape: "geojson-table",
3859
- schema: getSchema2(database, vectorTable.name),
3860
- type: "FeatureCollection",
3861
- // @ts-expect-error TODO - null geometries causing problems...
3862
- features: geojsonFeatures
3863
- };
3864
- }
3865
- function getGeoPackageArrowTable2(database, vectorTable, projections, options) {
3866
- const queryResult = database.exec(`SELECT * FROM \`${vectorTable.name}\`;`)[0];
3867
- const columns = (queryResult == null ? void 0 : queryResult.columns) || [];
3868
- const values = (queryResult == null ? void 0 : queryResult.values) || [];
3869
- const projection = getProjection2(vectorTable, projections, options);
3870
- const outputCrs = options.reproject ? options.targetCrs : vectorTable.srsId === void 0 ? void 0 : projections[vectorTable.srsId];
3871
- const schema = getGeoPackageArrowSchema2(database, vectorTable, outputCrs);
3872
- const tableBuilder = new ArrowTableBuilder(schema);
3873
- for (const row of values) {
3874
- tableBuilder.addObjectRow(constructArrowRow2(columns, row, vectorTable.geometryColumnName, projection));
3875
- }
3876
- return tableBuilder.finishTable();
3877
- }
3878
- function getProjections2(database) {
3879
- const statement = database.prepare("SELECT * FROM gpkg_spatial_ref_sys;");
3880
- const projectionMapping = {};
3881
- while (statement.step()) {
3882
- const projectionRow = statement.getAsObject();
3883
- const definition = getSpatialReferenceSystemDefinition2(projectionRow);
3884
- if (definition) {
3885
- projectionMapping[projectionRow.srs_id] = definition;
3886
- }
3887
- }
3888
- return projectionMapping;
3889
- }
3890
- function getSpatialReferenceSystemDefinition2(spatialReferenceSystem) {
3891
- const definition = spatialReferenceSystem.definition_12_063 || spatialReferenceSystem.definition;
3892
- return definition && definition.trim().toLowerCase() !== "undefined" ? definition : void 0;
3893
- }
3894
- function constructGeoJsonFeature2(columns, row, vectorTable, dataColumns, featureIdColumn, projection) {
3895
- const featureIdIndex = featureIdColumn ? columns.indexOf(featureIdColumn) : -1;
3896
- const geometryColumnIndex = columns.indexOf(vectorTable.geometryColumnName);
3897
- const rawGeometry = parseGeometry2(row[geometryColumnIndex]);
3898
- const geometry = projection ? reprojectGeometry2(rawGeometry, projection) : rawGeometry;
3899
- const properties = {};
3900
- if (dataColumns) {
3901
- for (const [columnName, propertyName] of Object.entries(dataColumns)) {
3902
- const columnIndex = columns.indexOf(columnName);
3903
- const outputName = propertyName || columnName;
3904
- properties[outputName] = row[columnIndex];
3905
- }
3906
- } else {
3907
- for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
3908
- if (columnIndex === featureIdIndex || columnIndex === geometryColumnIndex) {
3909
- continue;
3910
- }
3911
- properties[columns[columnIndex]] = row[columnIndex];
3912
- }
3913
- }
3914
- return {
3915
- id: featureIdIndex >= 0 && (typeof row[featureIdIndex] === "string" || typeof row[featureIdIndex] === "number") ? row[featureIdIndex] : void 0,
3916
- type: "Feature",
3917
- geometry,
3918
- properties
3919
- };
3920
- }
3921
- function constructArrowRow2(columns, row, geometryColumnName, projection) {
3922
- const arrowRow = {};
3923
- for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
3924
- const columnName = columns[columnIndex];
3925
- const value = row[columnIndex];
3926
- if (columnName === geometryColumnName) {
3927
- const wkb = parseGeometryWKB2(value);
3928
- if (wkb && projection) {
3929
- reprojectWKBInPlace(wkb, (coordinate) => projection.projectSync(coordinate));
3930
- }
3931
- arrowRow[GEOMETRY_OUTPUT_COLUMN_NAME2] = wkb;
3932
- continue;
3933
- }
3934
- arrowRow[columnName] = value;
3935
- }
3936
- return arrowRow;
3937
- }
3938
- function getProjection2(vectorTable, projections, options) {
3939
- if (!options.reproject) {
3940
- return null;
3941
- }
3942
- if (vectorTable.srsId === void 0) {
3943
- throw new CRSReprojectionError("missing-source-crs", `GeoPackage reprojection requires a source CRS identifier for table "${vectorTable.name}"`, { targetCrs: options.targetCrs });
3944
- }
3945
- const sourceProjection = projections[vectorTable.srsId];
3946
- if (!sourceProjection) {
3947
- throw new CRSReprojectionError("missing-source-crs", `GeoPackage reprojection requires a defined source CRS for SRS ${vectorTable.srsId}`, { targetCrs: options.targetCrs });
3948
- }
3949
- try {
3950
- return import_projection2.projectionEngine.createProjection({
3951
- from: getProjectionDefinition2(sourceProjection),
3952
- to: options.targetCrs
3953
- });
3954
- } catch (error) {
3955
- const message = error instanceof Error ? error.message : String(error);
3956
- throw new CRSReprojectionError("transformation-failed", `GeoPackage reprojection failed: ${message}`, { sourceCrs: sourceProjection, targetCrs: options.targetCrs, cause: error });
3957
- }
3958
- }
3959
- function getProjectionDefinition2(definition) {
3960
- var _a, _b;
3961
- if (/^\s*PROJCS\s*\[/i.test(definition) && /EXTENSION\s*\[\s*"PROJ4"/i.test(definition)) {
3962
- const { root } = (0, import_crs3.parseWKTCRS)(definition);
3963
- const authority = root.values.find((value) => value.type === "node" && value.keyword.toUpperCase() === "AUTHORITY");
3964
- if ((authority == null ? void 0 : authority.type) === "node" && ((_a = authority.values[0]) == null ? void 0 : _a.type) === "string" && authority.values[0].value.toUpperCase() === "EPSG" && ((_b = authority.values[1]) == null ? void 0 : _b.type) === "string" && authority.values[1].value === "3857") {
3965
- return "EPSG:3857";
3966
- }
3967
- }
3968
- return definition;
3969
- }
3970
- function reprojectGeometry2(geometry, projection) {
3971
- if (!geometry) {
3972
- return null;
3973
- }
3974
- const feature = { type: "Feature", geometry, properties: {} };
3975
- return transformGeoJsonCoords([feature], (coordinate) => projection.projectSync(coordinate))[0].geometry;
3976
- }
3977
- function parseGeometry2(geometryValue) {
3978
- const wkb = parseGeometryWKB2(geometryValue);
3979
- return wkb ? convertWKBToGeometry(wkb.buffer.slice(wkb.byteOffset, wkb.byteOffset + wkb.byteLength)) : null;
3980
- }
3981
- function parseGeometryWKB2(geometryValue) {
3982
- if (!geometryValue) {
3983
- return null;
3984
- }
3985
- const arrayBuffer = getArrayBufferFromValue2(geometryValue);
3986
- const view = new DataView(arrayBuffer);
3987
- const { envelopeLength, emptyGeometry } = parseGeometryBitFlags2(view.getUint8(3));
3988
- if (emptyGeometry) {
3989
- return null;
3990
- }
3991
- const wkbOffset = 8 + envelopeLength;
3992
- return new Uint8Array(arrayBuffer, wkbOffset);
3993
- }
3994
- function parseGeometryBitFlags2(byte) {
3995
- const envelopeValue = (byte & 14) / 2;
3996
- const envelopeLength = ENVELOPE_BYTE_LENGTHS2[envelopeValue];
3997
- return {
3998
- littleEndian: Boolean(byte & 1),
3999
- envelopeLength,
4000
- emptyGeometry: Boolean(byte & 16),
4001
- extendedGeometryType: Boolean(byte & 32)
4002
- };
4003
- }
4004
- function getFeatureIdName2(database, tableName) {
4005
- const statement = database.prepare(`PRAGMA table_info(\`${tableName}\`)`);
4006
- while (statement.step()) {
4007
- const pragmaTableInfo = statement.getAsObject();
4008
- if (pragmaTableInfo.pk) {
4009
- return pragmaTableInfo.name;
4010
- }
4011
- }
4012
- return null;
4013
- }
4014
- function getDataColumns2(database, tableName) {
4015
- let statement;
4016
- try {
4017
- statement = database.prepare("SELECT * FROM gpkg_data_columns WHERE table_name=:tableName;");
4018
- } catch (error) {
4019
- if (error.message.includes("no such table")) {
4020
- return null;
4021
- }
4022
- throw error;
4023
- }
4024
- statement.bind({ ":tableName": tableName });
4025
- const dataColumns = {};
4026
- while (statement.step()) {
4027
- const column = statement.getAsObject();
4028
- dataColumns[column.column_name] = column.name || null;
4029
- }
4030
- return dataColumns;
4031
- }
4032
- function getSchema2(database, tableName) {
4033
- const statement = database.prepare(`PRAGMA table_info(\`${tableName}\`)`);
4034
- const fields = [];
4035
- while (statement.step()) {
4036
- const pragmaTableInfo = statement.getAsObject();
4037
- fields.push({
4038
- name: pragmaTableInfo.name,
4039
- type: getSqliteFieldType2(pragmaTableInfo.type),
4040
- nullable: !pragmaTableInfo.notnull
4041
- });
4042
- }
4043
- return { fields, metadata: {} };
4044
- }
4045
- function getGeoPackageArrowSchema2(database, vectorTable, crs) {
4046
- const statement = database.prepare(`PRAGMA table_info(\`${vectorTable.name}\`)`);
4047
- const fields = [];
4048
- while (statement.step()) {
4049
- const pragmaTableInfo = statement.getAsObject();
4050
- if (pragmaTableInfo.name === vectorTable.geometryColumnName) {
4051
- continue;
4052
- }
4053
- fields.push({
4054
- name: pragmaTableInfo.name,
4055
- type: getSqliteFieldType2(pragmaTableInfo.type),
4056
- nullable: !pragmaTableInfo.notnull
4057
- });
4058
- }
4059
- const geometryField = makeWKBGeometryField(GEOMETRY_OUTPUT_COLUMN_NAME2);
4060
- if (crs) {
4061
- geometryField.metadata["ARROW:extension:metadata"] = JSON.stringify(getGeoArrowCrsMetadata2(crs));
4062
- }
4063
- fields.push(geometryField);
4064
- const schema = { fields, metadata: {} };
4065
- setWKBGeometrySchemaMetadata(schema, {
4066
- geometryColumnName: GEOMETRY_OUTPUT_COLUMN_NAME2,
4067
- geometryTypes: [getGeoMetadataGeometryType2(vectorTable)]
4068
- });
4069
- return schema;
4070
- }
4071
- function getGeoArrowCrsMetadata2(crs) {
4072
- if (typeof crs !== "string") {
4073
- return { crs, crs_type: "projjson" };
4074
- }
4075
- if (/^[A-Za-z][A-Za-z0-9_.-]*:[^\s]+$/.test(crs)) {
4076
- return { crs, crs_type: "authority_code" };
4077
- }
4078
- return { crs };
4079
- }
4080
- function getGeoMetadataGeometryType2(vectorTable) {
4081
- const geometryTypeNameMap = {
4082
- GEOMETRY: "Geometry",
4083
- POINT: "Point",
4084
- LINESTRING: "LineString",
4085
- POLYGON: "Polygon",
4086
- MULTIPOINT: "MultiPoint",
4087
- MULTILINESTRING: "MultiLineString",
4088
- MULTIPOLYGON: "MultiPolygon",
4089
- GEOMETRYCOLLECTION: "GeometryCollection"
4090
- };
4091
- const geometryType = geometryTypeNameMap[vectorTable.geometryTypeName] || "Geometry";
4092
- return vectorTable.z > 0 ? `${geometryType} Z` : geometryType;
4093
- }
4094
- function getSqliteFieldType2(sqliteType) {
4095
- const normalizedType = (sqliteType || "TEXT").toUpperCase();
4096
- return SQL_TYPE_MAPPING2[normalizedType] || "utf8";
4097
- }
4098
- function getGeoPackageBounds2(row) {
4099
- const minX = normalizeOptionalNumber2(row.min_x);
4100
- const minY = normalizeOptionalNumber2(row.min_y);
4101
- const maxX = normalizeOptionalNumber2(row.max_x);
4102
- const maxY = normalizeOptionalNumber2(row.max_y);
4103
- if (minX === void 0 || minY === void 0 || maxX === void 0 || maxY === void 0) {
4104
- return void 0;
4105
- }
4106
- return { minX, minY, maxX, maxY };
4107
- }
4108
- function isDefaultTableMarker2(value) {
4109
- if (!value) {
4110
- return false;
4111
- }
4112
- const normalizedValue = value.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
4113
- return DEFAULT_TABLE_MARKERS2.has(normalizedValue);
4114
- }
4115
- function getArrayBufferFromValue2(value) {
4116
- if (value instanceof ArrayBuffer) {
4117
- return value;
4118
- }
4119
- if (ArrayBuffer.isView(value)) {
4120
- return value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
4121
- }
4122
- throw new Error("Expected GeoPackage geometry column to contain binary data.");
4123
- }
4124
- function normalizeOptionalString2(value) {
4125
- return typeof value === "string" && value.length ? value : void 0;
4126
- }
4127
- function normalizeOptionalNumber2(value) {
4128
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
4129
- }
4130
-
4131
- // dist/geopackage/lib/geopackage-tile-metadata.js
4132
- init_loader_utils();
4133
- function listGeoPackageTileTables(database) {
4134
- const tables = readRows(database, "SELECT * FROM gpkg_contents WHERE data_type = 'tiles' ORDER BY table_name");
4135
- return tables.map((table) => {
4136
- const name = String(table.table_name);
4137
- const sets = readRows(database, `
4138
- SELECT matrix_set.*, reference.srs_id AS reference_srs_id, reference.organization, reference.organization_coordsys_id
4139
- FROM gpkg_tile_matrix_set AS matrix_set
4140
- LEFT JOIN gpkg_spatial_ref_sys AS reference ON reference.srs_id = matrix_set.srs_id
4141
- WHERE matrix_set.table_name = ?`, [name]);
4142
- const matrixSet = sets[0];
4143
- if (sets.length !== 1 || !matrixSet || matrixSet.srs_id !== table.srs_id || !Number.isSafeInteger(matrixSet.srs_id) || matrixSet.reference_srs_id !== matrixSet.srs_id) {
4144
- throw new Error(`Invalid GeoPackage tile matrix set for ${name}`);
4145
- }
4146
- const { min_x: minimumX, min_y: minimumY, max_x: maximumX, max_y: maximumY } = matrixSet;
4147
- if (![minimumX, minimumY, maximumX, maximumY].every((value) => typeof value === "number" && Number.isFinite(value)) || Number(minimumX) >= Number(maximumX) || Number(minimumY) >= Number(maximumY)) {
4148
- throw new Error(`Invalid GeoPackage tile matrix bounds for ${name}`);
4149
- }
4150
- const organization = typeof matrixSet.organization === "string" ? matrixSet.organization : "";
4151
- const authorityCode = matrixSet.organization_coordsys_id;
4152
- const crs = organization && organization.toLowerCase() !== "none" && typeof authorityCode === "number" && Number.isSafeInteger(authorityCode) && authorityCode >= 0 ? `${organization.toUpperCase()}:${authorityCode}` : void 0;
4153
- const rows = readRows(database, "SELECT * FROM gpkg_tile_matrix WHERE table_name = ? ORDER BY zoom_level", [name]);
4154
- const identifiers = /* @__PURE__ */ new Set();
4155
- const matrices = rows.map((row) => {
4156
- const level = row.zoom_level;
4157
- if (typeof level !== "number" || !Number.isSafeInteger(level) || level < 0 || identifiers.has(level) || ![row.matrix_width, row.matrix_height, row.tile_width, row.tile_height].every((value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0) || ![row.pixel_x_size, row.pixel_y_size].every((value) => typeof value === "number" && Number.isFinite(value) && value > 0)) {
4158
- throw new Error(`Invalid GeoPackage tile matrix for ${name}`);
4159
- }
4160
- const width = Number(row.matrix_width) * Number(row.tile_width) * Number(row.pixel_x_size);
4161
- const height = Number(row.matrix_height) * Number(row.tile_height) * Number(row.pixel_y_size);
4162
- if (!matchesMatrixExtent(width, Number(minimumX), Number(maximumX)) || !matchesMatrixExtent(height, Number(minimumY), Number(maximumY))) {
4163
- throw new Error(`GeoPackage tile matrix dimensions disagree with bounds for ${name}`);
4164
- }
4165
- identifiers.add(level);
4166
- return createTileGridMatrix({
4167
- id: String(level),
4168
- resolution: Number(row.pixel_x_size),
4169
- resolutionY: Number(row.pixel_y_size),
4170
- point: [Number(minimumX), Number(maximumY)],
4171
- swapAxes: false,
4172
- tileWidth: Number(row.tile_width),
4173
- tileHeight: Number(row.tile_height),
4174
- matrixWidth: Number(row.matrix_width),
4175
- matrixHeight: Number(row.matrix_height)
4176
- });
4177
- });
4178
- return {
4179
- name,
4180
- identifier: typeof table.identifier === "string" ? table.identifier : void 0,
4181
- description: typeof table.description === "string" ? table.description : void 0,
4182
- srsId: Number(matrixSet.srs_id),
4183
- crs,
4184
- bounds: [
4185
- [Number(minimumX), Number(minimumY)],
4186
- [Number(maximumX), Number(maximumY)]
4187
- ],
4188
- tileGrid: createTileGrid(crs, matrices)
4189
- };
4190
- });
4191
- }
4192
- function readRows(database, query, parameters = []) {
4193
- const statement = database.prepare(query);
4194
- try {
4195
- statement.bind(parameters);
4196
- const rows = [];
4197
- while (statement.step())
4198
- rows.push(statement.getAsObject());
4199
- return rows;
4200
- } finally {
4201
- statement.free();
4202
- }
4203
- }
4204
- function matchesMatrixExtent(span, minimum, maximum) {
4205
- const declaredSpan = maximum - minimum;
4206
- if (!Number.isFinite(span) || !Number.isFinite(declaredSpan))
4207
- return false;
4208
- const tolerance = 32 * Number.EPSILON * Math.max(Math.abs(minimum), Math.abs(maximum), span, declaredSpan);
4209
- return Math.abs(span - declaredSpan) <= tolerance;
4210
- }
4211
-
4212
- // dist/geopackage/geopackage-source-loader.js
4213
- var VERSION4 = true ? "5.0.0-alpha.14" : "latest";
4214
- var GeoPackageSource = {
4215
- ...GeoPackageFormat,
4216
- dataType: null,
4217
- batchType: null,
4218
- name: "GeoPackageSource",
4219
- version: VERSION4,
4220
- type: "geopackage",
4221
- fromUrl: true,
4222
- fromBlob: true,
4223
- options: {
4224
- geopackage: {
4225
- sqlJsCDN: DEFAULT_SQLJS_CDN,
4226
- table: void 0,
4227
- workerUrl: void 0
4228
- },
4229
- gis: {}
4230
- },
4231
- defaultOptions: {
4232
- geopackage: {
4233
- sqlJsCDN: DEFAULT_SQLJS_CDN,
4234
- table: void 0,
4235
- workerUrl: void 0
4236
- },
4237
- gis: {}
4238
- },
4239
- testURL: (url) => /\.gpkg(?:$|[?#])/i.test(url),
4240
- createDataSource: (data, options, coreApi) => new GeoPackageDataSource(data, options, coreApi)
4241
- };
4242
- var GeoPackageDataSource = class extends DataSource {
4243
- arrayBufferPromise = null;
4244
- metadataPromise = null;
4245
- constructor(data, options, coreApi) {
4246
- super(data, options, GeoPackageSource.defaultOptions, coreApi);
4247
- }
4248
- /** Returns GeoPackage table metadata and marks the selected default table. */
4249
- async getMetadata() {
4250
- if (!this.metadataPromise) {
4251
- this.metadataPromise = this.loadMetadata();
4252
- }
4253
- return this.metadataPromise;
4254
- }
4255
- /** Discovers the selected feature table schema and spatial bounds for the shared scan panel. */
4256
- async getQueryMetadata(options = {}) {
4257
- throwIfAborted(options.signal);
4258
- const metadata = await this.getMetadata();
4259
- throwIfAborted(options.signal);
4260
- const selectedTable = metadata.tables.find((table) => table.isDefault) || metadata.tables[0];
4261
- if (!selectedTable)
4262
- throw new Error("GeoPackage contains no vector feature tables");
4263
- const fieldNames = new Set(selectedTable.schema.fields.map((field) => field.name));
4264
- const geometryColumnName = fieldNames.has("geometry") ? "geometry" : fieldNames.has(selectedTable.geometryColumnName) ? selectedTable.geometryColumnName : void 0;
4265
- return createScanQueryMetadata({
4266
- sourceType: "geopackage",
4267
- queryType: "table",
4268
- execution: { status: "supported", method: "read" },
4269
- name: selectedTable.identifier || selectedTable.name,
4270
- description: selectedTable.description,
4271
- schema: selectedTable.schema,
4272
- columnRoles: geometryColumnName ? { [geometryColumnName]: "geometry" } : void 0,
4273
- capabilities: {
4274
- table: {
4275
- projection: "residual",
4276
- predicate: "residual",
4277
- limit: "residual",
4278
- streaming: false,
4279
- cancellation: false
4280
- }
4281
- },
4282
- spatial: selectedTable.bounds || selectedTable.crs ? {
4283
- bounds: selectedTable.bounds ? { minimum: selectedTable.bounds[0], maximum: selectedTable.bounds[1] } : void 0,
4284
- coordinateReferenceSystems: selectedTable.crs ? [selectedTable.crs] : void 0
4285
- } : void 0,
4286
- statistics: { byteLength: void 0 }
4287
- });
4288
- }
4289
- /** Reads one encoded tile from an explicitly selected raster table. Missing tiles return null.
4290
- * The byte limit applies to encoded payloads; opening SQLite still loads the whole GeoPackage.
4291
- */
4292
- async getTile(tableName, parameters, options = {}) {
4293
- var _a;
4294
- throwIfAborted(parameters.signal);
4295
- const maximumBytes = options.maxBytes ?? 16 * 1024 * 1024;
4296
- if (!Number.isSafeInteger(maximumBytes) || maximumBytes < 0) {
4297
- throw new Error("Invalid GeoPackage tile byte limit");
4298
- }
4299
- const metadata = await this.getMetadata();
4300
- throwIfAborted(parameters.signal);
4301
- const table = metadata.tileTables.find((candidate) => candidate.name === tableName);
4302
- if (!table)
4303
- throw new Error("Unknown GeoPackage tile table: " + tableName);
4304
- const matrix = getRequestedTileMatrix(table.tileGrid.matrices || [], (value) => value.id, parameters);
4305
- if (!matrix)
4306
- throw new Error("Unknown GeoPackage tile matrix");
4307
- if (![parameters.x, parameters.y].every((value) => Number.isSafeInteger(value))) {
4308
- throw new Error("GeoPackage tile coordinates must be integers");
4309
- }
4310
- if (parameters.x < 0 || parameters.y < 0 || !matrix.matrixSize || parameters.x >= matrix.matrixSize[0] || parameters.y >= matrix.matrixSize[1])
4311
- return null;
4312
- const database = await loadGeoPackageDatabase2(await this.getArrayBuffer(), ((_a = this.options.geopackage) == null ? void 0 : _a.sqlJsCDN) ?? DEFAULT_SQLJS_CDN);
4313
- try {
4314
- throwIfAborted(parameters.signal);
4315
- const identifier = '"' + table.name.replaceAll('"', '""') + '"';
4316
- const statement = database.prepare("SELECT length(tile_data) AS size, typeof(tile_data) AS type, CASE WHEN length(tile_data) <= ? THEN tile_data ELSE NULL END AS payload FROM " + identifier + " WHERE zoom_level = ? AND tile_column = ? AND tile_row = ? LIMIT 1");
4317
- try {
4318
- statement.bind([maximumBytes, Number(matrix.id), parameters.x, parameters.y]);
4319
- if (!statement.step())
4320
- return null;
4321
- const row = statement.getAsObject();
4322
- if (row.type !== "blob")
4323
- throw new Error("Invalid GeoPackage tile payload");
4324
- if (Number(row.size) > maximumBytes)
4325
- throw new Error("GeoPackage tile exceeds byte limit");
4326
- throwIfAborted(parameters.signal);
4327
- return row.payload.slice().buffer;
4328
- } finally {
4329
- statement.free();
4330
- }
4331
- } finally {
4332
- database.close();
4333
- }
4334
- }
4335
- /** Loads one GeoPackage vector table as an Arrow table. */
4336
- async getTable(tableName) {
4337
- const arrayBuffer = await this.getArrayBuffer();
4338
- return parseGeoPackageToArrow2(arrayBuffer, this.getLoaderOptions(tableName));
4339
- }
4340
- /** Executes projection, residual predicates, and a global limit on the selected feature table. */
4341
- async query(options = {}) {
4342
- throwIfAborted(options.signal);
4343
- const table = await this.getTable();
4344
- throwIfAborted(options.signal);
4345
- return queryGeoPackageTable(table, options);
4346
- }
4347
- /** Executes a common table scan as one bounded Arrow batch. */
4348
- async *read(options = {}) {
4349
- const table = await this.query(options);
4350
- yield makeTableScanBatch(table);
4351
- }
4352
- async loadMetadata() {
4353
- var _a, _b, _c;
4354
- const arrayBuffer = await this.getArrayBuffer();
4355
- const database = await loadGeoPackageDatabase2(arrayBuffer, ((_a = this.options.geopackage) == null ? void 0 : _a.sqlJsCDN) ?? DEFAULT_SQLJS_CDN);
4356
- try {
4357
- const vectorTables = listGeoPackageVectorTables2(database);
4358
- const projections = getProjections2(database);
4359
- const defaultTable = vectorTables.length || ((_b = this.options.geopackage) == null ? void 0 : _b.table) ? selectGeoPackageVectorTable2(vectorTables, ((_c = this.options.geopackage) == null ? void 0 : _c.table) || void 0) : void 0;
4360
- return {
4361
- tileTables: listGeoPackageTileTables(database),
4362
- tables: vectorTables.map((vectorTable) => {
4363
- const crs = vectorTable.srsId === void 0 ? void 0 : projections[vectorTable.srsId];
4364
- return {
4365
- schema: getGeoPackageArrowSchema2(database, vectorTable, crs),
4366
- name: vectorTable.name,
4367
- identifier: vectorTable.identifier,
4368
- description: vectorTable.description,
4369
- srsId: vectorTable.srsId,
4370
- crs,
4371
- geometryColumnName: vectorTable.geometryColumnName,
4372
- geometryTypeName: vectorTable.geometryTypeName,
4373
- bounds: vectorTable.bounds ? [
4374
- [vectorTable.bounds.minX, vectorTable.bounds.minY],
4375
- [vectorTable.bounds.maxX, vectorTable.bounds.maxY]
4376
- ] : void 0,
4377
- isDefault: vectorTable.name === (defaultTable == null ? void 0 : defaultTable.name)
4378
- };
4379
- })
4380
- };
4381
- } finally {
4382
- database.close();
4383
- }
4384
- }
4385
- async getArrayBuffer() {
4386
- if (!this.arrayBufferPromise) {
4387
- this.arrayBufferPromise = this.loadArrayBuffer();
4388
- }
4389
- return this.arrayBufferPromise;
4390
- }
4391
- async loadArrayBuffer() {
4392
- try {
4393
- if (typeof this.data === "string") {
4394
- const response = await this.fetch(this.url);
4395
- if (!response.ok) {
4396
- throw new Error(`${response.status} ${response.statusText}`);
4397
- }
4398
- return await response.arrayBuffer();
4399
- }
4400
- return await this.data.arrayBuffer();
4401
- } catch (error) {
4402
- throw this.reportError(error, `Failed to load GeoPackage from ${this.url || "Blob input"}`);
4403
- }
4404
- }
4405
- getLoaderOptions(tableName) {
4406
- var _a, _b, _c, _d;
4407
- const loadOptions = this.loadOptions;
4408
- return {
4409
- ...loadOptions,
4410
- geopackage: {
4411
- ...loadOptions.geopackage,
4412
- ...this.options.geopackage,
4413
- sqlJsCDN: ((_a = this.options.geopackage) == null ? void 0 : _a.sqlJsCDN) ?? ((_b = loadOptions.geopackage) == null ? void 0 : _b.sqlJsCDN),
4414
- table: tableName || ((_c = this.options.geopackage) == null ? void 0 : _c.table) || ((_d = loadOptions.geopackage) == null ? void 0 : _d.table)
4415
- },
4416
- gis: {
4417
- ...loadOptions.gis,
4418
- ...this.options.gis
4419
- }
4420
- };
4421
- }
4422
- };
4423
- function queryGeoPackageTable(table, options) {
4424
- const availableColumns = table.data.schema.fields.map((field) => field.name);
4425
- validateTableQueryOptions(availableColumns, options);
4426
- const queriedTable = queryArrowTable(table, options, (predicate, columns, rowCount) => filterColumnarRowIndices(predicate, columns, rowCount));
4427
- return { ...queriedTable, schema: convertArrowToSchema(queriedTable.data.schema) };
4428
- }
4429
- function throwIfAborted(signal) {
4430
- if (signal == null ? void 0 : signal.aborted)
4431
- throw new DOMException("The operation was aborted", "AbortError");
4432
- }
4433
37
  //# sourceMappingURL=index.cjs.map