Hi <br><br>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 :(<br><br>The line i'm using to write the new value:
<br><br> ds.GetRasterBand(1).WriteRaster(s,t,1,1,str(newvalue))<br><br>gives me a raster with values written as 91 no matter what value one actually wants to write . what am i doing wrong?<br><br>the code i've written is provided below (lifted from a routine by Eric Raymond at
<a href="http://aspn.activestate.com/ASPN/Mail/Message/image-sig/2825804">http://aspn.activestate.com/ASPN/Mail/Message/image-sig/2825804</a>). it uses a copy (saved as ...demo-data/newfile.tif) to avoid mucking up the original file.
<br><br>if you can help...<br><br>thanks<br><br>sujoy<br><br>######################<br> def floodlist(self, pixel=None,line=None,value=None,newvalue=None):<br> edge = []<br> edge.append((pixel,line))<br> base_ds =
self.app.view_manager.get_active_view().list_layers()[0].get_parent()<br><br> bbase = vrtutils.serializeDataset(base_ds.get_dataset())<br> vrtlines = gdal.SerializeXMLTree(bbase)<br> vrtds = gdal.OpenShared
(vrtlines)<br> driver = gdal.GetDriverByName('GTiff')<br> fname = os.path.join(gview.home_dir,'demo-data','newtest.tif')<br> vrtds2 = driver.CreateCopy(fname,vrtds)<br><br> while edge:<br> newedge = []
<br> for (pixel,line) in edge:<br> for (s,t) in ((pixel+1, line), (pixel-1, line), (pixel, line+1), (pixel, line-1)):<br> newvalue = vrtds2.GetRasterBand(1).ReadAsArray(s,t,1,1)
<br> if newvalue == value:<br> newedge.append((s,t))<br> vrtds2.GetRasterBand(1).WriteRaster(s,t,1,1,str(newvalue))<br><br> edge = newedge<br><br>
vrtds2.FlushCache()<br> self.app.open_gdal_dataset(vrtds2)<br><br>