Show:

This node-gdal binding for Node.js provides a feature-complete way of reading, writing, and manipulating geospatial data (raster and vector) using GDAL.

// sample: open a shapefile and display all features as geojson
var dataset = gdal.open("states.shp");

dataset.layers.get(0).features.forEach(function(feature) {
    console.log(feature.getGeometry().toJSON());
});

Properties

gdal.drivers

gdal.GDALDrivers const

The collection of all drivers registered with GDAL

gdal.lastError

Object const

Details about the last error that occurred. The property will be null or an object containing three properties: "number", "message", and "type".

gdal.version

String const

GDAL version (not the binding version)

Attributes

lastError

Object

Static Methods

gdal.checksumImage
(
  • src
  • x=0
  • y=0
  • w=src.width
  • h=src.height
)

Compute checksum for image region.

Parameters:

  • src gdal.RasterBand
  • [x=0] Integer optional
  • [y=0] Integer optional
  • [w=src.width] Integer optional
  • [h=src.height] Integer optional

Returns:

integer

gdal.config.get
(
  • key
)
String

Defined in lib/gdal.js:37

Gets a GDAL configuration setting.

Parameters:

  • key String

Returns:

String

Example:

data_path = gdal.config.get('GDAL_DATA');`
gdal.config.set
(
  • key
  • value
)
Mixed

Defined in lib/gdal.js:52

Sets a GDAL configuration setting.

Parameters:

  • key String
  • value String

Returns:

Mixed

Example:

gdal.config.set('GDAL_DATA', data_path);`
gdal.contourGenerate
(
  • options
)

Create vector contours from raster DEM.

This algorithm will generate contour vectors for the input raster band on the requested set of contour levels. The vector contours are written to the passed in vector layer. Also, a NODATA value may be specified to identify pixels that should not be considered in contour line generation.

Parameters:

  • options Object
    • src gdal.RasterBand
    • dst gdal.Layer
    • [offset=0] Number optional

      The "offset" relative to which contour intervals are applied. This is normally zero, but could be different. To generate 10m contours at 5, 15, 25, ... the offset would be 5.

    • [interval=100] Number optional

      The elevation interval between contours generated.

    • [fixedLevels] Number[] optional

      A list of fixed contour levels at which contours should be generated. Overrides interval/base options if set.

    • [nodata] Number optional

      The value to use as a "nodata" value. That is, a pixel value which should be ignored in generating contours as if the value of the pixel were not known.

    • [idField] Integer optional

      A field index to indicate where a unique id should be written for each feature (contour) written.

    • [elevField] Integer optional

      A field index to indicate where the elevation value of the contour should be written.

gdal.decToDMS
(
  • angle
  • axis
  • precision=2
)
String

Defined in src/gdal.hpp:137

Convert decimal degrees to degrees, minutes, and seconds string

Parameters:

  • angle Number
  • axis String

    "lat" or "long"

  • [precision=2] Integer optional

Returns:

String:

A string nndnn'nn.nn'"L where n is a number and L is either N or E

gdal.fillNodata
(
  • options
)

Fill raster regions by interpolation from edges.

Parameters:

  • options Object
    • src gdal.RasterBand

      This band to be updated in-place.

    • [mask] gdal.RasterBand optional

      Mask band

    • searchDist Number

      The maximum distance (in pixels) that the algorithm will search out for values to interpolate.

    • [smoothingIterations=0] Integer optional

      The number of 3x3 average filter smoothing iterations to run after the interpolation to dampen artifacts.

gdal.open
(
  • path
  • mode="r"
  • drivers
  • x_size
  • y_size
  • band_count
  • data_type
  • creation_options
)
gdal.Dataset

Defined in lib/gdal.js:507

Creates or opens a dataset. Dataset should be explicitly closed with dataset.close() method if opened in "w" mode to flush any changes. Otherwise, datasets are closed when (and if) node decides to garbage collect them.

