[gdal-dev] Reading ERS format with "HeaderOffset" field
Frank Warmerdam
warmerdam at pobox.com
Fri Jul 4 17:56:54 EDT 2008
Frank Horowitz wrote:
> Hi all,
>
> We've been trying to read some ERS ("foo.ers") files in ERMapper raw
> raster format. While many of them work perfectly (thanks for the great
> software, BTW!) we're finding a bug in reading some of those files which
> incorporate the "HeaderOffset" field.
>
> The obvious thing is happening when reading a file with such a header:
> the values are shifted right "HeaderOffset" pixels, and the header is
> being read as data in the image.
>
> Looking through the code, I had a go a hacking (emphasis on hacking) a
> simple patch:
...
> +/* -------------------------------------------------------------------- */
> /* Establish the data type. */
> /* -------------------------------------------------------------------- */
> GDALDataType eType;
> @@ -776,9 +786,9 @@
> poDS->SetBand(
> iBand+1,
> new RawRasterBand( poDS, iBand+1, poDS->fpImage,
> - iWordSize * iBand *
> poDS->nRasterXSize,
> + headerOffset + iWordSize * iBand
> * poDS->nRasterXSize,
> iWordSize,
> - iWordSize * nBands *
> poDS->nRasterXSize,
> + headerOffset + iWordSize *
> nBands * poDS->nRasterXSize,
> eType, bNative, TRUE ));
> }
> }
>
> The trouble is, I'm shooting blind, without understanding details of
> GDAL's data model, API, codebase, etc. etc. etc. This patch does not
> appear to work, with results ranging from simple failure to account for
> the header when actually reading such a file to segfaults.
The RawRasterBand() arguments are:
RawRasterBand( GDALDataset *poDS, int nBand, FILE * fpRaw,
vsi_l_offset nImgOffset, int nPixelOffset,
int nLineOffset,
GDALDataType eDataType, int bNativeOrder,
int bIsVSIL = FALSE, int bOwnsFP = FALSE );
the only one you need to offset by the header amount is nImgOffset.
It looks like you also modified the line offset. Try it with:
poDS->SetBand(
iBand+1,
new RawRasterBand( poDS, iBand+1, poDS->fpImage,
headerOffset + iWordSize * iBand *
poDS->nRasterXSize,
iWordSize,
iWordSize * nBands * poDS->nRasterXSize,
eType, bNative, TRUE ));
If that works, please submit a ticket with the patch and I'll apply
it in the master. A small dataset demonstrating use of the header offset
would also be helpful.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | President OSGeo, http://osgeo.org
More information about the gdal-dev
mailing list