API reference
The v3 surface, straight from the bound C++ headers. Method names are camelCase; on the web with useWorker every call returns a promise.
initCppJs(options?)
import "gdal3.js/Dataset.h";
import "gdal3.js/Driver.h";
import "gdal3.js/GCP.h";
import "gdal3.js/SubdatasetInfo.h";
import { initCppJs, Gdal } from "gdal3.js/Gdal.h";
const Module = await initCppJs({ useWorker: true, fs: { opfs: true } });
Options: useWorker (browser; run in a Web Worker, objects become async proxies) and fs.opfs (browser; mount OPFS at /opfs). See configuration.
Module helpers
| HELPER | PURPOSE |
|---|---|
Module.toVector("VectorString", arr) | JS array → C++ vector<string> (program options) |
Module.toArray(v) | C++ vector → JS array (e.g. driver lists) |
Module.getFileList(dir) | Files in a VFS directory, with sizes |
Module.getDefaultPath() | The default writable root (e.g. /opfs) |
Module.FS.mkdirTree(dir) | Create a directory tree |
Gdal: static methods (grouped)
| GROUP | METHODS |
|---|---|
| Open & identify | open(path) · open(path, eAccess) · openEx(path[, flags[, allowedDrivers, openOptions, siblingFiles]]) · openShared · identifyDriver · identifyDriverEx |
| Programs | warp(dest, dstDS, srcDSs, opts) · buildVRT(dest, srcDSs, srcNames, opts) · multiDimTranslate(dest, dstDS, srcDSs, opts), the rest live on Dataset |
| Drivers | getDrivers() · getDriverCount() · getDriver(i) · getDriverByName(name) · allRegister() · registerPlugins() · registerPlugin(name) |
| Config | setConfigOption · getConfigOption · setThreadLocalConfigOption · getThreadLocalConfigOption · getGlobalConfigOption · getConfigOptions · setPathSpecificOption · getPathSpecificOption · clearPathSpecificOptions |
| Errors | getLastErrorMsg · getLastErrorNo · getLastErrorType · errorReset · getErrorCounter · vsiGetLastErrorMsg · vsiGetLastErrorNo · vsiErrorReset · error(class, no, msg) · popErrorHandler · setCurrentErrorHandlerCatchDebug |
| Virtual FS | readDir · readDirRecursive · mkdir · mkdirRecursive · rmdir · rmdirRecursive · unlink · unlinkBatch · rename · copyFile · fileFromMemBuffer · getFileSystemsPrefixes · getFileSystemOptions · getActualURL · getSignedURL |
| Geo math | applyGeoTransform · invGeoTransform · gcpsToGeoTransform(gcps, geoTransform, approxOK) · decToDMS · packedDMSToDec · decToPackedDMS |
| Cache & types | setCacheMax · getCacheMax · getCacheUsed · getDataTypeName · getDataTypeByName · getDataTypeSize · dataTypeIsComplex · dataTypeUnion · getColorInterpretationName · getPaletteInterpretationName |
| Misc | versionInfo(req) · getNumCPUs · getUsablePhysicalRAM · parseCommandLine · setProjDataPath · getSubdatasetInfo(path) · findFile · pushFinderLocation · popFinderLocation · finderClean · escapeString · binaryToHex · hexToBinary · destroyDriverManager |
Dataset
| GROUP | METHODS |
|---|---|
| Programs | translate(dest, opts) · vectorTranslate(dest, opts) · vectorTranslate2(dstDS, opts) · rasterize(dest|dstDS, opts) · demProcessing(dest, processing, colorFile, opts) · nearblack(dest, dstDS, opts) · grid(dest, opts) · footprint(dest, dstDS, opts) |
| Info | info(opts) · vectorInfo(opts) · multiDimInfo(opts): pass ["-json"] and parse |
| Raster | getRasterXSize · getRasterYSize · getRasterCount · buildOverviews(resampling, levels, opts) · addBand(type, opts) · createMaskBand(flags) · clearStatistics · flushCache |
| Georeferencing | getGeoTransform · setGeoTransform · getProjectionRef · setProjection · getGCPs · setGCPs(gcps, projection) · getGCPCount · getGCPProjection |
| Vector / layers | getLayerCount · deleteLayer(i) · isLayerPrivate(i) · resetReading · testCapability(cap) · startTransaction(force) · commitTransaction · rollbackTransaction · abortSQL · getFieldDomainNames(opts) · deleteFieldDomain(name) · getRelationshipNames(opts) · deleteRelationship(name) |
| Lifecycle | close() · getDriver() · getFileList() |
Driver
getShortName · getLongName · isReadable · isWritable · isRaster · isVector · getExtension · getExtensions · getOpenOptions · getCreationOptions · getLayerCreationOptions · getHelpTopic · getMetadataItem(name) · create(path, xsize, ysize, …) · createCopy(path, …) · createMultiDimensional(path, …) · deleteDriver(path) · rename(new, old) · copyFiles(new, old) · registerDriver · deregisterDriver
GCP & SubdatasetInfo
GCP: new GCP(x, y, z, pixel, line, info, id) with getters/setters for each field: pair with Gdal.gcpsToGeoTransform and ds.setGCPs.
SubdatasetInfo: Gdal.getSubdatasetInfo(path) → getPathComponent · getSubdatasetComponent · modifyPathComponent(newPath), for container formats holding multiple datasets.
TypeScript
Honest status: the generated .h-module bridges don't ship .d.ts files yet, so TS projects import them with // @ts-ignore and type their own wrappers, exactly what the bundled converter apps do (their types.ts files are a good starting point). Generated typings are on the roadmap.
Configuration options
Program options are plain GDAL CLI flags passed as a string vector: the upstream GDAL programs documentation is the reference. Runtime behaviour switches are covered in configuration.
GDAL version & drivers
await Gdal.versionInfo("RELEASE_NAME"); // "3.13.1"
await Gdal.getDriverCount(); // 100+, CI-asserted