diff --git a/src/geotiff.js b/src/geotiff.js index 17349a41..9382bebb 100644 --- a/src/geotiff.js +++ b/src/geotiff.js @@ -422,6 +422,13 @@ class GeoTIFF extends GeoTIFFBase { offset + offsetSize + (entrySize * numDirEntries), ); + // Parse RPC coefficients if available + if (fileDirectory.RPCCoefficient && fileDirectory.RPCCoefficient.length === 92) { + fileDirectory.RPCCoefficient = this.parseRPCCoefficients(fileDirectory.RPCCoefficient); + } else if (fileDirectory.RPCCoefficient) { + console.warn('Invalid RPCCoefficient length'); + } + return new ImageFileDirectory( fileDirectory, geoKeyDirectory, @@ -429,6 +436,32 @@ class GeoTIFF extends GeoTIFFBase { ); } + parseRPCCoefficients(rpcArray) { + if (rpcArray.length !== 92) { + console.warn(`Invalid RPCCoefficient length. Expected 92, got ${rpcArray.length}`); + return null; + } + + return { + ERR_BIAS: rpcArray[0], + ERR_RAND: rpcArray[1], + LINE_OFF: rpcArray[2], + SAMP_OFF: rpcArray[3], + LAT_OFF: rpcArray[4], + LONG_OFF: rpcArray[5], + HEIGHT_OFF: rpcArray[6], + LINE_SCALE: rpcArray[7], + SAMP_SCALE: rpcArray[8], + LAT_SCALE: rpcArray[9], + LONG_SCALE: rpcArray[10], + HEIGHT_SCALE: rpcArray[11], + LINE_NUM_COEFF: rpcArray.slice(12, 32), + LINE_DEN_COEFF: rpcArray.slice(32, 52), + SAMP_NUM_COEFF: rpcArray.slice(52, 72), + SAMP_DEN_COEFF: rpcArray.slice(72, 92), + }; + } + async requestIFD(index) { // see if we already have that IFD index requested. if (this.ifdRequests[index]) { diff --git a/src/globals.js b/src/globals.js index 5707a669..5720c58c 100644 --- a/src/globals.js +++ b/src/globals.js @@ -116,6 +116,7 @@ export const fieldTagNames = { 0x87AF: 'GeoKeyDirectory', 0x87B0: 'GeoDoubleParams', 0x87B1: 'GeoAsciiParams', + 0xC69C: 'RPCCoefficient', // LERC 0xC5F2: 'LercParameters', @@ -171,6 +172,7 @@ export const fieldTagTypes = { 34736: 'DOUBLE', 34737: 'ASCII', 42113: 'ASCII', + 50844: 'DOUBLE', }; export const arrayFields = [ @@ -183,6 +185,7 @@ export const arrayFields = [ fieldTags.TileByteCounts, fieldTags.TileOffsets, fieldTags.SubIFDs, + fieldTags.RPCCoefficient, ]; export const fieldTypeNames = {