<div>Thanks for the mail Alan.</div>
<div> </div>
<div>I am programming it in Cpp and using Qt architechture . I will try with a new raster band and try to make it as a mask with forecfully assiging a value to it.</div>
<div> </div>
<div> </div>
<div> </div>
<div>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512">data = (uchar *) CPLMalloc(sizeof(uchar)*width*height*bytesPerPixel);</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512">poBandR->RasterIO(GF_Read, xOff, yOff, width, height, data, width, height, (GDALDataType)dataType,bytesPerPixel, 0);</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512">for(int k = 0 ; k < width*height; k++)</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 768">{</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 768"> if(((uchar*)data)[k] != 255)</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 768"> ((uchar*)data)[k] = 0 ;</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 768"> else</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 768"> ((uchar*)data)[k] = 1 ;</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512">poBandR->RasterIO(GF_Write, xOff, yOff, width, height, data, width, height, (GDALDataType)dataType,bytesPerPixel, 0);</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512">if(data != NULL)</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 768">{</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 768">delete data ;</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 768">data = NULL ;</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512">}</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">const char *pszDriverName = "ESRI Shapefile";</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">OGRSFDriver *poDriver;</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">OGRDataSource* ds = poDriver->CreateDataSource("Shape", NULL );</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">OGRLayer* poLayer = ds->CreateLayer("myfile",NULL,wkbMultiPolygon,NULL);</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">CPLErr er = GDALPolygonize(poBandR , NULL , poLayer ,1,NULL,NULL,NULL);<br></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">Regards,</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">Srikanth<br></p></div>
<div class="gmail_quote">On Wed, Nov 18, 2009 at 4:35 PM, Alan Steel <span dir="ltr"><<a href="mailto:alan.steel@ext.jrc.ec.europa.eu">alan.steel@ext.jrc.ec.europa.eu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi Srikanth,<br><br>I have used gdal_polygonize.py, which is based on GDALpolygonize(). I think you know the algorithm better than I do, as you see that the 2nd argument is the mask band, which masks output values that are zero in the mask band.<br>
<br>Ok, that doesn't answer your question, and I don't know what is available in GDAL to write custom masks. I only write to suggest that you try learning a bit of C (or other programming language), which will alow you to write simple routines quickly.<br>
It does take time to learn, but can be very rewarding - and you can also eventually incorporate GDAL libraries into your programs. Not a short-tem solution, I know, but good in the long term. A C compiler comes with linux (gcc) and there are free IDEs that you can install on any platform.<br>
<br>The following is a loop that would (as part of a C program) write an output raster file that masks input pixel integer values with a value of 25 as 0.<br><br> for(b = 0; b < bands; b++){ for(i = 0; i < rows; i++){<br>
//read a row of data from input file<br> fread(dataRow, sizeof(int), cols, fp_in1);<br> for(d=dataRow, o=dataRowOut; d < dataRow+cols; d++, o++){<br> if(*d == 25)<br>
*o = 0;<br> }<br> fwrite(dataRowOut, sizeof(int), cols, fp_out);<br> } }<br><br>Regards,<br><font color="#888888"><br>Alan</font>
<div>
<div></div>
<div class="h5"><br><br>Srikanth wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi ,<br> I have found the solution myself.<br>Below is the piece of code for polygonizing the raster.<br> Yet there is another problem i am facing. I am unable to create a mask band for a particular pixel value.I understand that could be done using thresholding. But I did not find any method for that in GDAL.<br>
Any help/suggestions are appreciated.<br> <br>GDALAllRegister();<br><br>OGRRegisterAll();<br><br>String pszFilename = "C:\\Images\\s3dImages\\geo_liss.tif";<br><br>poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );<br>
<br>GDALRasterBand *poBandR,*poBandMask ;<br><br>poBandR = poDataset->GetRasterBand(1);<br><br>poBandR->CreateMaskBand(GMF_PER_DATASET);<br><br>poBandMask = poBandR->GetMaskBand() ;<br><br>poBandMask->Fill(10,0);<br>
<br>const char *pszDriverName = "ESRI Shapefile";<br><br>OGRSFDriver *poDriver;<br><br>poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);<br><br>OGRDataSource* ds = poDriver->CreateDataSource("Shape", NULL );<br>
<br>OGRLayer* poLayer = ds->CreateLayer("myfile",NULL,wkbMultiPolygon,NULL);<br><br>CPLErr er = GDALPolygonize(poBandR , poBandMask , poLayer ,1,NULL,NULL,NULL);<br><br>poLayer->SyncToDisk();<br><br>OGRDataSource::DestroyDataSource(ds);<br>
<br> <br></blockquote><br></div></div></blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Srikanth K.<br><a href="http://www.servetheneedy.org">www.servetheneedy.org</a><br><br>