[Gdal-dev] Creating an empty ColorTable in C++

Roger Bivand Roger.Bivand at nhh.no
Tue Aug 29 15:31:50 EDT 2006


On Tue, 29 Aug 2006, Frank Warmerdam wrote:

> Roger Bivand wrote:
>   > My plan was to pass from R to GDAL the handles to two data sets, the
> > output one of which would get populated by the color index band and the 
> > color table. I now see a clean error exit:
> > 
> > Error in rgdal:::SGDF2RGB(xx) : 
> >         GDAL Error 6: SetColorTable() not supported for existing TIFF files.
> > 
> > which suggests that I should rather initiate the output dataset in my 
> > C/C++ code.
> 
> Roger,
> 
> I think the key here is that the GeoTIFF driver in GDAL only allows you
> to assign a pseudocolor table to a file before you start any raster data.
> 

OK, thanks.

> >> I suspect that the GetColorTable() is returning NULL which is causing the
> >> crash later on.
> >>
> >> Also, I notice you were using the C++ method to fetch the color table.
> >> It is up to you, but if you were to use only the C API in an R interface
> >> to GDAL it would make things much less "version fragile".  That is, new
> >> versions of GDAL could be substituted without necessarily having to
> >> recompile the R wrappers as the C API is much more ABI stable than the
> >> C++ API.
> >>
> > 
> > I'm very much building on and maintaining Tim Keitt's elegant C++ code, 
> > which is written C++ style; as is evident C++ is not a language I enjoy, 
> > but I would not want to have to rewrite Tim's earlier work. So the code 
> > has stayed a mixture of elegance where I haven't done anything and 
> > muddling through where I have written things.
> 
> OK, I can understand the desire to not rewrite everything.  I just wanted
> to raise the issue.

Using system() from the R level and assuming rgb2pct.py in the PATH, 
things work OK, which is enough for now. I'll return to the compiled code 
later, which will remove the Python dependency (the Windows rgdal 
binary package does not have Python build-in). Tim was using the raster 
decimation and a quick image to check if he was in the right part of a big 
raster.

Thanks!

Roger

> 
> Best regards,
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the Gdal-dev mailing list