[FWTools] WriteRaster outputs incorrect values

Sujoy Chaudhuri ecollage at gmail.com
Tue Mar 28 11:08:32 EST 2006


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.

if you can help...

thanks

sujoy

######################
    def floodlist(self, pixel=None,line=None,value=None,newvalue=None):
        edge = []
        edge.append((pixel,line))
        base_ds = self.app.view_manager.get_active_view
().list_layers()[0].get_parent()

        bbase = vrtutils.serializeDataset(base_ds.get_dataset())
        vrtlines = gdal.SerializeXMLTree(bbase)
    vrtds = gdal.OpenShared(vrtlines)
        driver = gdal.GetDriverByName('GTiff')
        fname = os.path.join(gview.home_dir,'demo-data','newtest.tif')
        vrtds2 = driver.CreateCopy(fname,vrtds)

        while edge:
            newedge = []
            for (pixel,line) in edge:
                for (s,t) in ((pixel+1, line), (pixel-1, line), (pixel,
line+1), (pixel, line-1)):
                    newvalue = vrtds2.GetRasterBand(1).ReadAsArray(s,t,1,1)
                    if newvalue == value:
                        newedge.append((s,t))
                        vrtds2.GetRasterBand
(1).WriteRaster(s,t,1,1,str(newvalue))

            edge = newedge

    vrtds2.FlushCache()
        self.app.open_gdal_dataset(vrtds2)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/fwtools/attachments/20060328/165fd65c/attachment.html


More information about the FWTools mailing list