Parameters:

  • path String | Buffer

    Path to dataset or in-memory Buffer to open

  • [mode="r"] String optional

    The mode to use to open the file: "r", "r+", or "w"

  • [drivers] String | Array optional

    Driver name, or list of driver names to attempt to use.

  • [x_size] Integer optional

    Used when creating a raster dataset with the "w" mode.

  • [y_size] Integer optional

    Used when creating a raster dataset with the "w" mode.

  • [band_count] Integer optional

    Used when creating a raster dataset with the "w" mode.

  • [data_type] Integer optional

    Used when creating a raster dataset with the "w" mode.

  • [creation_options] String[] | Object optional

    Used when creating a dataset with the "w" mode.

Returns:

Example:

var dataset = gdal.open('./data.shp');`
var dataset = gdal.open(fs.readFileSync('./data.shp'));`
gdal.openAsync
(
  • path
  • mode="r"
  • drivers
  • x_size
  • y_size
  • band_count
  • data_type
  • creation_options
  • callback
)
gdal.Dataset

Defined in lib/gdal.js:675

Asynchronously creates or opens a dataset. Dataset should be explicitly closed with dataset.close() method if opened in "w" mode to flush any changes. Otherwise, datasets are closed when (and if) node decides to garbage collect them. If the last parameter is a callback, then this callback is called on completion and undefined is returned. Otherwise the function returns a Promise resolved with the result.

Parameters:

  • path String | Buffer

    Path to dataset or in-memory Buffer to open

  • [mode="r"] String optional

    The mode to use to open the file: "r", "r+", or "w"

  • [drivers] String | Array optional

    Driver name, or list of driver names to attempt to use.

  • [x_size] Integer optional

    Used when creating a raster dataset with the "w" mode.

  • [y_size] Integer optional

    Used when creating a raster dataset with the "w" mode.

  • [band_count] Integer optional

    Used when creating a raster dataset with the "w" mode.

  • [data_type] Integer optional

    Used when creating a raster dataset with the "w" mode.

  • [creation_options] String[] | Object optional

    Used when creating a dataset with the "w" mode.

  • [callback] RequestCallback optional

    Promisifiable callback, always the last parameter, can be specified even if certain optional parameters are omitted

Returns:

Example:

var dataset = await gdal.openAsync('./data.shp');`
var dataset = await gdal.openAsync(await fd.readFile('./data.shp'));`
gdal.openAsync('./data.shp', (err, ds) => {...});`
gdal.polygonize
(
  • options
)

Creates vector polygons for all connected regions of pixels in the raster sharing a common pixel value. Each polygon is created with an attribute indicating the pixel value of that polygon. A raster mask may also be provided to determine which pixels are eligible for processing.

Parameters:

  • options Object
    • src gdal.RasterBand
    • dst gdal.Layer
    • [mask] gdal.RasterBand optional
    • pixValField Integer

      The attribute field index indicating the feature attribute into which the pixel value of the polygon should be written.

    • [connectedness=4] Integer optional

      Either 4 indicating that diagonal pixels are not considered directly adjacent for polygon membership purposes or 8 indicating they are.

    • [useFloats=false] Boolean optional

      Use floating point buffers instead of int buffers.

gdal.quiet ()

Disables all output.

gdal.reprojectImage
(
  • options
  • [options.options] Warp options (see: [reference]
)

Reprojects a dataset.

Parameters:

gdal.setPROJSearchPaths
(
  • Path
)

Set paths where proj will search it data.

Parameters:

  • Path String

    c:\ProjData

gdal.sieveFilter
(
  • options
)

Removes small raster polygons.

Parameters:

  • options Object
    • src gdal.RasterBand
    • dst gdal.RasterBand

      Output raster band. It may be the same as src band to update the source in place.

    • [mask] gdal.RasterBand optional

      All pixels in the mask band with a value other than zero will be considered suitable for inclusion in polygons.

    • threshold Number

      Raster polygons with sizes smaller than this will be merged into their largest neighbour.

    • [connectedness=4] Integer optional

      Either 4 indicating that diagonal pixels are not considered directly adjacent for polygon membership purposes or 8 indicating they are.

gdal.suggestedWarpOutput
(
  • options
)
Object

Used to determine the bounds and resolution of the output virtual file which should be large enough to include all the input image.

Parameters:

Returns:

Object:

An object containing "rasterSize" and "geoTransform" properties.

gdal.verbose ()

Displays extra debugging information from GDAL.