[FWTools] WriteRaster outputs incorrect values

Frank Warmerdam warmerdam at pobox.com
Tue Mar 28 11:42:10 EST 2006


Sujoy Chaudhuri wrote:
> Hi
> 
> I've been working on a tool that helps correct contiguous patches of 
> mis-classified imagery with an interactive 'change-value-to:__' using a 
> flood-fill routine and it works - well somewhat :(
> 
> The line i'm using to write the new value:
> 
>     ds.GetRasterBand(1).WriteRaster(s,t,1,1,str(newvalue))
> 
> gives me a raster with values written as 91 no matter what value one 
> actually wants to write . what am i doing wrong?
> 
> the code i've written is provided below (lifted from a routine by Eric 
> Raymond at 
> http://aspn.activestate.com/ASPN/Mail/Message/image-sig/2825804). it 
> uses a copy (saved as ...demo-data/newfile.tif) to avoid mucking up the 
> original file.

Sujoy,

The problem is that newvalue is an array, likely something like [[27]]
but you are converting it directly to a string before passing to WriteRaster.
Well, str([[27]]) is '[[27]]', and the ascii code for the '[' character is 91.
I think you might have better luck passing chr(newvalue[0][0]) which passes
a string of one character with the ascii code matching the numeric value of
the [0][0] element of the newvalue array.

I will warn you that your current approach is likely to be very slow.  There
is quite a bit of overhead for each GDAL RasterIO() type call, and so doing
one for every pixel is not going to be pleasant.  If if get things working,
you might want to look at ways to hold more or all of the image in RAM.

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 OSGF, http://osgeo.org



More information about the FWTools mailing list