@loaders.gl/gis 4.3.2 → 4.4.0-alpha.1

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 (173) hide show
  1. package/dist/index.cjs +2411 -469
  2. package/dist/index.cjs.map +4 -4
  3. package/dist/index.d.ts +31 -12
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +38 -15
  6. package/dist/lib/binary-geometry-api/binary-geometry-info.d.ts +21 -0
  7. package/dist/lib/binary-geometry-api/binary-geometry-info.d.ts.map +1 -0
  8. package/dist/lib/binary-geometry-api/binary-geometry-info.js +48 -0
  9. package/dist/lib/binary-geometry-api/concat-binary-geometry.d.ts +5 -0
  10. package/dist/lib/binary-geometry-api/concat-binary-geometry.d.ts.map +1 -0
  11. package/dist/lib/binary-geometry-api/concat-binary-geometry.js +50 -0
  12. package/dist/lib/{binary-features/transform.d.ts → binary-geometry-api/transform-coordinates.d.ts} +1 -2
  13. package/dist/lib/binary-geometry-api/transform-coordinates.d.ts.map +1 -0
  14. package/dist/lib/{binary-features/transform.js → binary-geometry-api/transform-coordinates.js} +0 -1
  15. package/dist/lib/feature-collection-converters/convert-binary-features-to-geojson.d.ts +16 -0
  16. package/dist/lib/feature-collection-converters/convert-binary-features-to-geojson.d.ts.map +1 -0
  17. package/dist/lib/{binary-features/binary-to-geojson.js → feature-collection-converters/convert-binary-features-to-geojson.js} +3 -90
  18. package/dist/lib/{binary-features/flat-geojson-to-binary.d.ts → feature-collection-converters/convert-flat-geojson-to-binary-features.d.ts} +6 -9
  19. package/dist/lib/feature-collection-converters/convert-flat-geojson-to-binary-features.d.ts.map +1 -0
  20. package/dist/lib/{binary-features/flat-geojson-to-binary.js → feature-collection-converters/convert-flat-geojson-to-binary-features.js} +5 -5
  21. package/dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.d.ts +74 -0
  22. package/dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.d.ts.map +1 -0
  23. package/dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.js +377 -0
  24. package/dist/lib/{binary-features/geojson-to-binary.d.ts → feature-collection-converters/convert-geojson-to-binary-features.d.ts} +2 -2
  25. package/dist/lib/feature-collection-converters/convert-geojson-to-binary-features.d.ts.map +1 -0
  26. package/dist/lib/feature-collection-converters/convert-geojson-to-binary-features.js +24 -0
  27. package/dist/lib/{binary-features/geojson-to-flat-geojson.d.ts → feature-collection-converters/convert-geojson-to-flat-geojson.d.ts} +2 -2
  28. package/dist/lib/feature-collection-converters/convert-geojson-to-flat-geojson.d.ts.map +1 -0
  29. package/dist/lib/{binary-features/geojson-to-flat-geojson.js → feature-collection-converters/convert-geojson-to-flat-geojson.js} +4 -1
  30. package/dist/lib/feature-collection-converters/helpers/flat-geojson-to-binary-types.d.ts.map +1 -0
  31. package/dist/lib/feature-collection-converters/helpers/flat-geojson-to-binary-types.js +4 -0
  32. package/dist/lib/geometry-api/geometry-info.d.ts +21 -0
  33. package/dist/lib/geometry-api/geometry-info.d.ts.map +1 -0
  34. package/dist/lib/{binary-features/extract-geometry-info.js → geometry-api/geometry-info.js} +4 -1
  35. package/dist/lib/geometry-converters/convert-binary-geometry-to-geojson.d.ts +4 -0
  36. package/dist/lib/geometry-converters/convert-binary-geometry-to-geojson.d.ts.map +1 -0
  37. package/dist/lib/geometry-converters/convert-binary-geometry-to-geojson.js +91 -0
  38. package/dist/lib/geometry-converters/convert-geoarrow-to-geojson.d.ts +13 -0
  39. package/dist/lib/geometry-converters/convert-geoarrow-to-geojson.d.ts.map +1 -0
  40. package/dist/lib/geometry-converters/convert-geoarrow-to-geojson.js +164 -0
  41. package/dist/lib/geometry-converters/convert-to-geojson.d.ts +6 -0
  42. package/dist/lib/geometry-converters/convert-to-geojson.d.ts.map +1 -0
  43. package/dist/lib/geometry-converters/convert-to-geojson.js +39 -0
  44. package/dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.d.ts +6 -0
  45. package/dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.d.ts.map +1 -0
  46. package/dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.js +195 -0
  47. package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.d.ts +9 -0
  48. package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.d.ts.map +1 -0
  49. package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.js +273 -0
  50. package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.d.ts +8 -0
  51. package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.d.ts.map +1 -0
  52. package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.js +44 -0
  53. package/dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.d.ts +10 -0
  54. package/dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.d.ts.map +1 -0
  55. package/dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.js +254 -0
  56. package/dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.d.ts +3 -0
  57. package/dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.d.ts.map +1 -0
  58. package/dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.js +164 -0
  59. package/dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.d.ts +11 -0
  60. package/dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.d.ts.map +1 -0
  61. package/dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.js +9 -0
  62. package/dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.d.ts +16 -0
  63. package/dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.d.ts.map +1 -0
  64. package/dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.js +258 -0
  65. package/dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts +43 -0
  66. package/dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts.map +1 -0
  67. package/dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.js +174 -0
  68. package/dist/lib/geometry-converters/wkb/helpers/wkb-types.d.ts +64 -0
  69. package/dist/lib/geometry-converters/wkb/helpers/wkb-types.d.ts.map +1 -0
  70. package/dist/lib/geometry-converters/wkb/helpers/wkb-types.js +46 -0
  71. package/dist/lib/geometry-converters/wkb/helpers/wkb-utils.d.ts +21 -0
  72. package/dist/lib/geometry-converters/wkb/helpers/wkb-utils.d.ts.map +1 -0
  73. package/dist/lib/geometry-converters/wkb/helpers/wkb-utils.js +64 -0
  74. package/dist/lib/geometry-converters/wkb/helpers/write-wkb-header.d.ts +8 -0
  75. package/dist/lib/geometry-converters/wkb/helpers/write-wkb-header.d.ts.map +1 -0
  76. package/dist/lib/geometry-converters/wkb/helpers/write-wkb-header.js +33 -0
  77. package/dist/lib/table-converters/convert-geoarrow-table.d.ts +27 -0
  78. package/dist/lib/table-converters/convert-geoarrow-table.d.ts.map +1 -0
  79. package/dist/lib/table-converters/convert-geoarrow-table.js +154 -0
  80. package/dist/lib/table-converters/convert-wkb-table-to-geojson.d.ts +4 -0
  81. package/dist/lib/table-converters/convert-wkb-table-to-geojson.d.ts.map +1 -0
  82. package/dist/lib/{tables/convert-table-to-geojson.js → table-converters/convert-wkb-table-to-geojson.js} +10 -16
  83. package/dist/lib/table-converters/make-arrow-batch-iterator.d.ts +6 -0
  84. package/dist/lib/table-converters/make-arrow-batch-iterator.d.ts.map +1 -0
  85. package/dist/lib/table-converters/make-arrow-batch-iterator.js +35 -0
  86. package/dist/lib/utils/base64-encoder.d.ts +5 -0
  87. package/dist/lib/utils/base64-encoder.d.ts.map +1 -0
  88. package/dist/lib/utils/base64-encoder.js +153 -0
  89. package/dist/lib/utils/binary-reader.d.ts +18 -0
  90. package/dist/lib/utils/binary-reader.d.ts.map +1 -0
  91. package/dist/lib/utils/binary-reader.js +69 -0
  92. package/dist/lib/utils/binary-writer.d.ts +30 -0
  93. package/dist/lib/utils/binary-writer.d.ts.map +1 -0
  94. package/dist/lib/utils/binary-writer.js +127 -0
  95. package/dist/lib/utils/concat-typed-arrays.d.ts +3 -0
  96. package/dist/lib/utils/concat-typed-arrays.d.ts.map +1 -0
  97. package/dist/lib/utils/concat-typed-arrays.js +18 -0
  98. package/dist/lib/utils/hex-encoder.d.ts +15 -0
  99. package/dist/lib/utils/hex-encoder.d.ts.map +1 -0
  100. package/dist/lib/utils/hex-encoder.js +54 -0
  101. package/dist/lib/utils/hex-transcoder.d.ts +15 -0
  102. package/dist/lib/utils/hex-transcoder.d.ts.map +1 -0
  103. package/dist/lib/utils/hex-transcoder.js +50 -0
  104. package/dist/lib/wkt-crs/encode-wkt-crs.d.ts +10 -0
  105. package/dist/lib/wkt-crs/encode-wkt-crs.d.ts.map +1 -0
  106. package/dist/lib/wkt-crs/encode-wkt-crs.js +35 -0
  107. package/dist/lib/wkt-crs/parse-wkt-crs.d.ts +15 -0
  108. package/dist/lib/wkt-crs/parse-wkt-crs.d.ts.map +1 -0
  109. package/dist/lib/wkt-crs/parse-wkt-crs.js +120 -0
  110. package/package.json +7 -5
  111. package/src/index.ts +87 -14
  112. package/src/lib/binary-geometry-api/binary-geometry-info.ts +75 -0
  113. package/src/lib/binary-geometry-api/concat-binary-geometry.ts +78 -0
  114. package/src/lib/{binary-features/transform.ts → binary-geometry-api/transform-coordinates.ts} +0 -1
  115. package/src/lib/{binary-features/binary-to-geojson.ts → feature-collection-converters/convert-binary-features-to-geojson.ts} +5 -142
  116. package/src/lib/{binary-features/flat-geojson-to-binary.ts → feature-collection-converters/convert-flat-geojson-to-binary-features.ts} +14 -9
  117. package/src/lib/feature-collection-converters/convert-geoarrow-to-binary-features.ts +496 -0
  118. package/src/lib/{binary-features/geojson-to-binary.ts → feature-collection-converters/convert-geojson-to-binary-features.ts} +11 -7
  119. package/src/lib/{binary-features/geojson-to-flat-geojson.ts → feature-collection-converters/convert-geojson-to-flat-geojson.ts} +5 -1
  120. package/src/lib/{binary-features → feature-collection-converters/helpers}/flat-geojson-to-binary-types.ts +4 -0
  121. package/src/lib/{binary-features/extract-geometry-info.ts → geometry-api/geometry-info.ts} +20 -2
  122. package/src/lib/geometry-converters/convert-binary-geometry-to-geojson.ts +148 -0
  123. package/src/lib/geometry-converters/convert-geoarrow-to-geojson.ts +193 -0
  124. package/src/lib/geometry-converters/convert-to-geojson.ts +52 -0
  125. package/src/lib/geometry-converters/wkb/convert-geometry-to-twkb.ts +308 -0
  126. package/src/lib/geometry-converters/wkb/convert-geometry-to-wkb.ts +365 -0
  127. package/src/lib/geometry-converters/wkb/convert-geometry-to-wkt.ts +54 -0
  128. package/src/lib/geometry-converters/wkb/convert-twkb-to-geometry.ts +366 -0
  129. package/src/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.ts +238 -0
  130. package/src/lib/geometry-converters/wkb/convert-wkb-to-geometry.ts +23 -0
  131. package/src/lib/geometry-converters/wkb/convert-wkt-to-geometry.ts +294 -0
  132. package/src/lib/geometry-converters/wkb/helpers/parse-wkb-header.ts +213 -0
  133. package/src/lib/geometry-converters/wkb/helpers/wkb-types.ts +82 -0
  134. package/src/lib/geometry-converters/wkb/helpers/wkb-utils.ts +85 -0
  135. package/src/lib/geometry-converters/wkb/helpers/write-wkb-header.ts +41 -0
  136. package/src/lib/table-converters/convert-geoarrow-table.ts +218 -0
  137. package/src/lib/{tables/convert-table-to-geojson.ts → table-converters/convert-wkb-table-to-geojson.ts} +10 -23
  138. package/src/lib/table-converters/make-arrow-batch-iterator.ts +53 -0
  139. package/src/lib/utils/base64-encoder.ts +157 -0
  140. package/src/lib/utils/binary-reader.ts +76 -0
  141. package/src/lib/utils/binary-writer.ts +136 -0
  142. package/src/lib/utils/concat-typed-arrays.ts +24 -0
  143. package/src/lib/utils/hex-encoder.ts +60 -0
  144. package/src/lib/utils/hex-transcoder.ts +54 -0
  145. package/src/lib/wkt-crs/encode-wkt-crs.ts +41 -0
  146. package/src/lib/wkt-crs/parse-wkt-crs.ts +149 -0
  147. package/dist/lib/binary-features/binary-to-geojson.d.ts +0 -18
  148. package/dist/lib/binary-features/binary-to-geojson.d.ts.map +0 -1
  149. package/dist/lib/binary-features/extract-geometry-info.d.ts +0 -8
  150. package/dist/lib/binary-features/extract-geometry-info.d.ts.map +0 -1
  151. package/dist/lib/binary-features/flat-geojson-to-binary-types.d.ts.map +0 -1
  152. package/dist/lib/binary-features/flat-geojson-to-binary-types.js +0 -1
  153. package/dist/lib/binary-features/flat-geojson-to-binary.d.ts.map +0 -1
  154. package/dist/lib/binary-features/geojson-to-binary.d.ts.map +0 -1
  155. package/dist/lib/binary-features/geojson-to-binary.js +0 -21
  156. package/dist/lib/binary-features/geojson-to-flat-geojson.d.ts.map +0 -1
  157. package/dist/lib/binary-features/transform.d.ts.map +0 -1
  158. package/dist/lib/geo/geoarrow-metadata.d.ts +0 -27
  159. package/dist/lib/geo/geoarrow-metadata.d.ts.map +0 -1
  160. package/dist/lib/geo/geoarrow-metadata.js +0 -70
  161. package/dist/lib/geo/geoparquet-metadata-schema.d.ts +0 -79
  162. package/dist/lib/geo/geoparquet-metadata-schema.d.ts.map +0 -1
  163. package/dist/lib/geo/geoparquet-metadata-schema.js +0 -69
  164. package/dist/lib/geo/geoparquet-metadata.d.ts +0 -45
  165. package/dist/lib/geo/geoparquet-metadata.d.ts.map +0 -1
  166. package/dist/lib/geo/geoparquet-metadata.js +0 -117
  167. package/dist/lib/tables/convert-table-to-geojson.d.ts +0 -5
  168. package/dist/lib/tables/convert-table-to-geojson.d.ts.map +0 -1
  169. package/src/lib/geo/geoarrow-metadata.ts +0 -100
  170. package/src/lib/geo/geoparquet-metadata-schema.json +0 -60
  171. package/src/lib/geo/geoparquet-metadata-schema.ts +0 -71
  172. package/src/lib/geo/geoparquet-metadata.ts +0 -191
  173. /package/dist/lib/{binary-features → feature-collection-converters/helpers}/flat-geojson-to-binary-types.d.ts +0 -0
