@@ -123,7 +123,7 @@ const _writeIFD = (bin, data, _offset, ifd) => {
123
123
124
124
let val = ifd [ key ] ;
125
125
126
- if ( typeof val === ' undefined' ) {
126
+ if ( val === undefined ) {
127
127
throw new Error ( `failed to get value for key ${ key } ` ) ;
128
128
}
129
129
@@ -290,16 +290,7 @@ const toArray = (input) => {
290
290
const metadataDefaults = [
291
291
[ 'Compression' , 1 ] , // no compression
292
292
[ 'PlanarConfiguration' , 1 ] ,
293
- [ 'XPosition' , 0 ] ,
294
- [ 'YPosition' , 0 ] ,
295
- [ 'ResolutionUnit' , 1 ] , // Code 1 for actual pixel count or 2 for pixels per inch.
296
- [ 'ExtraSamples' , 0 ] , // should this be an array??
297
- [ 'GeoAsciiParams' , 'WGS 84\u0000' ] ,
298
- [ 'ModelTiepoint' , [ 0 , 0 , 0 , - 180 , 90 , 0 ] ] , // raster fits whole globe
299
- [ 'GTModelTypeGeoKey' , 2 ] ,
300
- [ 'GTRasterTypeGeoKey' , 1 ] ,
301
- [ 'GeographicTypeGeoKey' , 4326 ] ,
302
- [ 'GeogCitationGeoKey' , 'WGS 84' ] ,
293
+ [ 'ExtraSamples' , 0 ] ,
303
294
] ;
304
295
305
296
export function writeGeotiff ( data , metadata ) {
@@ -373,10 +364,32 @@ export function writeGeotiff(data, metadata) {
373
364
metadata . SampleFormat = times ( numBands , ( ) => 1 ) ;
374
365
}
375
366
367
+ // if didn't pass in projection information, assume the popular 4326 "geographic projection"
368
+ if ( ! metadata . hasOwnProperty ( 'GeographicTypeGeoKey' ) && ! metadata . hasOwnProperty ( 'ProjectedCSTypeGeoKey' ) ) {
369
+ metadata . GeographicTypeGeoKey = 4326 ;
370
+ metadata . ModelTiepoint = [ 0 , 0 , 0 , - 180 , 90 , 0 ] ; // raster fits whole globe
371
+ metadata . GeogCitationGeoKey = 'WGS 84' ;
372
+ metadata . GTModelTypeGeoKey = 2 ;
373
+ }
374
+
376
375
const geoKeys = Object . keys ( metadata )
377
376
. filter ( ( key ) => endsWith ( key , 'GeoKey' ) )
378
377
. sort ( ( a , b ) => name2code [ a ] - name2code [ b ] ) ;
379
378
379
+ if ( ! metadata . GeoAsciiParams ) {
380
+ let geoAsciiParams = '' ;
381
+ geoKeys . forEach ( ( name ) => {
382
+ const code = Number ( name2code [ name ] ) ;
383
+ const tagType = fieldTagTypes [ code ] ;
384
+ if ( tagType === 'ASCII' ) {
385
+ geoAsciiParams += `${ metadata [ name ] . toString ( ) } \u0000` ;
386
+ }
387
+ } ) ;
388
+ if ( geoAsciiParams . length > 0 ) {
389
+ metadata . GeoAsciiParams = geoAsciiParams ;
390
+ }
391
+ }
392
+
380
393
if ( ! metadata . GeoKeyDirectory ) {
381
394
const NumberOfKeys = geoKeys . length ;
382
395
@@ -421,7 +434,9 @@ export function writeGeotiff(data, metadata) {
421
434
'GTRasterTypeGeoKey' ,
422
435
'ImageLength' , // synonym of ImageHeight
423
436
'ImageWidth' ,
437
+ 'Orientation' ,
424
438
'PhotometricInterpretation' ,
439
+ 'ProjectedCSTypeGeoKey' ,
425
440
'PlanarConfiguration' ,
426
441
'ResolutionUnit' ,
427
442
'SamplesPerPixel' ,
0 commit comments