【问题标题】:Error while writing pixel values in a raster file using node gdal使用节点 gdal 在光栅文件中写入像素值时出错
【发布时间】:2017-05-22 06:01:37
【问题描述】:

使用以下代码光栅化文件:

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)

请帮忙。

【问题讨论】:

    标签: gis raster gdal


    【解决方案1】:

    代替

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

    使用

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

    允许写入raster.bip

    【讨论】:

    • 使用gdal.GA_Update 产生TypeError: mode must be an string 的错误。因此我改用gdal.open("raster.bip", "w")。这产生了另一个错误Driver must be specified。请建议指定哪个驱动程序。 Source
    • 请您提供您的完整代码(或至少在您摘录之前的部分)? - 您的链接适用于 C/C++ API,而不适用于 Python 模块(包装它)。
    • 我正在使用node-gdal。我上面提供的链接也适用于 node-gdal 包装器。代码中没有其他内容与我们这里的问题相关。
    猜你喜欢
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    • 2018-07-09
    • 1970-01-01
    相关资源
    最近更新 更多