11import { Epsg , EpsgCode , TileMatrixSets } from '@basemaps/geo' ;
22import { GdalCommand } from './gdal.runner.js' ;
33import { CogifyCreationOptions } from './stac.js' ;
4-
5- export const CogifyDefaults = {
6- compression : 'webp' ,
7- blockSize : 512 ,
8- quality : 90 ,
9- warpResampling : 'bilinear' ,
10- overviewResampling : 'lanczos' ,
11- } as const ;
4+ import { Presets } from '../preset.js' ;
125
136export function gdalBuildVrt ( id : string , source : string [ ] ) : GdalCommand {
147 if ( source . length === 0 ) throw new Error ( 'No source files given for :' + id ) ;
@@ -33,7 +26,7 @@ export function gdalBuildVrtWarp(
3326 [ '-wo' , 'NUM_THREADS=ALL_CPUS' ] , // Multithread the warp
3427 [ '-s_srs' , Epsg . get ( sourceProjection ) . toEpsgString ( ) ] , // Source EPSG
3528 [ '-t_srs' , tileMatrix . projection . toEpsgString ( ) ] , // Target EPSG
36- [ '-r' , opt . warpResampling ?? CogifyDefaults . warpResampling ] ,
29+ opt . warpResampling ? [ '-r' , opt . warpResampling ] : undefined ,
3730 cutline . path ? [ '-cutline' , cutline . path , '-cblend' , cutline . blend ] : undefined ,
3831 sourceVrt ,
3932 id + '.' + tileMatrix . identifier + '.vrt' ,
@@ -45,7 +38,7 @@ export function gdalBuildVrtWarp(
4538}
4639
4740export function gdalBuildCog ( id : string , sourceVrt : string , opt : CogifyCreationOptions ) : GdalCommand {
48- const cfg = { ...CogifyDefaults , ...opt } ;
41+ const cfg = { ...Presets [ opt . preset ] , ...opt } ;
4942 const tileMatrix = TileMatrixSets . find ( cfg . tileMatrix ) ;
5043 if ( tileMatrix == null ) throw new Error ( 'Unable to find tileMatrix: ' + cfg . tileMatrix ) ;
5144
@@ -68,20 +61,22 @@ export function gdalBuildCog(id: string, sourceVrt: string, opt: CogifyCreationO
6861 [ '-of' , 'COG' ] ,
6962 [ '-co' , 'NUM_THREADS=ALL_CPUS' ] , // Use all CPUS
7063 [ '--config' , 'GDAL_NUM_THREADS' , 'all_cpus' ] , // Also required to NUM_THREADS till gdal 3.7.x
71- [ '-co' , 'BIGTIFF=YES ' ] , // Default to BIG_TIFF
64+ [ '-co' , 'BIGTIFF=IF_NEEDED ' ] , // BigTiff is somewhat slower and most (All?) of the COGS should be well below 4GB
7265 [ '-co' , 'ADD_ALPHA=YES' ] ,
7366 [ '-co' , 'BLOCKSIZE=512' ] ,
7467 [ '-co' , `WARP_RESAMPLING=${ cfg . warpResampling } ` ] ,
7568 [ '-co' , `OVERVIEW_RESAMPLING=${ cfg . overviewResampling } ` ] ,
7669 [ '-co' , `COMPRESS=${ cfg . compression } ` ] ,
77- [ '-co' , `QUALITY=${ cfg . quality } ` ] ,
70+ cfg . quality ? [ '-co' , `QUALITY=${ cfg . quality } ` ] : undefined ,
71+ cfg . maxZError ? [ '-co' , `MAX_Z_ERROR=${ cfg . maxZError } ` ] : undefined ,
7872 [ '-co' , 'SPARSE_OK=YES' ] ,
7973 [ '-co' , `TARGET_SRS=${ tileMatrix . projection . toEpsgString ( ) } ` ] ,
8074 [ '-co' , `EXTENT=${ tileExtent . join ( ',' ) } ,` ] ,
8175 [ '-tr' , targetResolution , targetResolution ] ,
8276 sourceVrt ,
8377 targetTiff ,
8478 ]
79+ . filter ( ( f ) => f != null )
8580 . flat ( )
8681 . map ( String ) ,
8782 } ;
0 commit comments