REFERENCE · API

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?)

boot
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

HELPERPURPOSE
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)

GROUPMETHODS
Open & identifyopen(path) · open(path, eAccess) · openEx(path[, flags[, allowedDrivers, openOptions, siblingFiles]]) · openShared · identifyDriver · identifyDriverEx
Programswarp(dest, dstDS, srcDSs, opts) · buildVRT(dest, srcDSs, srcNames, opts) · multiDimTranslate(dest, dstDS, srcDSs, opts), the rest live on Dataset
DriversgetDrivers() · getDriverCount() · getDriver(i) · getDriverByName(name) · allRegister() · registerPlugins() · registerPlugin(name)
ConfigsetConfigOption · getConfigOption · setThreadLocalConfigOption · getThreadLocalConfigOption · getGlobalConfigOption · getConfigOptions · setPathSpecificOption · getPathSpecificOption · clearPathSpecificOptions
ErrorsgetLastErrorMsg · getLastErrorNo · getLastErrorType · errorReset · getErrorCounter · vsiGetLastErrorMsg · vsiGetLastErrorNo · vsiErrorReset · error(class, no, msg) · popErrorHandler · setCurrentErrorHandlerCatchDebug
Virtual FSreadDir · readDirRecursive · mkdir · mkdirRecursive · rmdir · rmdirRecursive · unlink · unlinkBatch · rename · copyFile · fileFromMemBuffer · getFileSystemsPrefixes · getFileSystemOptions · getActualURL · getSignedURL
Geo mathapplyGeoTransform · invGeoTransform · gcpsToGeoTransform(gcps, geoTransform, approxOK) · decToDMS · packedDMSToDec · decToPackedDMS
Cache & typessetCacheMax · getCacheMax · getCacheUsed · getDataTypeName · getDataTypeByName · getDataTypeSize · dataTypeIsComplex · dataTypeUnion · getColorInterpretationName · getPaletteInterpretationName
MiscversionInfo(req) · getNumCPUs · getUsablePhysicalRAM · parseCommandLine · setProjDataPath · getSubdatasetInfo(path) · findFile · pushFinderLocation · popFinderLocation · finderClean · escapeString · binaryToHex · hexToBinary · destroyDriverManager

Dataset

GROUPMETHODS
Programstranslate(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)
Infoinfo(opts) · vectorInfo(opts) · multiDimInfo(opts): pass ["-json"] and parse
RastergetRasterXSize · getRasterYSize · getRasterCount · buildOverviews(resampling, levels, opts) · addBand(type, opts) · createMaskBand(flags) · clearStatistics · flushCache
GeoreferencinggetGeoTransform · setGeoTransform · getProjectionRef · setProjection · getGCPs · setGCPs(gcps, projection) · getGCPCount · getGCPProjection
Vector / layersgetLayerCount · deleteLayer(i) · isLayerPrivate(i) · resetReading · testCapability(cap) · startTransaction(force) · commitTransaction · rollbackTransaction · abortSQL · getFieldDomainNames(opts) · deleteFieldDomain(name) · getRelationshipNames(opts) · deleteRelationship(name)
Lifecycleclose() · 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

at runtime
await Gdal.versionInfo("RELEASE_NAME");   // "3.13.1"
await Gdal.getDriverCount();              // 100+, CI-asserted