@@ -0,0 +1,120 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // parse-wkt-crs was forked from https://github.com/DanielJDufour/wkt-crs under Creative Commons CC0 1.0 license.
5
+ /**
6
+ *
7
+ * @param wkt
8
+ * @param options
9
+ * @returns
10
+ */
11
+ export function parseWKTCRS(wkt, options) {
12
+ if (options?.debug) {
13
+ console.log('[wktcrs] parse starting with\n', wkt);
14
+ }
15
+ // move all keywords into first array item slot
16
+ // from PARAM[12345, 67890] to ["PARAM", 12345, 67890]
17
+ wkt = wkt.replace(/[A-Z][A-Z\d_]+\[/gi, (match) => `["${match.substr(0, match.length - 1)}",`);
18
+ // wrap variables in strings
19
+ // from [...,NORTH] to [...,"NORTH"]
20
+ wkt = wkt.replace(/, ?([A-Z][A-Z\d_]+[,\]])/gi, (match, p1) => {
21
+ const varname = p1.substr(0, p1.length - 1);
22
+ return ',' + `"${options?.raw ? 'raw:' : ''}${varname}"${p1[p1.length - 1]}`;
23
+ });
24
+ if (options?.raw) {
25
+ // replace all numbers with strings
26
+ wkt = wkt.replace(/, {0,2}(-?[\.\d]+)(?=,|\])/g, function (match, p1) {
27
+ return ',' + `"${options?.raw ? 'raw:' : ''}${p1}"`;
28
+ });
29
+ }
30
+ // str should now be valid JSON
31
+ if (options?.debug) {
32
+ console.log(`[wktcrs] json'd wkt: '${wkt}'`);
33
+ }
34
+ let data;
35
+ try {
36
+ data = JSON.parse(wkt);
37
+ }
38
+ catch (error) {
39
+ console.error(`[wktcrs] failed to parse '${wkt}'`);
40
+ throw error;
41
+ }
42
+ if (options?.debug) {
43
+ console.log(`[wktcrs] json parsed: '${wkt}'`);
44
+ }
45
+ function process(data, parent) {
46
+ const kw = data[0];
47
+ // after removing the first element with .shift()
48
+ // data is now just an array of attributes
49
+ data.forEach(function (it) {
50
+ if (Array.isArray(it)) {
51
+ process(it, data);
52
+ }
53
+ });
54
+ const kwarr = `MULTIPLE_${kw}`;
55
+ if (kwarr in parent) {
56
+ parent[kwarr].push(data);
57
+ }
58
+ else if (kw in parent) {
59
+ parent[kwarr] = [parent[kw], data];
60
+ delete parent[kw];
61
+ }
62
+ else {
63
+ parent[kw] = data;
64
+ }
65
+ return parent;
66
+ }
67
+ const result = process(data, [data]);
68
+ if (options?.debug) {
69
+ console.log('[wktcrs] parse returning', result);
70
+ }
71
+ if (options?.sort) {
72
+ sort(result, options);
73
+ }
74
+ return result;
75
+ }
76
+ function sort(data, options) {
77
+ const keys = Object.keys(data).filter((k) => !/\d+/.test(k));
78
+ const keywords = options?.keywords || [];
79
+ if (!options?.keywords) {
80
+ // try to find multiples
81
+ const counts = {};
82
+ if (Array.isArray(data)) {
83
+ data.forEach((it) => {
84
+ if (Array.isArray(it) && it.length >= 2 && typeof it[1] === 'string') {
85
+ const k = it[0];
86
+ if (!counts[k])
87
+ counts[k] = 0;
88
+ counts[k]++;
89
+ }
90
+ });
91
+ for (const k in counts) {
92
+ if (counts[k] > 0)
93
+ keywords.push(k);
94
+ }
95
+ }
96
+ }
97
+ keys.forEach((key) => {
98
+ data[key] = sort(data[key]);
99
+ });
100
+ keywords.forEach((key) => {
101
+ const indices = [];
102
+ const params = [];
103
+ data.forEach((item, i) => {
104
+ if (Array.isArray(item) && item[0] === key) {
105
+ indices.push(i);
106
+ params.push(item);
107
+ }
108
+ });
109
+ params.sort((a, b) => {
110
+ a = a[1].toString();
111
+ b = b[1].toString();
112
+ return a < b ? -1 : a > b ? 1 : 0;
113
+ });
114
+ // replace in order
115
+ params.forEach((param, i) => {
116
+ data[indices[i]] = param;
117
+ });
118
+ });
119
+ return data;
120
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loaders.gl/gis",
3
3
  "description": "Helpers for GIS category data",
4
- "version": "4.3.2",
4
+ "version": "4.4.0-alpha.1",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "publishConfig": {
@@ -32,8 +32,10 @@
32
32
  "README.md"
33
33
  ],
34
34
  "dependencies": {
35
- "@loaders.gl/loader-utils": "4.3.2",
36
- "@loaders.gl/schema": "4.3.2",
35
+ "@loaders.gl/geoarrow": "4.4.0-alpha.1",
36
+ "@loaders.gl/loader-utils": "4.4.0-alpha.1",
37
+ "@loaders.gl/schema": "4.4.0-alpha.1",
38
+ "@loaders.gl/schema-utils": "4.4.0-alpha.1",
37
39
  "@mapbox/vector-tile": "^1.3.1",
38
40
  "@math.gl/polygon": "^4.1.0",
39
41
  "pbf": "^3.2.1"
@@ -42,7 +44,7 @@
42
44
  "@math.gl/proj4": "^4.1.0"
43
45
  },
44
46
  "peerDependencies": {
45
- "@loaders.gl/core": "^4.3.0"
47
+ "@loaders.gl/core": "4.4.0-alpha.0"
46
48
  },
47
- "gitHead": "b4203b8703f64a38d6f79a3113bc7bb51d45c93a"
49
+ "gitHead": "f1732de45907bd500bf4eedb4803beca8bf4bfb0"
48
50
  }
