JavaScript
terrio, pure-Rust geospatial data I/O, compiled to WebAssembly for browsers and Node.js. Datasets are opened from bytes, with a file name telling the format, and written back to bytes.
import init, { open, fromGeoJSON, rasterFromArray, transformPoints, describeCrs } from "terrio";
await init(); // in Node.js: await init({ module_or_path: fs.readFileSync(wasmPath) })
const bytes = new Uint8Array(await (await fetch("dem.tif")).arrayBuffer());
const dem = open(bytes, "dem.tif");
dem.info(); // the summary `terrio info --json` prints
dem.width, dem.height, dem.count, dem.dtype, dem.crs, dem.transform, dem.nodata
const band = dem.readBand(1); // Float32Array, Uint8Array... row after row
const tile = dem.readBand(1, [0, 0, 256, 256]); // a window [col_off, row_off, width, height]
const cog = dem.toBytes("dem_cog.tif", { format: "COG", compress: "DEFLATE" });
const roads = open(geojsonBytes, "roads.geojson");
roads.toGeoJSON(); // a FeatureCollection object
const fgb = roads.toBytes("roads.fgb", { tSrs: "EPSG:3857", where: "lanes > 2" });
const [xs, ys] = transformPoints([-122.4], [37.8], "EPSG:4326", "EPSG:32610");
In WebAssembly, these formats are read from and written to memory:
| Read | Write | |
|---|---|---|
| Raster | GeoTIFF/COG, Esri ASCII grid | GeoTIFF, COG (lossless compressions), Esri ASCII grid |
| Vector | GeoJSON, TopoJSON, FlatGeobuf*, KML, KMZ, GML, GPX, zip archives of these | GeoJSON, TopoJSON, FlatGeobuf, KML, KMZ, GML, GPX |
* The format library's FlatGeobuf reader overflows on large files in 32-bit WebAssembly; terrio's own FlatGeobuf driver will replace it.
Shapefiles, GeoParquet and GeoPackage are not yet read from memory in WebAssembly.
Building
wasm-pack build js --release --target web --out-dir pkg --out-name terrio
wasm-pack build js --release --target nodejs --out-dir pkg-node --out-name terrio
node --test js/tests/node.test.mjs # TERRIO_TEST_DATA=... adds real files checked against GDAL