Haoliang Yu Haoliang Yu - 3 months ago 34
Javascript Question

How to save spatial reference to GeoTIFF created by node-gdal?

I am trying to create a GeoTIFF using node-gdal and set the spatial reference to it. The spatial reference is from an existing file and write the code like this

// 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();


However, when I load the saved file with QGIS, it suggests the GeoTIFF doesn't have any projection information.

The full code can be found HERE.

Answer

This is obviously a typo :-(

this.spatialReference = dataset.spatialReference;

should be

this.src = dataset.src;