package/src/index.ts CHANGED
@@ -3,21 +3,94 @@
3
3
  // Geo Metadata
4
4
  // import {default as GEOPARQUET_METADATA_SCHEMA} from './lib/geo/geoparquet-metadata-schema.json';
5
5
  // export {GEOPARQUET_METADATA_SCHEMA};
6
- export {GEOPARQUET_METADATA_JSON_SCHEMA} from './lib/geo/geoparquet-metadata-schema';
6
+ // export {GEOPARQUET_METADATA_JSON_SCHEMA} from './lib/geoarrow/geoparquet-metadata-schema';
7
7
 
8
- export type {GeoMetadata} from './lib/geo/geoparquet-metadata';
9
- export {getGeoMetadata, setGeoMetadata, unpackGeoMetadata} from './lib/geo/geoparquet-metadata';
10
- export {unpackJSONStringMetadata} from './lib/geo/geoparquet-metadata';
8
+ // export type {GeoMetadata} from './lib/geoarrow/geoparquet-metadata';
9
+ // export {
10
+ // getGeoMetadata,
11
+ // setGeoMetadata,
12
+ // unpackGeoMetadata
13
+ // } from './lib/geoarrow/geoparquet-metadata';
14
+ // export {unpackJSONStringMetadata} from './lib/geoarrow/geoparquet-metadata';
11
15
 
