<div>Dear All,</div>
<div> </div>
<div>I am reading and writing raster images using GDAL. Below is the code which I am using for writing a raster.</div>
<div>At times the code is working fine. But many a time , it is getting crashed in the <strong>GetRasterBand.</strong> I have debugged the code several times and the variables passed seems to be perfect. Any help in this is regard would be appreciated.</div>
<div> </div>
<div> </div>
<div>bool GDALImageWriter::InitiliazeDataset(char* filename , int width , int height , int numOfbands ,rasterDataType datatype){</div>
<div> </div>
<div> this->imageWidth = width ;</div>
<div> this->imageHeight = height ;</div>
<div> this->numOfBands = numOfbands ;</div>
<div> this->datatpye = datatype ;</div>
<div> poBand = new GDALRasterBand*[numOfbands] ;</div>
<div> </div>
<div> poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");</div>
<div> </div>
<div> //papszOptions = CSLSetNameValue( papszOptions, "TILED", "YES" );</div>
<div> //papszOptions = CSLSetNameValue( papszOptions, "COMPRESS", "PACKBITS" );</div>
<div> </div>
<div> poDataset=NULL;</div>
<div> <strong>poDataset = poDriver->Create(filename , width , height , numOfbands ,(GDALDataType)datatype,NULL);</strong></div>
<div> </div>
<div> for(int i=0 ; i < numOfbands ; i++)</div>
<div> {</div>
<div> poBand[i] = poDataset->GetRasterBand(i+1);</div>
<div> }</div>
<div> </div>
<div> </div>
<div> if(projectionStr != NULL)</div>
<div> poDataset->SetProjection(projectionStr);</div>
<div> if(adfGeoTransform != NULL)</div>
<div> poDataset->SetGeoTransform(adfGeoTransform);</div>
<div> </div>
<div> if(poDataset == NULL)</div>
<div> return false ;</div>
<div> else</div>
<div> return true ;</div>
<div>}</div>
<div> </div>
<div> </div>
<div> </div>
<div>bool GDALImageWriter::writeData(int x , int y , int blockWidth , int blockHeight ,uchar* data){
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512">for(int i=0 ; i < numOfBands ; i++){</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 512">poBand[i]->RasterIO(GF_Write, x, y, blockWidth, blockHeight,data, blockWidth, blockHeight,(GDALDataType)this->datatpye, 0, 0);</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-user-state: 0">}</p></div>
<div> </div>
<div>bool GDALImageWriter::closeDataset(){
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">if(poDataset!=NULL)</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 256">GDALClose(poDataset);</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 0">}</p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 0"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 0"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 0"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 0"> </p>
<p style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-block-indent: 0; -qt-user-state: 0"> </p></div>
<div>-- </div>
<div>Regards,</div>
<div>Srikanth K.</div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>