mmomtchev / node-gdal-async

Node.js bindings for GDAL (Geospatial Data Abstraction Library) with full async support
https://mmomtchev.github.io/node-gdal-async/
Apache License 2.0
129 stars 26 forks source link

Support for COG #75

Closed bojanbizjak closed 11 months ago

bojanbizjak commented 1 year ago

I wonder if it is possible or planned to have built-in support for GeoTIFF to COG conversion?

Reference: COG – Cloud Optimized GeoTIFF generator - https://gdal.org/drivers/raster/cog.html

mmomtchev commented 1 year ago

It is certainly possible, but it would require adding libgeotiff as a dependency on all OSes

ivansalacceo commented 1 year ago

You can use this to convert to COG manually

const filePath = '/tmp/nonCog.tiff',
const resultFilePath = '/tmp/cog.tiff'
const temporaryFilePath = '/tmp/temporary.tiff'

const dataset = await gdal.openAsync(filePath);
const tiled = await gdal.translateAsync(temporaryFilePath, dataset, ['-co', 'TILED=YES', '-co', 'COMPRESS=DEFLATE']);
await tiled.buildOverviewsAsync('NEAREST', [2, 4, 8, 16, 32]);
await gdal.translateAsync(resultFilePath, tiled, ['-co', 'TILED=YES', '-co', 'COMPRESS=DEFLATE', '-co', 'COPY_SRC_OVERVIEWS=YES']);
mmomtchev commented 1 year ago

It seems that in recent GDAL versions, the internal libtiff supports COG out of the box, everything that is needed is to add proper files for unit testing to render it official

mmomtchev commented 11 months ago

I confirm, converting files to COG is supported out of the box:

In Node.js:

const cog = gdal.drivers.get('COG');
cog.createCopy('sample-cog.tif', gdal.open('sample.tif'));

Then on the command-line:

python ./node_modules/gdal-async/deps/libgdal/gdal/swig/python/gdal-utils/osgeo_utils/samples/validate_cloud_optimized_geotiff.py sample-cog.tif

   sample-cog.tif is a valid cloud optimized GeoTIFF

   The size of all IFD headers is 1096 bytes

I remind you that the COG driver can be used only for writing. COGs are valid GeoTIFFs and can and must be read with the GeoTIFF driver.