12
- export type {GeoArrowEncoding, GeoArrowMetadata} from './lib/geo/geoarrow-metadata';
13
- export {getGeometryColumnsFromSchema} from './lib/geo/geoarrow-metadata';
16
+ //
17
+ export type {GeojsonGeometryInfo} from './lib/geometry-api/geometry-info';
18
+ export {getGeometryInfo} from './lib/geometry-api/geometry-info';
14
19
 
15
- // Table conversion
16
- export {convertWKBTableToGeoJSON} from './lib/tables/convert-table-to-geojson';
20
+ // Binary Geometry Utilities
21
+ export type {BinaryGeometryInfo} from './lib/binary-geometry-api/binary-geometry-info';
22
+ export {getBinaryGeometryInfo} from './lib/binary-geometry-api/binary-geometry-info';
23
+ export {
24
+ transformBinaryCoords,
25
+ transformGeoJsonCoords
26
+ } from './lib/binary-geometry-api/transform-coordinates';
17
27
 
18
- // Binary Geometries
19
- export {flatGeojsonToBinary} from './lib/binary-features/flat-geojson-to-binary';
20
- export {geojsonToBinary} from './lib/binary-features/geojson-to-binary';
21
- export {geojsonToFlatGeojson} from './lib/binary-features/geojson-to-flat-geojson';
22
- export {binaryToGeojson, binaryToGeometry} from './lib/binary-features/binary-to-geojson';
23
- export {transformBinaryCoords, transformGeoJsonCoords} from './lib/binary-features/transform';
28
+ // TABLE CONVERSION
29
+ export {convertGeoArrowToTable} from './lib/table-converters/convert-geoarrow-table';
30
+ export {convertWKBTableToGeoJSON} from './lib/table-converters/convert-wkb-table-to-geojson';
31
+
32
+ // FEATURE COLLECTION CONVERSION
33
+ export {
34
+ convertFlatGeojsonToBinaryFeatureCollection,
35
+ // deprecated
36
+ convertFlatGeojsonToBinaryFeatureCollection as flatGeojsonToBinary
37
+ } from './lib/feature-collection-converters/convert-flat-geojson-to-binary-features';
38
+ export {
39
+ convertGeojsonToBinaryFeatureCollection,
40
+ // deprecated
41
+ convertGeojsonToBinaryFeatureCollection as geojsonToBinary
42
+ } from './lib/feature-collection-converters/convert-geojson-to-binary-features';
43
+ export {
44
+ convertGeojsonToFlatGeojson,
45
+ // deprecated
46
+ convertGeojsonToFlatGeojson as geojsonToFlatGeojson
47
+ } from './lib/feature-collection-converters/convert-geojson-to-flat-geojson';
48
+ export {
49
+ convertBinaryFeatureCollectionToGeojson,
50
+ convertBinaryFeatureCollectionToGeojson as binaryToGeojson
51
+ } from './lib/feature-collection-converters/convert-binary-features-to-geojson';
52
+
53
+ // GEOMETRY ENCODING DETECTION
54
+ export {isWKB, isTWKB, isWKT} from './lib/geometry-converters/wkb/helpers/parse-wkb-header';
55
+
56
+ export type {WKBHeader} from './lib/geometry-converters/wkb/helpers/wkb-types';
57
+ export {WKT_MAGIC_STRINGS} from './lib/geometry-converters/wkb/helpers/wkb-types';
58
+
59
+ // GEOMETRY CONVERSION
60
+ export {convertBinaryGeometryToGeometry} from './lib/geometry-converters/convert-binary-geometry-to-geojson';
61
+
62
+ export {convertWKTToGeometry} from './lib/geometry-converters/wkb/convert-wkt-to-geometry';
63
+ export {convertWKBToGeometry} from './lib/geometry-converters/wkb/convert-wkb-to-geometry';
64
+ export {convertWKBToBinaryGeometry} from './lib/geometry-converters/wkb/convert-wkb-to-binary-geometry';
65
+ export {convertTWKBToGeometry} from './lib/geometry-converters/wkb/convert-twkb-to-geometry';
66
+
67
+ export {convertGeometryToWKT} from './lib/geometry-converters/wkb/convert-geometry-to-wkt';
68
+ export {convertGeometryToWKB} from './lib/geometry-converters/wkb/convert-geometry-to-wkb';
69
+ export {convertGeometryToTWKB} from './lib/geometry-converters/wkb/convert-geometry-to-twkb';
70
+
71
+ // CRS
72
+ export type {WKTCRS, ParseWKTCRSOptions} from './lib//wkt-crs/parse-wkt-crs';
73
+ export {parseWKTCRS} from './lib//wkt-crs/parse-wkt-crs';
74
+ export type {EncodeWKTCRSOptions} from './lib//wkt-crs/encode-wkt-crs';
75
+ export {encodeWKTCRS} from './lib//wkt-crs/encode-wkt-crs';
76
+
77
+ // GEOARROW
78
+ export type {
79
+ BinaryDataFromGeoArrow,
80
+ BinaryGeometriesFromArrowOptions
81
+ } from './lib/feature-collection-converters/convert-geoarrow-to-binary-features';
82
+ export {
83
+ convertGeoArrowToBinaryFeatureCollection,
84
+ // deprecated
85
+ convertGeoArrowToBinaryFeatureCollection as getBinaryGeometriesFromArrow,
86
+ getBinaryGeometryTemplate,
87
+ getTriangleIndices,
88
+ getMeanCentersFromBinaryGeometries
89
+ } from './lib/feature-collection-converters/convert-geoarrow-to-binary-features';
90
+
91
+ export {convertGeoArrowGeometryToGeoJSON} from './lib/geometry-converters/convert-geoarrow-to-geojson';
92
+
93
+ // EXPERIMENTAL APIs
94
+
95
+ export {encodeHex, decodeHex} from './lib/utils/hex-transcoder';
96
+ export {extractNumericPropTypes as _extractNumericPropTypes} from './lib/feature-collection-converters/convert-flat-geojson-to-binary-features';
@@ -0,0 +1,75 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {BinaryGeometry} from '@loaders.gl/schema';
6
+
7
+ /**
8
+ * Information about a binary geometry
9
+ */
10
+ export type BinaryGeometryInfo = {
11
+ /** The GeoJSON style geometry type corresponding to this particular binary geometry */
12
+ multiGeometryType:
13
+ | 'Point'
14
+ | 'LineString'
15
+ | 'Polygon'
16
+ | 'MultiPoint'
17
+ | 'MultiLineString'
18
+ | 'MultiPolygon';
19
+ /** Is this a "Multi" version of the binary geometry? */
20
+ isMultiGeometry: boolean;
21
+ /** How many dimensions are the coordinates? */
22
+ dimension: number;
23
+ /** How many points does this geometry have? */
24
+ pointCount: number;
25
+ /** How many coordinates does this geometry have? */
26
+ coordinateCount: number;
27
+ };
28
+
29
+ /**
30
+ * @returns information about a binary geometry
31
+ */
32
+ export function getBinaryGeometryInfo(geometry: BinaryGeometry): BinaryGeometryInfo {
33
+ return {
34
+ isMultiGeometry: isMultiGeometryType(geometry),
35
+ multiGeometryType: getMultiGeometryType(geometry),
36
+ dimension: geometry.positions.size,
37
+ pointCount: geometry.positions.value.length / geometry.positions.size,
38
+ coordinateCount: geometry.positions.value.length
39
+ };
40
+ }
41
+
42
+ /** @returns true if a binary geometry corresponds to a MultiPoint, MultiLineString or MultiPolygon */
43
+ function isMultiGeometryType(geometry: BinaryGeometry) {
44
+ switch (geometry.type) {
45
+ case 'Point':
46
+ const {positions} = geometry;
47
+ return positions.value.length / positions.size > 1;
48
+ case 'LineString':
49
+ const {pathIndices} = geometry;
50
+ return pathIndices.value.length > 1;
51
+ case 'Polygon':
52
+ const {polygonIndices} = geometry;
53
+ return polygonIndices.value.length > 1;
54
+ default:
55
+ return false;
56
+ }
57
+ }
58
+
59
+ /**
60
+ * @returns geometry type of binary geometry, including MultiPoint, MultiLineString or MultiPolygon
61
+ */
62
+ function getMultiGeometryType(geometry: BinaryGeometry) {
63
+ const isMulti = isMultiGeometryType(geometry);
64
+ switch (geometry.type) {
65
+ case 'Point':
66
+ return isMulti ? 'MultiPoint' : 'Point';
67
+ case 'LineString':
68
+ return isMulti ? 'MultiLineString' : 'LineString';
69
+ case 'Polygon':
70
+ return isMulti ? 'MultiPolygon' : 'Polygon';
71
+ default:
72
+ // @ts-expect-error
73
+ throw new Error(`Illegal geometry type: ${type}`);
74
+ }
75
+ }
@@ -0,0 +1,78 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {
6
+ TypedArray,
7
+ BinaryPointGeometry,
8
+ BinaryLineGeometry,
9
+ BinaryPolygonGeometry
10
+ } from '@loaders.gl/schema';
11
+ import {concatTypedArrays} from '../utils/concat-typed-arrays';
12
+
13
+ export function concatenateBinaryPointGeometries(
14
+ binaryPointGeometries: BinaryPointGeometry[],
15
+ dimension: number
16
+ ): BinaryPointGeometry {
17
+ const positions: TypedArray[] = binaryPointGeometries.map((geometry) => geometry.positions.value);
18
+ const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
19
+
20
+ return {
21
+ type: 'Point',
22
+ positions: {value: concatenatedPositions, size: dimension}
23
+ };
24
+ }
25
+
26
+ export function concatenateBinaryLineGeometries(
27
+ binaryLineGeometries: BinaryLineGeometry[],
28
+ dimension: number
29
+ ): BinaryLineGeometry {
30
+ const lines: TypedArray[] = binaryLineGeometries.map((geometry) => geometry.positions.value);
31
+ const concatenatedPositions = new Float64Array(concatTypedArrays(lines).buffer);
32
+ const pathIndices = lines.map((line) => line.length / dimension).map(cumulativeSum(0));
33
+ pathIndices.unshift(0);
34
+
35
+ return {
36
+ type: 'LineString',
37
+ positions: {value: concatenatedPositions, size: dimension},
38
+ pathIndices: {value: new Uint32Array(pathIndices), size: 1}
39
+ };
40
+ }
41
+
42
+ export function concatenateBinaryPolygonGeometries(
43
+ binaryPolygonGeometries: BinaryPolygonGeometry[],
44
+ dimension: number
45
+ ): BinaryPolygonGeometry {
46
+ const polygons: TypedArray[] = [];
47
+ const primitivePolygons: TypedArray[] = [];
48
+
49
+ for (const binaryPolygon of binaryPolygonGeometries) {
50
+ const {positions, primitivePolygonIndices} = binaryPolygon;
51
+ polygons.push(positions.value);
52
+ primitivePolygons.push(primitivePolygonIndices.value);
53
+ }
54
+
55
+ const concatenatedPositions = new Float64Array(concatTypedArrays(polygons).buffer);
56
+ const polygonIndices = polygons.map((p) => p.length / dimension).map(cumulativeSum(0));
57
+ polygonIndices.unshift(0);
58
+
59
+ // Combine primitivePolygonIndices from each individual polygon
60
+ const primitivePolygonIndices = [0];
61
+ for (const primitivePolygon of primitivePolygons) {
62
+ primitivePolygonIndices.push(
63
+ ...primitivePolygon
64
+ .filter((x: number) => x > 0)
65
+ .map((x: number) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1])
66
+ );
67
+ }
68
+
69
+ return {
70
+ type: 'Polygon',
71
+ positions: {value: concatenatedPositions, size: dimension},
72
+ polygonIndices: {value: new Uint32Array(polygonIndices), size: 1},
73
+ primitivePolygonIndices: {value: new Uint32Array(primitivePolygonIndices), size: 1}
74
+ };
75
+ }
76
+
77
+ // https://stackoverflow.com/a/55261098
78
+ const cumulativeSum = (sum: number) => (value: number) => (sum += value);
@@ -38,7 +38,6 @@ function transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: Tr
38
38
 
