使用节点gdal在光栅文件中写入像素值时出错

时间:2017-05-22 06:01:37

标签: gis raster gdal

将以下代码用于光栅文件:

const gdal = require('gdal');
const dataset = gdal.open('raster.bip');
const band = dataset.bands.get(1);

band.pixels.write(0, 0, 1, 1, new Float32Array([-1111]));

但是得到以下错误:

/Users/alok/Smart Market/Code/OpenNetwork/node_modules/gdal/lib/gdal.js:681
                return write.apply(this, [x, y, width, height, data, options.buffer_width, options.buffer_height, options.pixel_space, options.line_space]);
                             ^

Error: Failed to write 4 bytes to file. 0 bytes written
    at RasterBandPixels.write (/Users/alok/Smart Market/Code/OpenNetwork/node_modules/gdal/lib/gdal.js:681:16)
    at Object.<anonymous> (/Users/alok/Smart Market/Code/OpenNetwork/coverage/WriteTest.js:99:15)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:422:7)
    at startup (bootstrap_node.js:143:9)

请帮忙。

1 个答案:

答案 0 :(得分:0)

而不是

const dataset = gdal.open('raster.bip');

使用

const dataset = gdal.open('raster.bip', gdal.GA_Update);

允许写入raster.bip