Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to read Arc/Info Binary Grids and convert them to other image formats using the C#-bindings of GDAL. I installed FWTools 2.4.7 and the current binaries (MSVC2010 (Win64) -stable) from here. Then I started testing the example C#-programs that are part of FWTools, especially GDALRead.cs and GDALReadDirect.cs. When I use the demo dataset utm.tif, this all works fine.

I then converted utm.tif to the Arc/Info Binary Grid format using ArcMap 10 (Conversion Tools - To Raster - Raster to other Format). When I try to use GDALRead.cs or GDALReadDirect.cs I get the following error messages:

GDALRead.cs:

Using driver Arc/Info Binary Grid
Band 1 :
DataType: GDT_Int16
Size (512,512)
PaletteInterp: GCI_Undefined
  OverView 0 :
     DataType: GDT_Int16
     Size (256,256)
     PaletteInterp: GCI_GrayIndex
  OverView 1 :
     DataType: GDT_Int16
     Size (128,128)
     PaletteInterp: GCI_GrayIndex
Non RGB images are not supported by this sample! ColorInterp = GCI_Undefined

GDALReadDirect.cs:

Using driver Arc/Info Binary Grid
Band 1 :
   DataType: GDT_Int16
   Size (512,512)
   PaletteInterp: GCI_Undefined
      OverView 0 :
         DataType: GDT_Int16
         Size (256,256)
         PaletteInterp: GCI_GrayIndex
      OverView 1 :
         DataType: GDT_Int16
         Size (128,128)
         PaletteInterp: GCI_GrayIndex
The number of the raster bands is not enough to run this sample

This behavior is a bit surprising for me, as I did not change the dataset, I simply converted it into a new format. Any hints about the reasons for this behavior and how I can use GDAL via C# to convert ArcInfo binary grids to other image formats appreciated.

share|improve this question

migrated from gis.stackexchange.com May 8 '13 at 20:35

This question came from our site for cartographers, geographers and GIS professionals.

1 Answer 1

up vote 0 down vote accepted

GDALReadDirect.cs has an erroneous method named SaveBitMapDirect, that first checks on the available Color interpretation and then on the number of bands. After the file is converted to Arc/Info binary Grid format, the information about the Color interpretation is lost, so only then the program checks on the number of available bands and returns an error message. SaveBitMapDirect works for the described case if Line 157 is edited:

if (redBand.GetRasterColorInterpretation() == ColorInterp.GCI_GrayIndex || redBand.GetRasterColorInterpretation() == ColorInterp.GCI_Undefined)

This is not a general fix, only for the immediate problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.