如何将空间参考保存到由 node-gdal 创建的 GeoTIFF?
How to save spatial reference to GeoTIFF created by node-gdal?
我正在尝试使用 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。
这显然是一个错字:-(
this.spatialReference = dataset.spatialReference;
应该是
this.src = dataset.src;
我正在尝试使用 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。
这显然是一个错字:-(
this.spatialReference = dataset.spatialReference;
应该是
this.src = dataset.src;