javascript使用gdal
时间: 2024-01-07 16:22:23 浏览: 159
根据提供的引用内容,以下是使用JavaScript中的gdal的示例:
```javascript
// 引入gdal模块
const gdal = require('gdal');
// 打开数据集
const dataset = gdal.open('input.tif');
// 获取数据集的宽度和高度
const width = dataset.rasterSize.x;
const height = dataset.rasterSize.y;
// 创建输出数据集
const outputDataset = gdal.open('output.tif', 'w', 'GTiff', width, height, 3, 'Byte');
// 读取原始数据集的波段
const band1 = dataset.bands.get(1);const band2 = dataset.bands.get(2);
const band3 = dataset.bands.get(3);
// 将原始数据集的波段写入输出数据集的波段
const outputBand1 = outputDataset.bands.get(1);
const outputBand2 = outputDataset.bands.get(2);
const outputBand3 = outputDataset.bands.get(3);
// 遍历每个像素,并将原始数据集的像素值写入输出数据集的像素值
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const value1 = band1.pixels.get(x, y);
const value2 = band2.pixels.get(x, y);
const value3 = band3.pixels.get(x, y);
outputBand1.pixels.set(x, y, value1);
outputBand2.pixels.set(x, y, value2);
outputBand3.pixels.set(x, y, value3);
}
}
// 保存输出数据集
outputDataset.close();
```
阅读全文
相关推荐


















