我正在尝试使用node-gdal创建GeoTIFF并设置空间参考。空间参考来自现有文件,并像这样编写代码
// read an existing file and get its spatial reference
let dataset = gdal.open(filePath);
this.bandData = dataset.bands.get(1);
this.rasterSize = dataset.rasterSize;
this.geoTransform = dataset.geoTransform;
this.spatialReference = dataset.spatialReference;
// save the same spatial reference to a new file
let driver = gdal.drivers.get('GTiff');
let dataset = driver.create(filePath, this.rasterSize.x, this.rasterSize.y, 1, gdal.GDT_Byte);
let bandData = dataset.bands.get(1);
bandData.pixels.write(0, 0, this.rasterSize.x, this.rasterSize.y, data);
dataset.spatialReference = this.spatialReference;
dataset.geoTransform = this.geoTransform;
dataset.flush();
但是,当我使用QGIS加载保存的文件时,它表明GeoTIFF没有任何投影信息。
可以找到完整的代码HERE。
答案 0 :(得分:0)
这显然是一个错字: - (
this.spatialReference = dataset.spatialReference;
应该是
this.src = dataset.src;