39
39
  /**
40
40
  * Apply transformation to every coordinate of GeoJSON features
41
- *
42
41
  * @param features Array of GeoJSON features
43
42
  * @param fn Function to call on each coordinate
44
43
  * @return Transformed GeoJSON features
@@ -3,30 +3,18 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {
6
- BinaryGeometry,
7
6
  BinaryGeometryType,
8
- BinaryPointGeometry,
9
- BinaryLineGeometry,
10
- BinaryPolygonGeometry,
11
7
  BinaryFeatureCollection,
12
8
  BinaryFeature,
13
9
  // BinaryPointFeature,
14
10
  // BinaryLineFeature,
15
11
  // BinaryPolygonFeature,
16
- BinaryAttribute,
17
12
  Feature,
18
- Geometry,
19
- Position,
20
- GeoJsonProperties,
21
- Point,
22
- MultiPoint,
23
- LineString,
24
- MultiLineString,
25
- Polygon,
26
- MultiPolygon
13
+ GeoJsonProperties
27
14
  } from '@loaders.gl/schema';
15
+ import {convertBinaryGeometryToGeometry} from '../geometry-converters/convert-binary-geometry-to-geojson';
28
16
 
29
- // Note:L We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.
17
+ // Note: We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.
30
18
  // type FeatureGeometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
31
19
 
32
20
  type BinaryToGeoJsonOptions = {
@@ -42,7 +30,7 @@ type BinaryToGeoJsonOptions = {
42
30
  * @param options.featureId Global feature id. If specified, only a single feature is extracted
43
31
  * @return GeoJSON objects
44
32
  */
