whitebox-wasm 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # whitebox-wasm
2
2
 
3
- **Pure-Rust GeoTIFF decoding compiled to WebAssembly.** No GDAL, no PROJ, no
4
- native libraries, no server. Decode GeoTIFF / BigTIFF / COG entirely in the
5
- browser, Node, Deno, or any Wasm host.
3
+ **Pure-Rust geospatial toolkit compiled to WebAssembly.** No GDAL, no PROJ, no
4
+ native libraries, no server. Work with raster, vector, and LiDAR data entirely
5
+ in the browser, Node, Deno, or any Wasm host:
6
+
7
+ - **Raster** - read/write GeoTIFF / BigTIFF / COG, stats, range-request streaming
8
+ - **Projections** - full EPSG + user-defined CRS to WGS84 lon/lat
9
+ - **Vector** - read GeoJSON, TopoJSON, GML, GPX, KML, FlatGeobuf, GeoPackage, KMZ -> GeoJSON, with reprojection
10
+ - **LiDAR** - read LAS / LAZ / PLY point clouds (xyz, classification, intensity)
11
+ - **Analysis** - convex hull, Moran's I spatial autocorrelation
12
+ - **Tools** - the full WhiteboxTools suite (733 tools) via `whitebox-wasm/tools`
6
13
 
7
14
  This wraps `wbgeotiff`, the shared GeoTIFF engine from the original
8
15
  [**whitebox_next_gen**](https://github.com/jblindsay/whitebox_next_gen) project
@@ -132,6 +139,74 @@ window). Requires a tiled COG on a server that supports HTTP range requests.
132
139
 
133
140
  JSON-returning functions report failures as `{"ok":false,"error":"..."}`; class methods throw on error.
134
141
 
142
+ ## Vector
143
+
144
+ ```js
145
+ import init, { vector_to_geojson, vector_info, vector_to_geojson_reproject } from "whitebox-wasm";
146
+ await init();
147
+ const bytes = new Uint8Array(await (await fetch("data.fgb")).arrayBuffer());
148
+ const geojson = JSON.parse(vector_to_geojson(bytes, "flatgeobuf"));
149
+ const meta = JSON.parse(vector_info(bytes, "flatgeobuf")); // { features, geometry, epsg, fields, bbox }
150
+ const wgs84 = vector_to_geojson_reproject(bytes, "flatgeobuf", 4326, 0); // dst, src(0=auto)
151
+ ```
152
+
153
+ - `vector_formats()` -> supported formats (geojson, topojson, gml, gpx, kml, flatgeobuf, geopackage, kmz)
154
+ - `vector_to_geojson(data, format)` -> GeoJSON string
155
+ - `vector_to_geojson_reproject(data, format, dst_epsg, src_epsg)` -> reprojected GeoJSON (`src_epsg=0` uses the layer CRS, or 4326)
156
+ - `vector_info(data, format)` -> JSON `{name, features, geometry, epsg, fields, bbox}`
157
+
158
+ ## LiDAR
159
+
160
+ ```js
161
+ import init, { lidar_info, lidar_read_xyz } from "whitebox-wasm";
162
+ await init();
163
+ const las = new Uint8Array(await (await fetch("cloud.laz")).arrayBuffer());
164
+ const meta = JSON.parse(lidar_info(las, "laz")); // { points, epsg, point_format, bounds }
165
+ const xyz = lidar_read_xyz(las, "laz"); // Float64Array [x0,y0,z0, x1,y1,z1, ...]
166
+ ```
167
+
168
+ - `lidar_formats()`, `lidar_info(data, format)` (header-only count/bounds for LAS/LAZ)
169
+ - `lidar_read_xyz` -> `Float64Array`; `lidar_read_classification` -> `Uint8Array`; `lidar_read_intensity` -> `Uint16Array`
170
+
171
+ ## Analysis
172
+
173
+ - `convex_hull(points_xy)` -> hull ring `Float64Array` (input `[x0,y0,x1,y1,...]`)
174
+ - `morans_i(points_xy, values, distance_threshold)` -> JSON global spatial autocorrelation `{morans_i, expected, variance, z_score, p_value, n}`
175
+
176
+ ## Tools (the full WhiteboxTools suite)
177
+
178
+ The `whitebox-wasm/tools` subpath runs the complete **WhiteboxTools** algorithm
179
+ suite (**733 tools** - slope, filters, hydrology, geomorphometry, vector ops,
180
+ ...). The tools are path-based, so they run through an in-memory WASI filesystem
181
+ (bundled `whitebox-cli.wasm`); raster outputs are Cloud Optimized GeoTIFFs.
182
+
183
+ ```js
184
+ import { runTool, listTools } from "whitebox-wasm/tools";
185
+
186
+ console.log((await listTools()).length); // 733
187
+
188
+ // raster: slope -> a COG
189
+ const { files } = await runTool("slope", {
190
+ args: ["--input=/work/dem.tif", "--output=/work/slope.tif", "--units=degrees"],
191
+ input: { "dem.tif": demBytes }, // Uint8Array, placed under /work
192
+ });
193
+ const slopeCog = files["slope.tif"]; // Uint8Array (tiled, Deflate, overviews)
194
+
195
+ // vector: convex hull -> GeoJSON
196
+ const hull = await runTool("minimum_convex_hull", {
197
+ args: ["--input=/work/in.geojson", "--output=/work/hull.geojson"],
198
+ input: { "in.geojson": geojsonBytes },
199
+ });
200
+ ```
201
+
202
+ - `listTools()` -> `string[]` of tool ids
203
+ - `runTool(id, { args, input })` -> `{ exitCode, stdout, files }` (`files` = outputs the tool wrote)
204
+ - `initTools(source?)` -> compile the runner; in Node pass the wasm bytes (browsers/bundlers omit it)
205
+
206
+ Needs the `@bjorn3/browser_wasi_shim` peer (declared as a dependency). The
207
+ `whitebox-cli.wasm` (~5 MB gzipped) is only fetched the first time you call a
208
+ tool, so the rest of the library stays lightweight.
209
+
135
210
  ## Limits
