[gdal-dev] Re: reg GDALPolygonize
Srikanth
srikanth1947 at gmail.com
Wed Nov 18 04:11:05 EST 2009
Hi ,
I have found the solution myself.
Below is the piece of code for polygonizing the raster.
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.
Any help/suggestions are appreciated.
GDALAllRegister();
OGRRegisterAll();
String pszFilename = "C:\\Images\\s3dImages\\geo_liss.tif";
poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );
GDALRasterBand *poBandR,*poBandMask ;
poBandR = poDataset->GetRasterBand(1);
poBandR->CreateMaskBand(GMF_PER_DATASET);
poBandMask = poBandR->GetMaskBand() ;
poBandMask->Fill(10,0);
const char *pszDriverName = "ESRI Shapefile";
OGRSFDriver *poDriver;
poDriver =
OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);
OGRDataSource* ds = poDriver->CreateDataSource("Shape", NULL );
OGRLayer* poLayer = ds->CreateLayer("myfile",NULL,wkbMultiPolygon,NULL);
CPLErr er = GDALPolygonize(poBandR , poBandMask , poLayer
,1,NULL,NULL,NULL);
poLayer->SyncToDisk();
OGRDataSource::DestroyDataSource(ds);
On Mon, Nov 16, 2009 at 3:27 PM, Srikanth <srikanth1947 at gmail.com> wrote:
> Dear All ,
>
> I am trying to convert a raster to vector using GDALPolygonize function .
> Below is the code I am using
> GDALAllRegister();
>
> String pszFilename = "C:\\Images\\image.tiff";
>
> poDataset = (GDALDataset *) GDALOpen( pszFilename , GA_ReadOnly );
>
> GDALRasterBand *poBandR,*poBandG,*poBandB;
>
> poBandR = poDataset->GetRasterBand(1);
>
> OGRLayer* poLayer;
>
> GDALPolygonize(poBandR , NULL , poLayer ,1,NULL,NULL,NULL);
>
>
> The process is crashed in the polygonize function. I wonder what might be
> wrong with the above. (or should I assign memory to OGRLayer ?)
>
> Any suggestions/examples regarding the same are appreciated.
>
>
> --
> Regards,
> Srikanth K.
>
>
>
--
Regards,
Srikanth K.
www.servetheneedy.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20091118/6aeeb88d/attachment.html
More information about the gdal-dev
mailing list