<div>Hi ,</div>
<div> </div>
<div>I have found the solution myself.</div>
<div>Below is the piece of code for polygonizing the raster.</div>
<div> </div>
<div>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.</div>
<div> </div>
<div>Any help/suggestions are appreciated.</div>
<div> </div>
<div><br>GDALAllRegister();</div>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">OGRRegisterAll();</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">String pszFilename = "C:\\Images\\s3dImages\\geo_liss.tif";</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">poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );</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">GDALRasterBand *poBandR,*poBandMask ;</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">poBandR = poDataset->GetRasterBand(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: 256">poBandR->CreateMaskBand(GMF_PER_DATASET);</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">poBandMask = poBandR->GetMaskBand() ;</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">poBandMask->Fill(10,0);</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-paragraph-type: empty"></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-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-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-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-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-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">CPLErr er = GDALPolygonize(poBandR , poBandMask , poLayer ,1,NULL,NULL,NULL);</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-paragraph-type: empty"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">poLayer->SyncToDisk();</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty"></p>
<div style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">OGRDataSource::DestroyDataSource(ds);</div>
<div style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256"> </div>
<div style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256"><br> </div>
<div class="gmail_quote">On Mon, Nov 16, 2009 at 3:27 PM, Srikanth <span dir="ltr"><<a href="mailto:srikanth1947@gmail.com">srikanth1947@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>Dear All ,</div>
<div> </div>
<div>I am trying to convert a raster to vector using GDALPolygonize function . Below is the code I am using<br clear="all"></div>
<div>GDALAllRegister();
<p style="MARGIN: 0px; TEXT-INDENT: 0px"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px">String pszFilename = "C:\\Images\\image.tiff";</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px">poDataset = (GDALDataset *) GDALOpen( pszFilename , GA_ReadOnly );</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px">GDALRasterBand *poBandR,*poBandG,*poBandB;</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px">poBandR = poDataset->GetRasterBand(1);</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px">OGRLayer* poLayer;</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px"></p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px">GDALPolygonize(poBandR , NULL , poLayer ,1,NULL,NULL,NULL);</p></div>
<div> </div>
<div> </div>
<div>The process is crashed in the polygonize function. I wonder what might be wrong with the above. (or should I assign memory to OGRLayer ?) </div>
<div> </div>
<div>Any suggestions/examples regarding the same are appreciated.</div>
<div> </div><font color="#888888">
<div><br>-- <br>Regards,<br>Srikanth K.<br><br><br></div></font></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>