136
211
 
137
212
  WebAssembly is 32-bit, so linear memory is capped at ~4 GiB. `geotiff_info` is
@@ -147,5 +222,5 @@ decoded in-browser). For such data, read metadata only or process server-side.
147
222
  ## License
148
223
 
149
224
  Dual-licensed under MIT or Apache-2.0, at your option. Includes the vendored
150
- `wbgeotiff` and `wbprojection` crates (Copyright John Lindsay, Whitebox
225
+ `wbgeotiff`, `wbprojection`, `wbvector`, `wblidar`, `wbtopology`, `wbspatialstats`, and `wbhdf` crates (Copyright John Lindsay, Whitebox
151
226
  Geospatial Inc.), used under the same dual license.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "whitebox-wasm",
3
3
  "type": "module",
4
- "description": "WebAssembly bindings for the pure-Rust Whitebox GeoTIFF engine",
5
- "version": "0.2.0",
4
+ "description": "Pure-Rust geospatial toolkit (raster, vector, LiDAR, projections) compiled to WebAssembly",
5
+ "version": "0.4.0",
6
6
  "license": "MIT OR Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -11,7 +11,10 @@
11
11
  "files": [
12
12
  "whitebox_wasm_bg.wasm",
13
13
  "whitebox_wasm.js",
14
- "whitebox_wasm.d.ts"
14
+ "whitebox_wasm.d.ts",
15
+ "whitebox-cli.wasm",
16
+ "tools.mjs",
17
+ "tools.d.ts"
15
18
  ],
16
19
  "main": "whitebox_wasm.js",
17
20
  "homepage": "https://github.com/opengeos/whitebox-wasm",
@@ -20,10 +23,23 @@
20
23
  "./snippets/*"
21
24
  ],
22
25
  "keywords": [
23
- "geotiff",
26
+ "geospatial",
24
27
  "wasm",
25
28
  "gis",
26
- "raster",
27
- "webassembly"
28
- ]
29
+ "geotiff",
30
+ "lidar"
31
+ ],
32
+ "dependencies": {
33
+ "@bjorn3/browser_wasi_shim": "^0.4.2"
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "types": "./whitebox_wasm.d.ts",
38
+ "default": "./whitebox_wasm.js"
39
+ },
40
+ "./tools": {
41
+ "types": "./tools.d.ts",
42
+ "default": "./tools.mjs"
43
+ }
44
+ }
29
45
  }
