gdal
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());
});
Table of Contents
- Properties
- Attributes
-
Static Methods
- gdal.checksumImage(srcxywh)
- gdal.config.get(key)
- gdal.config.set(keyvalue)
- gdal.contourGenerate(options)
- gdal.decToDMS(angleaxisprecision)
- gdal.fillNodata(options)
- gdal.open(pathmodedriversx_sizey_sizeband_countdata_typecreation_options)
- gdal.openAsync(pathmodedriversx_sizey_sizeband_countdata_typecreation_optionscallback)
- gdal.polygonize(options)
- gdal.quiet()
- gdal.reprojectImage(options[options.options] Warp options (see: [reference])
- gdal.setPROJSearchPaths(Path)
- gdal.sieveFilter(options)
- gdal.suggestedWarpOutput(options)
- gdal.verbose()
Properties
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)
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
Gets a GDAL configuration setting.
Parameters:
-
key
String
Returns:
Example:
data_path = gdal.config.get('GDAL_DATA');`
gdal.config.set
-
key
-
value
Sets a GDAL configuration setting.
Parameters:
-
key
String -
value
String
Returns:
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 optionalThe "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 optionalThe elevation interval between contours generated.
-
[fixedLevels]
Number[] optionalA list of fixed contour levels at which contours should be generated. Overrides interval/base options if set.
-
[nodata]
Number optionalThe 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 optionalA field index to indicate where a unique id should be written for each feature (contour) written.
-
[elevField]
Integer optionalA field index to indicate where the elevation value of the contour should be written.
-
gdal.decToDMS
-
angle
-
axis
-
precision=2
Convert decimal degrees to degrees, minutes, and seconds string
Parameters:
-
angle
Number -
axis
String"lat"
or"long"
-
[precision=2]
Integer optional
Returns:
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.RasterBandThis band to be updated in-place.
-
[mask]
gdal.RasterBand optionalMask band
-
searchDist
NumberThe maximum distance (in pixels) that the algorithm will search out for values to interpolate.
-
[smoothingIterations=0]
Integer optionalThe 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
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 | BufferPath to dataset or in-memory Buffer to open
-
[mode="r"]
String optionalThe mode to use to open the file:
"r"
,"r+"
, or"w"
-
[drivers]
String | Array optionalDriver name, or list of driver names to attempt to use.
-
[x_size]
Integer optionalUsed when creating a raster dataset with the
"w"
mode. -
[y_size]
Integer optionalUsed when creating a raster dataset with the
"w"
mode. -
[band_count]
Integer optionalUsed when creating a raster dataset with the
"w"
mode. -
[data_type]
Integer optionalUsed when creating a raster dataset with the
"w"
mode. -
[creation_options]
String[] | Object optionalUsed 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
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 | BufferPath to dataset or in-memory Buffer to open
-
[mode="r"]
String optionalThe mode to use to open the file:
"r"
,"r+"
, or"w"
-
[drivers]
String | Array optionalDriver name, or list of driver names to attempt to use.
-
[x_size]
Integer optionalUsed when creating a raster dataset with the
"w"
mode. -
[y_size]
Integer optionalUsed when creating a raster dataset with the
"w"
mode. -
[band_count]
Integer optionalUsed when creating a raster dataset with the
"w"
mode. -
[data_type]
Integer optionalUsed when creating a raster dataset with the
"w"
mode. -
[creation_options]
String[] | Object optionalUsed when creating a dataset with the
"w"
mode. -
[callback]
RequestCallback optionalPromisifiable 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
IntegerThe attribute field index indicating the feature attribute into which the pixel value of the polygon should be written.
-
[connectedness=4]
Integer optionalEither 4 indicating that diagonal pixels are not considered directly adjacent for polygon membership purposes or 8 indicating they are.
-
[useFloats=false]
Boolean optionalUse 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:
-
options
Object-
src
gdal.Dataset -
dst
gdal.Dataset -
s_srs
gdal.SpatialReference -
t_srs
gdal.SpatialReference -
[resampling]
String optionalResampling algorithm (available options)
-
[cutline]
gdal.Geometry optionalMust be in src dataset pixel coordinates. Use CoordinateTransformation to convert between georeferenced coordinates and pixel coordinates
-
[srcBands]
Integer[] optional -
[dstBands]
Integer[] optional -
[srcAlphaBand]
Integer optional -
[dstAlphaBand]
Integer optional -
[srcNodata]
Number optional -
[dstNodata]
Number optional -
[memoryLimit]
Integer optional -
[maxError]
Number optional -
[multi]
Boolean optional
-
-
[options.options] Warp options (see: [reference]
String[] | Object
gdal.setPROJSearchPaths
-
Path
Set paths where proj will search it data.
Parameters:
-
Path
Stringc:\ProjData
gdal.sieveFilter
-
options
Removes small raster polygons.
Parameters:
-
options
Object-
src
gdal.RasterBand -
dst
gdal.RasterBandOutput raster band. It may be the same as src band to update the source in place.
-
[mask]
gdal.RasterBand optionalAll pixels in the mask band with a value other than zero will be considered suitable for inclusion in polygons.
-
threshold
NumberRaster polygons with sizes smaller than this will be merged into their largest neighbour.
-
[connectedness=4]
Integer optionalEither 4 indicating that diagonal pixels are not considered directly adjacent for polygon membership purposes or 8 indicating they are.
-
gdal.suggestedWarpOutput
-
options
Used to determine the bounds and resolution of the output virtual file which should be large enough to include all the input image.
Parameters:
-
options
ObjectWarp options
-
src
gdal.Dataset -
s_srs
gdal.SpatialReference -
t_srs
gdal.SpatialReference -
[maxError=0]
Number optional
-
Returns:
An object containing "rasterSize"
and "geoTransform"
properties.
gdal.verbose
()
Displays extra debugging information from GDAL.