<div dir="ltr"><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Dear Dr. Brad/all, Thanks for your kind and prompt reply. Below are my answers/clarifications. It may also be said that the program stops execution just after the 'operation->Initialize(WO)' step. Can someone help me solve this problem.</span></div><span style="font-size:12.8000001907349px"><div><span style="font-size:12.8000001907349px"><br></span></div>On Wed, 19 Aug 2015 04:01:32 PM user gdal wrote:</span><div><span style="font-size:12.8000001907349px"><br>Dear friends,<br>I have to programmatically clip (using Visual C++) with GDALWarp. I proceeded like this:<br><br>GDALDataset *outimg;<br><br>outimg=driver->Create(filename, NewCol, NewRow, Band, DataType, NULL);<br><br>GDALWarpOptions *WO=GDALCreateWarpOptions( );<br><br></span><div><span style="font-size:12.8000001907349px">if(WO)<br>{<br>  WO->hSrcDS=inimg; WO->nBandCount=Band;<br></span><span style="font-size:12.8000001907349px"><br></span><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">What is inimg?</span><br style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Ans. The bigger input image from which I want to draw subset (i.e., clip) with the help of a vector layer myshp. It' (inimg) is of type GDALDataset *. In the declaration of variables, it would appear as GDALDataset *inimg Also, in WO->hCutline (pl. see below), I am passing myshp (which has strictly polygon topology), of the type OGRLayer * (i.e., OGRLayer *myshp). Of course the shape file and inimg have the same projection.<br><br><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">What (exactly) are you passing as filename?</span></div><div style="font-size:12.8000001907349px">Ans. char *filename (such as e:\sub\subimage.img. There are no other characters in the 'filename')<br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Can you try posting an actual, compilable example?</span></div><div style="font-size:12.8000001907349px">Ans. There is a GUI from which I extract parameters which can give us a lot of inconvenience. The program compiles without 'abusing' me. What I am getting is a run time (or debug time) error.<br style="font-size:12.8000001907349px"><br>----------------------------------------------------------------------------------------------------------------------------------------------<br><div style="font-size:12.8000001907349px"><div>GDALDataset *inimg, *outimg;<br></div><div><br></div><div>outimg->(GDALDataset *) GDALOpen(filename, GA_Update);<br></div><div>/* I also tried, instead of the above, outimg=driver->Create(filename, NewCol, NewRow, Band, DataType, NULL); NewCol and NewRow, have values of the range 30 each */ <br></div><div><br></div></div><span style="font-size:12.8000001907349px">GDALWarpOptions *WO=GDALCreateWarpOptions( );</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">if(WO)</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">{</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  WO->hSrcDS=inimg; WO->nBandCount=Band; </span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  </span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  // In a sample image I wish to use, Band =3, checked</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  </span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  WO->hDstDS=(GDALDatasetH)(</span><span style="font-size:12.8000001907349px">outimg); WO->hCutline=myshp;</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  WO->panSrcBands=(int *) CPLMalloc(sizeof(int)*Band); WO->panSrcBands[0]=Band;</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  WO->panDstBands=(int *) CPLMalloc(sizeof(int)*Band); WO->panDstBands[0]=Band;</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  WO->pfnProgress=</span><span style="font-size:12.8000001907349px">GDALTermProgress;</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  GDALWarpOperation *operation=new GDALWarpOperation;</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  if(operation)</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  {</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    operation->Initialize(WO);  // the speed breaker</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    operation->ChunkAndWarpImage(</span><span style="font-size:12.8000001907349px">0, 0, NewCol, NewRow);</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    </span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    GDALDestroyWarpOptions(WO); WO=NULL; delete operation; operation=NULL;</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    </span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">   }</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">   GDALClose((GDALDatasetH) outimg); outimg=NULL;</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">   </span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">  }  </span><br><br>----------------------------------------------------------------------------------------------------------------------------------------------<br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Does the tutorial (just by itself, exactly as written) work on your machine?</span><br style="font-size:12.8000001907349px">Ans. To be honest I haven't checked. I, however, have gone through the tutorial and after convincing myself that I have understood what to do, I wrote the program.</div></div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">With many thanks,</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Yours sincerely,</div><div style="font-size:12.8000001907349px"> B. Ramesh</div></div></div>