Opened 18 years ago

Last modified 17 years ago

#1311 closed defect (fixed)

colour table not read for ArcInfo binary grid

Reported by: matt.wilkie@… Owned by: warmerdam
Priority: highest Milestone:
Component: GDAL_Raster Version: unspecified
Severity: blocker Keywords:
Cc:

Description

The arcinfo binary grid page (http://www.gdal.org/frmt_various.html#AIG) says that "Support includes reading ... a color table (.clr) if available.", but on my system that does not occur without a workaround: copying the .clr file into the grid's data directory. However for ArcInfo, AV3, and ArcMap the .clr is not read unless it is in the parent directory (observed behaviour. I could not find a spec. The closest is http://tinyurl.com/zx5f9 "For GRID files, the colormap information is stored in a .clr file with the same name as the GRID.")

Directory of an ArcInfo Binary Grid shown below:

aibg_bug\aibg_256c.clr        <--- necessary for Arc to read pallette
aibg_bug\aibg_256c\aibg_256c.clr   <---- necessary for gdal to read pallette
aibg_bug\aibg_256c\dblbnd.adf
aibg_bug\aibg_256c\hdr.adf
aibg_bug\aibg_256c\log
aibg_bug\aibg_256c\prj.adf
aibg_bug\aibg_256c\sta.adf
aibg_bug\aibg_256c\vat.adf
aibg_bug\aibg_256c\w001001.adf
aibg_bug\aibg_256c\w001001x.adf
aibg_bug\info\arc.dir
aibg_bug\info\arc0000.dat
aibg_bug\info\arc0000.nit
aibg_bug\info\arc0001.dat
aibg_bug\info\arc0001.nit
aibg_bug\info\arc0002.dat
aibg_bug\info\arc0002.nit
aibg_bug\info\arc0002r.001

To reproduce bug for gdal, move the aibg_256c\*.clr file and run gdalinfo:

> gdalinfo aibg_256c
...
Band 1 Block=256x4 Type=Byte, ColorInterp=Undefined
...

and then put it back:

> gdalinfo aibg_256c
...
Band 1 Block=256x4 Type=Byte, ColorInterp=Palette
...

Attachments (4)

aibg_clr_bug.zip (57.9 KB ) - added by matt.wilkie@… 18 years ago.
sample arcinfo binary grid with colour map which reproduces the problem
cpl_conv.h (13.2 KB ) - added by dreamil@… 17 years ago.
file containing prototype for CPLCleanTrailingSlash function
cpl_path.cpp (28.5 KB ) - added by dreamil@… 17 years ago.
file containing function CPLCleanTrailingSlash
aigdataset.cpp (21.9 KB ) - added by dreamil@… 17 years ago.
actual code for fixing the bug

Download all attachments as: .zip

Change History (8)

by matt.wilkie@…, 18 years ago

Attachment: aibg_clr_bug.zip added

sample arcinfo binary grid with colour map which reproduces the problem

by dreamil@…, 17 years ago

Attachment: cpl_conv.h added

file containing prototype for CPLCleanTrailingSlash function

by dreamil@…, 17 years ago

Attachment: cpl_path.cpp added

file containing function CPLCleanTrailingSlash

by dreamil@…, 17 years ago

Attachment: aigdataset.cpp added

actual code for fixing the bug

comment:1 by dreamil@…, 17 years ago

With help from Frank, I have modified the aigdataset.cpp file to fix this bug. What is now done is, whenever looking for a color table file, we first lookup in the data directory. The first file with extension .clr is used as color table file. If the data directory doesnt contain a .clr file, then we try to find it in the parent directory. When looking for .clr file in parent directory, we only consider file whose name (without extension) is same as the data directory name.
  e.g. if the data directory name is mumbai then in the parent directory we look for file named mumbai.clr and so on. 
  This is because parent directory may contain more than one clr files which may belong to various data sets.
  For finding out the parent directory of data directory, we had to write a new function called CPLCleanTrailingSlash. This function removes the traling forward/backward slash specified in the path of data directory because having a traling slash in the path makes CPLGetFilename function return a blank string. So before calling CPLGetFilename on the path, we get the traling slash removed from it, if any. In case there is no trailing slash, the function returns path as it is.

  The solution has been tested and found working on GNU/Linux. The 3 attachments with this bug are not patches but they are actual source files.Frank is requested to commit the changes in CVS.

comment:2 by warmerdam, 17 years ago

Patches reviewed and applied. 

Bug report kept open pending writing an AIG driver test script.

comment:3 by matt.wilkie@…, 17 years ago

thanks guys :)

comment:4 by warmerdam, 17 years ago

Swapnil has written and committed the test script
(gdalautotest/gdrivers/aigrid.py) and it seems to be working fine. 

closing..

Note: See TracTickets for help on using tickets.