45
- export function binaryToGeojson(
33
+ export function convertBinaryFeatureCollectionToGeojson(
46
34
  data: BinaryFeatureCollection,
47
35
  options?: BinaryToGeoJsonOptions
48
36
  ): Feature[] | Feature {
@@ -91,25 +79,6 @@ function parseFeatures(data: BinaryFeatureCollection, type?: BinaryGeometryType)
91
79
  return parseFeatureCollection(dataArray);
92
80
  }
93
81
 
94
- /** Parse input binary data and return a valid GeoJSON geometry object */
95
- export function binaryToGeometry(
96
- data: BinaryGeometry,
97
- startIndex?: number,
98
- endIndex?: number
99
- ): Geometry {
100
- switch (data.type) {
101
- case 'Point':
102
- return pointToGeoJson(data, startIndex, endIndex);
103
- case 'LineString':
104
- return lineStringToGeoJson(data, startIndex, endIndex);
105
- case 'Polygon':
106
- return polygonToGeoJson(data, startIndex, endIndex);
107
- default:
108
- const unexpectedInput: never = data;
109
- throw new Error(`Unsupported geometry type: ${(unexpectedInput as any)?.type}`);
110
- }
111
- }
112
-
113
82
  // Normalize features
114
83
  // Return an array of data objects, each of which have a type key
115
84
  function normalizeInput(data: BinaryFeatureCollection, type?: BinaryGeometryType): BinaryFeature[] {
@@ -162,7 +131,7 @@ function parseFeatureCollection(dataArray: BinaryFeature[]): Feature[] {
162
131
 
163
132
  /** Parse input binary data and return a single GeoJSON Feature */
164
133
  function parseFeature(data: BinaryFeature, startIndex?: number, endIndex?: number): Feature {
165
- const geometry = binaryToGeometry(data, startIndex, endIndex);
134
+ const geometry = convertBinaryGeometryToGeometry(data, startIndex, endIndex);
166
135
  const properties = parseProperties(data, startIndex, endIndex);
167
136
  const fields = parseFields(data, startIndex, endIndex);
168
137
  return {type: 'Feature', geometry, properties, ...fields};
@@ -181,109 +150,3 @@ function parseProperties(data, startIndex: number = 0, endIndex?: number): GeoJs
181
150
  }
182
151
  return properties;
183
152
  }
184
-
185
- /** Parse binary data of type Polygon */
186
- function polygonToGeoJson(
187
- data: BinaryPolygonGeometry,
188
- startIndex: number = -Infinity,
189
- endIndex: number = Infinity
190
- ): Polygon | MultiPolygon {
191
- const {positions} = data;
192
- const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
193
- const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(
194
- (x) => x >= startIndex && x <= endIndex
195
- );
196
- const multi = polygonIndices.length > 2;
197
-
198
- // Polygon
199
- if (!multi) {
200
- const coordinates: Position[][] = [];
201
- for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
202
- const startRingIndex = primitivePolygonIndices[i];
203
- const endRingIndex = primitivePolygonIndices[i + 1];
204
- const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
205
- coordinates.push(ringCoordinates);
206
- }
207
-
208
- return {type: 'Polygon', coordinates};
209
- }
210
-
211
- // MultiPolygon
212
- const coordinates: Position[][][] = [];
213
- for (let i = 0; i < polygonIndices.length - 1; i++) {
214
- const startPolygonIndex = polygonIndices[i];
215
- const endPolygonIndex = polygonIndices[i + 1];
216
- const polygonCoordinates = polygonToGeoJson(
217
- data,
218
- startPolygonIndex,
219
- endPolygonIndex
220
- ).coordinates;
221
- coordinates.push(polygonCoordinates as Position[][]);
222
- }
223
-
224
- return {type: 'MultiPolygon', coordinates};
225
- }
226
-
227
- /** Parse binary data of type LineString */
228
- function lineStringToGeoJson(
229
- data: BinaryLineGeometry,
230
- startIndex: number = -Infinity,
231
- endIndex: number = Infinity
232
- ): LineString | MultiLineString {
233
- const {positions} = data;
234
- const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
235
- const multi = pathIndices.length > 2;
236
-
237
- if (!multi) {
238
- const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
239
- return {type: 'LineString', coordinates};
240
- }
241
-
242
- const coordinates: Position[][] = [];
243
- for (let i = 0; i < pathIndices.length - 1; i++) {
244
- const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
245
- coordinates.push(ringCoordinates);
246
- }
247
-
248
- return {type: 'MultiLineString', coordinates};
249
- }
250
-
251
- /** Parse binary data of type Point */
252
- function pointToGeoJson(data: BinaryPointGeometry, startIndex, endIndex): Point | MultiPoint {
253
- const {positions} = data;
254
- const coordinates = ringToGeoJson(positions, startIndex, endIndex);
255
- const multi = coordinates.length > 1;
256
-
257
- if (multi) {
258
- return {type: 'MultiPoint', coordinates};
259
- }
260
-
261
- return {type: 'Point', coordinates: coordinates[0]};
262
- }
263
-
264
- /**
265
- * Parse a linear ring of positions to a GeoJSON linear ring
266
- *
267
- * @param positions Positions TypedArray
268
- * @param startIndex Start index to include in ring
269
- * @param endIndex End index to include in ring
270
- * @returns GeoJSON ring
271
- */
272
- function ringToGeoJson(
273
- positions: BinaryAttribute,
274
- startIndex?: number,
275
- endIndex?: number
276
- ): Position[] {
277
- startIndex = startIndex || 0;
278
- endIndex = endIndex || positions.value.length / positions.size;
279
-
280
- const ringCoordinates: Position[] = [];
281
- for (let j = startIndex; j < endIndex; j++) {
282
- const coord = Array<number>();
283
- for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
284
- coord.push(Number(positions.value[k]));
285
- }
286
- ringCoordinates.push(coord);
287
- }
288
- return ringCoordinates;
289
- }
@@ -1,3 +1,7 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  /* eslint-disable indent */
2
6
  import {earcut} from '@math.gl/polygon';