package/tools.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /** Result of running a tool. */
2
+ export interface ToolResult {
3
+ /** Process exit code (0 = success). */
4
+ exitCode: number;
5
+ /** Captured stdout/stderr lines. */
6
+ stdout: string[];
7
+ /** New files the tool wrote, keyed by filename (e.g. the --output path's basename). */
8
+ files: Record<string, Uint8Array>;
9
+ }
10
+
11
+ export interface RunToolOptions {
12
+ /** CLI args, e.g. ["--input=/work/dem.tif", "--output=/work/out.tif", "--units=degrees"]. */
13
+ args?: string[];
14
+ /** Input files placed under /work, keyed by filename. */
15
+ input?: Record<string, Uint8Array>;
16
+ }
17
+
18
+ /** Compile the WASI tool runner once. Omit `source` in browsers/bundlers; pass
19
+ * the wasm bytes or a URL/Response in Node. */
20
+ export function initTools(source?: URL | Response | BufferSource | string): Promise<WebAssembly.Module>;
21
+
22
+ /** List every available tool id. */
23
+ export function listTools(): Promise<string[]>;
24
+
25
+ /** Run one tool over an in-memory filesystem. */
26
+ export function runTool(tool: string, opts?: RunToolOptions): Promise<ToolResult>;
package/tools.mjs ADDED
@@ -0,0 +1,83 @@
1
+ // whitebox-wasm/tools - run the WhiteboxTools (wbtools_oss) algorithm suite from
2
+ // JavaScript. The tools are the WASI binary `whitebox-cli.wasm` (733 path-based
3
+ // tools); this module executes them through a WASI shim with an in-memory
4
+ // filesystem, so they run in browsers, Node, Deno, and bundlers without a real
5
+ // disk. Raster outputs are Cloud Optimized GeoTIFFs.
6
+ //
7
+ // import { runTool, listTools } from "whitebox-wasm/tools";
8
+ // const { files } = await runTool("slope", {
9
+ // args: ["--input=/work/dem.tif", "--output=/work/slope.tif", "--units=degrees"],
10
+ // input: { "dem.tif": demBytes }, // Uint8Array, placed under /work
11
+ // });
12
+ // const slopeCog = files["slope.tif"]; // Uint8Array
13
+ import { WASI, File, OpenFile, ConsoleStdout, PreopenDirectory } from "@bjorn3/browser_wasi_shim";
14
+
15
+ let _module = null;
16
+
17
+ /**
18
+ * Compile the WASI tool runner once. In browsers/bundlers it loads the bundled
19
+ * `whitebox-cli.wasm` relative to this module. In Node (no fetch of file URLs),
20
+ * pass the wasm bytes or a URL/Response explicitly.
21
+ * @param {URL|Response|BufferSource|string} [source]
22
+ * @returns {Promise<WebAssembly.Module>}
23
+ */
24
+ export async function initTools(source) {
25
+ if (_module) return _module;
26
+ if (!source) source = new URL("./whitebox-cli.wasm", import.meta.url);
27
+ if (source instanceof Uint8Array || source instanceof ArrayBuffer) {
28
+ _module = await WebAssembly.compile(source);
29
+ } else if (source instanceof Response) {
30
+ _module = await WebAssembly.compileStreaming(source);
31
+ } else {
32
+ _module = await WebAssembly.compileStreaming(fetch(source));
33
+ }
34
+ return _module;
35
+ }
36
+
37
+ async function exec(argv, inputFiles) {
38
+ const mod = await initTools();
39
+ const inNames = new Set(Object.keys(inputFiles));
40
+ const contents = new Map(
41
+ Object.entries(inputFiles).map(([k, v]) => [k, new File(new Uint8Array(v))]));
42
+ const work = new PreopenDirectory("/work", contents);
43
+ const stdout = [];
44
+ const fds = [
45
+ new OpenFile(new File(new Uint8Array())),
46
+ ConsoleStdout.lineBuffered((s) => stdout.push(s)),
47
+ ConsoleStdout.lineBuffered((s) => stdout.push(s)),
48
+ work,
49
+ ];
50
+ const wasi = new WASI(["whitebox", ...argv], [], fds, { debug: false });
51
+ const inst = await WebAssembly.instantiate(mod, { wasi_snapshot_preview1: wasi.wasiImport });
52
+ let exitCode = 0;
53
+ try { exitCode = wasi.start(inst); }
54
+ catch (e) { if (e && e.constructor && e.constructor.name === "WASIProcExit") exitCode = e.code; else throw e; }
55
+ const files = {};
56
+ for (const [name, entry] of work.dir.contents) {
57
+ if (entry.data && !inNames.has(name)) files[name] = entry.data;
58
+ }
59
+ return { exitCode, stdout, files };
60
+ }
61
+
62
+ /**
63
+ * List every available tool id (733 of them).
64
+ * @returns {Promise<string[]>}
65
+ */
66
+ export async function listTools() {
67
+ const { stdout } = await exec(["list"], {});
68
+ return stdout.map((s) => s.trim()).filter((s) => s && !/tools:$/.test(s));
69
+ }
70
+
71
+ /**
72
+ * Run one tool over an in-memory filesystem.
73
+ * @param {string} tool tool id, e.g. "slope" (see {@link listTools})
74
+ * @param {object} [opts]
75
+ * @param {string[]} [opts.args] CLI args, e.g. ["--input=/work/dem.tif","--output=/work/out.tif","--units=degrees"]
76
+ * @param {Object<string, Uint8Array>} [opts.input] files placed under /work (key = filename)
77
+ * @returns {Promise<{exitCode:number, stdout:string[], files:Object<string,Uint8Array>}>}
78
+ * `files` contains any new files the tool wrote (e.g. the --output path).
79
+ */
80
+ export async function runTool(tool, opts = {}) {
81
+ const { args = [], input = {} } = opts;
82
+ return exec([tool, ...args], input);
83
+ }
Binary file
@@ -248,6 +248,12 @@ export class GeoTiffReader {
248
248
  */
249
249
  export function __start(): void;
250
250
 
251
+ /**
252
+ * Convex hull of a 2D point set. Input is `[x0,y0,x1,y1,...]`; output is the
253
+ * hull ring as `[x0,y0,...]` (closed). Needs at least 3 points.
254
+ */
255
+ export function convex_hull(points_xy: Float64Array): Float64Array;
256
+
251
257
  /**
252
258
  * Decode only a GeoTIFF's header and return its metadata as JSON. O(header)
253
259
  * memory, so it works on multi-gigabyte rasters that whole-image reads cannot
@@ -270,6 +276,75 @@ export function geotiff_read_band_f64(data: Uint8Array, band: number): Float64Ar
270
276
  */
271
277
  export function geotiff_stats(data: Uint8Array): string;
272
278
 
279
+ /**
280
+ * LiDAR formats this build can read from memory.
281
+ */
282
+ export function lidar_formats(): string;
283
+
284
+ /**
285
+ * Read a LiDAR file's metadata as JSON. For LAS/LAZ this is header-only (count,
286
+ * bounds, CRS, point format, COPC flag) and never decodes points:
287
+ * `{"ok":true,"format","points","epsg"|null,"point_format"|null,
288
+ * "bounds":[min_x,min_y,min_z,max_x,max_y,max_z]|null,"copc":bool}`.
289
+ */
290
+ export function lidar_info(data: Uint8Array, format: string): string;
291
+
292
+ /**
293
+ * Read per-point classification codes as a `Uint8Array` (length `point_count`).
294
+ */
295
+ export function lidar_read_classification(data: Uint8Array, format: string): Uint8Array;
296
+
297
+ /**
298
+ * Read per-point intensity as a `Uint16Array` (length `point_count`).
299
+ */
300
+ export function lidar_read_intensity(data: Uint8Array, format: string): Uint16Array;
301
+
302
+ /**
303
+ * Read all point coordinates as an interleaved `Float64Array`
304
+ * `[x0,y0,z0, x1,y1,z1, ...]` (length `3 * point_count`).
305
+ *
306
+ * Guarded against 32-bit memory blowup; very large clouds return a clean error
307
+ * (read the header with `lidar_info`, or downsample on your side).
308
+ */
309
+ export function lidar_read_xyz(data: Uint8Array, format: string): Float64Array;
310
+
311
+ /**
312
+ * Global Moran's I spatial autocorrelation for point data, using a binary
313
+ * distance-band spatial weights matrix (neighbors within `distance_threshold`).
314
+ *
315
+ * `points_xy` is `[x0,y0,...]`, `values` is one value per point. Returns JSON:
316
+ * `{"ok":true,"morans_i","expected","variance","z_score","p_value","n"}`.
317
+ *
318
+ * Builds neighbors in O(n^2); intended for up to a few thousand points.
319
+ */
320
+ export function morans_i(points_xy: Float64Array, values: Float64Array, distance_threshold: number): string;
321
+
322
+ /**
323
+ * Vector formats this build can read from memory (comma-separated).
324
+ */
325
+ export function vector_formats(): string;
326
+
327
+ /**
328
+ * Read a vector dataset and return metadata as JSON:
329
+ * `{"ok":true,"name","features","geometry","epsg"|null,"fields":[...],
330
+ * "bbox":[min_x,min_y,max_x,max_y]|null}`.
331
+ */
332
+ export function vector_info(data: Uint8Array, format: string): string;
333
+
334
+ /**
335
+ * Read a vector dataset and return it as a GeoJSON `FeatureCollection` string.
336
+ */
337
+ export function vector_to_geojson(data: Uint8Array, format: string): string;
338
+
339
+ /**
340
+ * Read a vector dataset, reproject it to `dst_epsg`, and return GeoJSON.
341
+ * Uses the bundled pure-Rust projection engine (full EPSG support).
342
+ *
343
+ * `src_epsg` overrides the source CRS: pass `0` to use the layer's own CRS, or
344
+ * fall back to EPSG:4326 if it declares none (GeoJSON is WGS84 by RFC 7946).
345
+ */
346
+ export function vector_to_geojson_reproject(data: Uint8Array, format: string, dst_epsg: number, src_epsg: number): string;
347
+
273
348
  /**
274
349
  * Semantic version of this crate, exposed for runtime feature detection.
275
350
  */
@@ -279,6 +354,7 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
279
354
 
280
355
  export interface InitOutput {
281
356
  readonly memory: WebAssembly.Memory;
357
+ readonly __start: () => void;
282
358
  readonly __wbg_cogbuilder_free: (a: number, b: number) => void;
283
359
  readonly __wbg_cogstream_free: (a: number, b: number) => void;
284
360
  readonly __wbg_geotiffreader_free: (a: number, b: number) => void;
@@ -307,6 +383,7 @@ export interface InitOutput {
307
383
  readonly cogstream_num_levels: (a: number) => number;
308
384
  readonly cogstream_tile_range: (a: number, b: number, c: number, d: number, e: number) => void;
309
385
  readonly cogstream_tiles_for_window: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
386
+ readonly convex_hull: (a: number, b: number, c: number) => void;
310
387
  readonly geotiff_info: (a: number, b: number, c: number) => void;
311
388
  readonly geotiff_read_band_f64: (a: number, b: number, c: number, d: number) => void;
312
389
  readonly geotiff_stats: (a: number, b: number, c: number) => void;
@@ -338,8 +415,25 @@ export interface InitOutput {
338
415
  readonly geotiffreader_stats_json: (a: number, b: number) => void;
339
416
  readonly geotiffreader_value_transform: (a: number, b: number) => void;
340
417
  readonly geotiffreader_width: (a: number) => number;
418
+ readonly lidar_formats: (a: number) => void;
419
+ readonly lidar_info: (a: number, b: number, c: number, d: number, e: number) => void;
420
+ readonly lidar_read_classification: (a: number, b: number, c: number, d: number, e: number) => void;
421
+ readonly lidar_read_intensity: (a: number, b: number, c: number, d: number, e: number) => void;
422
+ readonly lidar_read_xyz: (a: number, b: number, c: number, d: number, e: number) => void;
423
+ readonly morans_i: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
424
+ readonly vector_formats: (a: number) => void;
425
+ readonly vector_info: (a: number, b: number, c: number, d: number, e: number) => void;
426
+ readonly vector_to_geojson: (a: number, b: number, c: number, d: number, e: number) => void;
427
+ readonly vector_to_geojson_reproject: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
341
428
  readonly version: (a: number) => void;
342
- readonly __start: () => void;
429
+ readonly rust_zstd_wasm_shim_calloc: (a: number, b: number) => number;
430
+ readonly rust_zstd_wasm_shim_free: (a: number) => void;
431
+ readonly rust_zstd_wasm_shim_malloc: (a: number) => number;
432
+ readonly rust_zstd_wasm_shim_memcmp: (a: number, b: number, c: number) => number;
433
+ readonly rust_zstd_wasm_shim_memcpy: (a: number, b: number, c: number) => number;
434
+ readonly rust_zstd_wasm_shim_memmove: (a: number, b: number, c: number) => number;
435
+ readonly rust_zstd_wasm_shim_memset: (a: number, b: number, c: number) => number;
436
+ readonly rust_zstd_wasm_shim_qsort: (a: number, b: number, c: number, d: number) => void;
343
437
  readonly __wbindgen_export: (a: number, b: number, c: number) => void;
344
438
  readonly __wbindgen_export2: (a: number, b: number) => number;
345
439
  readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
package/whitebox_wasm.js CHANGED
@@ -989,6 +989,33 @@ export function __start() {
989
989
  wasm.__start();
990
990
  }
991
991
 
992
+ /**
993
+ * Convex hull of a 2D point set. Input is `[x0,y0,x1,y1,...]`; output is the
994
+ * hull ring as `[x0,y0,...]` (closed). Needs at least 3 points.
995
+ * @param {Float64Array} points_xy
996
+ * @returns {Float64Array}
997
+ */
998
+ export function convex_hull(points_xy) {
999
+ try {
1000
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1001
+ const ptr0 = passArrayF64ToWasm0(points_xy, wasm.__wbindgen_export2);
1002
+ const len0 = WASM_VECTOR_LEN;
1003
+ wasm.convex_hull(retptr, ptr0, len0);
1004
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1005
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1006
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1007
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1008
+ if (r3) {
1009
+ throw takeObject(r2);
1010
+ }
1011
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
1012
+ wasm.__wbindgen_export(r0, r1 * 8, 8);
1013
+ return v2;
1014
+ } finally {
1015
+ wasm.__wbindgen_add_to_stack_pointer(16);
1016
+ }
1017
+ }
1018
+
992
1019
  /**
993
1020
  * Decode only a GeoTIFF's header and return its metadata as JSON. O(header)
994
1021
  * memory, so it works on multi-gigabyte rasters that whole-image reads cannot
@@ -1071,6 +1098,332 @@ export function geotiff_stats(data) {
1071
1098
  }
1072
1099
  }
1073
1100
 
1101
+ /**
1102
+ * LiDAR formats this build can read from memory.
1103
+ * @returns {string}
1104
+ */
1105
+ export function lidar_formats() {
1106
+ let deferred1_0;
1107
+ let deferred1_1;
1108
+ try {
1109
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1110
+ wasm.lidar_formats(retptr);
1111
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1112
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1113
+ deferred1_0 = r0;
1114
+ deferred1_1 = r1;
1115
+ return getStringFromWasm0(r0, r1);
1116
+ } finally {
1117
+ wasm.__wbindgen_add_to_stack_pointer(16);
1118
+ wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
1119
+ }
1120
+ }
1121
+
1122
+ /**
1123
+ * Read a LiDAR file's metadata as JSON. For LAS/LAZ this is header-only (count,
1124
+ * bounds, CRS, point format, COPC flag) and never decodes points:
1125
+ * `{"ok":true,"format","points","epsg"|null,"point_format"|null,
1126
+ * "bounds":[min_x,min_y,min_z,max_x,max_y,max_z]|null,"copc":bool}`.
1127
+ * @param {Uint8Array} data
1128
+ * @param {string} format
1129
+ * @returns {string}
1130
+ */
1131
+ export function lidar_info(data, format) {
1132
+ let deferred4_0;
1133
+ let deferred4_1;
1134
+ try {
1135
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1136
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export2);
1137
+ const len0 = WASM_VECTOR_LEN;
1138
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
1139
+ const len1 = WASM_VECTOR_LEN;
1140
+ wasm.lidar_info(retptr, ptr0, len0, ptr1, len1);
1141
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1142
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1143
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1144
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1145
+ var ptr3 = r0;
1146
+ var len3 = r1;
1147
+ if (r3) {
1148
+ ptr3 = 0; len3 = 0;
1149
+ throw takeObject(r2);
1150
+ }
1151
+ deferred4_0 = ptr3;
1152
+ deferred4_1 = len3;
1153
+ return getStringFromWasm0(ptr3, len3);
1154
+ } finally {
1155
+ wasm.__wbindgen_add_to_stack_pointer(16);
1156
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
1157
+ }
1158
+ }
1159
+
1160
+ /**
1161
+ * Read per-point classification codes as a `Uint8Array` (length `point_count`).
1162
+ * @param {Uint8Array} data
1163
+ * @param {string} format
1164
+ * @returns {Uint8Array}
1165
+ */
1166
+ export function lidar_read_classification(data, format) {
1167
+ try {
1168
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1169
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export2);
1170
+ const len0 = WASM_VECTOR_LEN;
1171
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
1172
+ const len1 = WASM_VECTOR_LEN;
1173
+ wasm.lidar_read_classification(retptr, ptr0, len0, ptr1, len1);
1174
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1175
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1176
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1177
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1178
+ if (r3) {
1179
+ throw takeObject(r2);
1180
+ }
1181
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
1182
+ wasm.__wbindgen_export(r0, r1 * 1, 1);
1183
+ return v3;
1184
+ } finally {
1185
+ wasm.__wbindgen_add_to_stack_pointer(16);
1186
+ }
1187
+ }
1188
+
1189
+ /**
1190
+ * Read per-point intensity as a `Uint16Array` (length `point_count`).
1191
+ * @param {Uint8Array} data
1192
+ * @param {string} format
1193
+ * @returns {Uint16Array}
1194
+ */
1195
+ export function lidar_read_intensity(data, format) {
1196
+ try {
1197
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1198
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export2);
1199
+ const len0 = WASM_VECTOR_LEN;
1200
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
1201
+ const len1 = WASM_VECTOR_LEN;
1202
+ wasm.lidar_read_intensity(retptr, ptr0, len0, ptr1, len1);
1203
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1204
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1205
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1206
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1207
+ if (r3) {
1208
+ throw takeObject(r2);
1209
+ }
1210
+ var v3 = getArrayU16FromWasm0(r0, r1).slice();
1211
+ wasm.__wbindgen_export(r0, r1 * 2, 2);
1212
+ return v3;
1213
+ } finally {
1214
+ wasm.__wbindgen_add_to_stack_pointer(16);
1215
+ }
1216
+ }
1217
+
1218
+ /**
1219
+ * Read all point coordinates as an interleaved `Float64Array`
1220
+ * `[x0,y0,z0, x1,y1,z1, ...]` (length `3 * point_count`).
1221
+ *
1222
+ * Guarded against 32-bit memory blowup; very large clouds return a clean error
1223
+ * (read the header with `lidar_info`, or downsample on your side).
1224
+ * @param {Uint8Array} data
1225
+ * @param {string} format
1226
+ * @returns {Float64Array}
1227
+ */
1228
+ export function lidar_read_xyz(data, format) {
1229
+ try {
1230
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1231
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export2);
1232
+ const len0 = WASM_VECTOR_LEN;
1233
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
1234
+ const len1 = WASM_VECTOR_LEN;
1235
+ wasm.lidar_read_xyz(retptr, ptr0, len0, ptr1, len1);
1236
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1237
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1238
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1239
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1240
+ if (r3) {
1241
+ throw takeObject(r2);
1242
+ }
1243
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
1244
+ wasm.__wbindgen_export(r0, r1 * 8, 8);
1245
+ return v3;
1246
+ } finally {
1247
+ wasm.__wbindgen_add_to_stack_pointer(16);
1248
+ }
1249
+ }
1250
+
1251
+ /**
1252
+ * Global Moran's I spatial autocorrelation for point data, using a binary
1253
+ * distance-band spatial weights matrix (neighbors within `distance_threshold`).
1254
+ *
1255
+ * `points_xy` is `[x0,y0,...]`, `values` is one value per point. Returns JSON:
1256
+ * `{"ok":true,"morans_i","expected","variance","z_score","p_value","n"}`.
1257
+ *
1258
+ * Builds neighbors in O(n^2); intended for up to a few thousand points.
1259
+ * @param {Float64Array} points_xy
1260
+ * @param {Float64Array} values
1261
+ * @param {number} distance_threshold
1262
+ * @returns {string}
1263
+ */
1264
+ export function morans_i(points_xy, values, distance_threshold) {
1265
+ let deferred4_0;
1266
+ let deferred4_1;
1267
+ try {
1268
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1269
+ const ptr0 = passArrayF64ToWasm0(points_xy, wasm.__wbindgen_export2);
1270
+ const len0 = WASM_VECTOR_LEN;
1271
+ const ptr1 = passArrayF64ToWasm0(values, wasm.__wbindgen_export2);
1272
+ const len1 = WASM_VECTOR_LEN;
1273
+ wasm.morans_i(retptr, ptr0, len0, ptr1, len1, distance_threshold);
1274
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1275
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1276
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1277
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1278
+ var ptr3 = r0;
1279
+ var len3 = r1;
1280
+ if (r3) {
1281
+ ptr3 = 0; len3 = 0;
1282
+ throw takeObject(r2);
1283
+ }
1284
+ deferred4_0 = ptr3;
1285
+ deferred4_1 = len3;
1286
+ return getStringFromWasm0(ptr3, len3);
1287
+ } finally {
1288
+ wasm.__wbindgen_add_to_stack_pointer(16);
1289
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
1290
+ }
1291
+ }
1292
+
1293
+ /**
1294
+ * Vector formats this build can read from memory (comma-separated).
1295
+ * @returns {string}
1296
+ */
1297
+ export function vector_formats() {
1298
+ let deferred1_0;
1299
+ let deferred1_1;
1300
+ try {
1301
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1302
+ wasm.vector_formats(retptr);
1303
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1304
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1305
+ deferred1_0 = r0;
1306
+ deferred1_1 = r1;
1307
+ return getStringFromWasm0(r0, r1);
1308
+ } finally {
1309
+ wasm.__wbindgen_add_to_stack_pointer(16);
1310
+ wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
1311
+ }
1312
+ }
1313
+
1314
+ /**
1315
+ * Read a vector dataset and return metadata as JSON:
1316
+ * `{"ok":true,"name","features","geometry","epsg"|null,"fields":[...],
1317
+ * "bbox":[min_x,min_y,max_x,max_y]|null}`.
1318
+ * @param {Uint8Array} data
1319
+ * @param {string} format
1320
+ * @returns {string}
1321
+ */
1322
+ export function vector_info(data, format) {
1323
+ let deferred4_0;
1324
+ let deferred4_1;
1325
+ try {
1326
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1327
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export2);
1328
+ const len0 = WASM_VECTOR_LEN;
1329
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
1330
+ const len1 = WASM_VECTOR_LEN;
1331
+ wasm.vector_info(retptr, ptr0, len0, ptr1, len1);
1332
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1333
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1334
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1335
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1336
+ var ptr3 = r0;
1337
+ var len3 = r1;
1338
+ if (r3) {
1339
+ ptr3 = 0; len3 = 0;
1340
+ throw takeObject(r2);
1341
+ }
1342
+ deferred4_0 = ptr3;
1343
+ deferred4_1 = len3;
1344
+ return getStringFromWasm0(ptr3, len3);
1345
+ } finally {
1346
+ wasm.__wbindgen_add_to_stack_pointer(16);
1347
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
1348
+ }
1349
+ }
1350
+
1351
+ /**
1352
+ * Read a vector dataset and return it as a GeoJSON `FeatureCollection` string.
1353
+ * @param {Uint8Array} data
1354
+ * @param {string} format
1355
+ * @returns {string}
1356
+ */
1357
+ export function vector_to_geojson(data, format) {
1358
+ let deferred4_0;
1359
+ let deferred4_1;
1360
+ try {
1361
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1362
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export2);
1363
+ const len0 = WASM_VECTOR_LEN;
1364
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
1365
+ const len1 = WASM_VECTOR_LEN;
1366
+ wasm.vector_to_geojson(retptr, ptr0, len0, ptr1, len1);
1367
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1368
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1369
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1370
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1371
+ var ptr3 = r0;
1372
+ var len3 = r1;
1373
+ if (r3) {
1374
+ ptr3 = 0; len3 = 0;
1375
+ throw takeObject(r2);
1376
+ }
1377
+ deferred4_0 = ptr3;
1378
+ deferred4_1 = len3;
1379
+ return getStringFromWasm0(ptr3, len3);
1380
+ } finally {
1381
+ wasm.__wbindgen_add_to_stack_pointer(16);
1382
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
1383
+ }
1384
+ }
1385
+
1386
+ /**
1387
+ * Read a vector dataset, reproject it to `dst_epsg`, and return GeoJSON.
1388
+ * Uses the bundled pure-Rust projection engine (full EPSG support).
1389
+ *
1390
+ * `src_epsg` overrides the source CRS: pass `0` to use the layer's own CRS, or
1391
+ * fall back to EPSG:4326 if it declares none (GeoJSON is WGS84 by RFC 7946).
1392
+ * @param {Uint8Array} data
1393
+ * @param {string} format
1394
+ * @param {number} dst_epsg
1395
+ * @param {number} src_epsg
1396
+ * @returns {string}
1397
+ */
1398
+ export function vector_to_geojson_reproject(data, format, dst_epsg, src_epsg) {
1399
+ let deferred4_0;
1400
+ let deferred4_1;
1401
+ try {
1402
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1403
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export2);
1404
+ const len0 = WASM_VECTOR_LEN;
1405
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
1406
+ const len1 = WASM_VECTOR_LEN;
1407
+ wasm.vector_to_geojson_reproject(retptr, ptr0, len0, ptr1, len1, dst_epsg, src_epsg);
1408
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1409
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1410
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1411
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1412
+ var ptr3 = r0;
1413
+ var len3 = r1;
1414
+ if (r3) {
1415
+ ptr3 = 0; len3 = 0;
1416
+ throw takeObject(r2);
1417
+ }
1418
+ deferred4_0 = ptr3;
1419
+ deferred4_1 = len3;
1420
+ return getStringFromWasm0(ptr3, len3);
1421
+ } finally {
1422
+ wasm.__wbindgen_add_to_stack_pointer(16);
1423
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
1424
+ }
1425
+ }
1426
+
1074
1427
  /**
1075
1428
  * Semantic version of this crate, exposed for runtime feature detection.
1076
1429
  * @returns {string}
Binary file