<div dir="ltr"><p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">Dear All,</span></p><p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">I want to programmatically clip a raster ("inimg") with a polygon vector of the format shp ("myshp"); both have the same geog. reference, which I tested using std. SW, say, QGIS. I proceeded as per the code below. I am getting an error "</span><font face="Arial, sans-serif"><span style="font-size:11.3333px">Unhandled exception... Access Violation</span></font><span style="font-family:Arial,sans-serif;font-size:8.5pt">", when no pointers are NULL! What could have been the error in my understanding?</span></p><p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><br></p><p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">GDALDataset *inimg,
*outimg;</span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif"> </span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">outimg->(GDALDataset
*) GDALOpen(filename, GA_Update);</span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">outimg=driver->Create(filename,
NewCol, NewRow, Band, DataType, NULL); /* NewCol and NewRow, each have values
of the range 30 */ </span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif"> </span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">GDALWarpOptions
*WO=GDALCreateWarpOptions( );<br>
<br>
if(WO)<br>
{<br>
  WO->hSrcDS=(GDALDatasetH)(inimg); WO->nBandCount=Band; </span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">  </span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">  // In a sample
image I wish to use, Band =3, checked<br>
  <br>
  WO->hDstDS=(GDALDatasetH)(outimg); WO->hCutline=myshp; // OGRLayer *myshp;<br>
<br>
  WO->panSrcBands=(int *) CPLMalloc(sizeof(int)*Band);
WO->panSrcBands[0]=Band;<br>
  WO->panDstBands=(int *) CPLMalloc(sizeof(int)*Band);
WO->panDstBands[0]=Band;<br>
<br>
  WO->pfnProgress=GDALTermProgress;<br>
<br>
  GDALWarpOperation *operation=new GDALWarpOperation;<br>
<br>
  if(operation)<br>
  {<br>
    operation->Initialize(WO);  // the speed breaker<br>
    operation->ChunkAndWarpImage(0, 0, NewCol, NewRow);<br>
    <br>
    GDALDestroyWarpOptions(WO); WO=NULL; delete operation;
operation=NULL;<br>
    <br>
   }<br>
<br>
   GDALClose((GDALDatasetH) outimg); outimg=NULL;<br>
   <br>
  }  </span></p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Referring to the above,</p><p class="MsoNormal"><br></p>

<p class="MsoNormal" style="margin-bottom:12pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">What is inimg?</span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">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>
What (exactly) are you passing as filename?</span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">Ans. char *filename
(such as e:\sub\subimage.img. There are no other characters in the 'filename')<br>
<br>
Can you try posting an actual, compilable example?</span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif">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.</span></p>

<p class="MsoNormal" style="margin-bottom:0.0001pt;background-image:initial;background-repeat:initial"><span style="font-size:8.5pt;font-family:Arial,sans-serif"> </span></p>

<p class="MsoNormal">With thanks,</p>

<p class="MsoNormal">                                                                                                                                                                                                                                              Yours sincerely,</p>

<p class="MsoNormal">                                                                                                                                                     B. Ramesh</p></div>