3
7
  import type {
@@ -8,10 +12,15 @@ import type {
8
12
  FlatPoint,
9
13
  FlatLineString,
10
14
  FlatPolygon,
11
- GeojsonGeometryInfo,
12
15
  TypedArray
13
16
  } from '@loaders.gl/schema';
14
- import {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-binary-types';
17
+ import {GeojsonGeometryInfo} from '../geometry-api/geometry-info';
18
+ import {
19
+ PropArrayConstructor,
20
+ Lines,
21
+ Points,
22
+ Polygons
23
+ } from './helpers/flat-geojson-to-binary-types';
15
24
 
16
25
  /**
17
26
  * Convert binary features to flat binary arrays. Similar to
@@ -26,11 +35,11 @@ import {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-b
26
35
  * @param options
27
36
  * @returns filled arrays
28
37
  */
29
- export function flatGeojsonToBinary(
38
+ export function convertFlatGeojsonToBinaryFeatureCollection(
30
39
  features: FlatFeature[],
31
40
  geometryInfo: GeojsonGeometryInfo,
32
41
  options?: FlatGeojsonToBinaryOptions
33
- ) {
42
+ ): BinaryFeatureCollection {
34
43
  const propArrayTypes = extractNumericPropTypes(features);
35
44
  const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
36
45
  return fillArrays(
@@ -56,17 +65,13 @@ export type FlatGeojsonToBinaryOptions = {
56
65
  triangulate?: boolean;
57
66
  };
58
67
 
59
- export const TEST_EXPORTS = {
60
- extractNumericPropTypes
61
- };
62
-
63
68
  /**
64
69
  * Extracts properties that are always numeric
65
70
  *
66
71
  * @param features
67
72
  * @returns object with numeric types
68
73
  */
69
- function extractNumericPropTypes(features: FlatFeature[]): {
74
+ export function extractNumericPropTypes(features: FlatFeature[]): {
70
75
  [key: string]: PropArrayConstructor;
71
76
  } {
72
77
  const propArrayTypes = {};