[gdal-dev] GDALWarp fails to initialize
user gdal
userofgdal at gmail.com
Tue Sep 8 21:59:04 PDT 2015
Dear All,
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 "Unhandled exception... Access Violation", when no
pointers are NULL! What could have been the error in my understanding?
GDALDataset *inimg, *outimg;
outimg->(GDALDataset *) GDALOpen(filename, GA_Update);
outimg=driver->Create(filename, NewCol, NewRow, Band, DataType, NULL); /*
NewCol and NewRow, each have values of the range 30 */
GDALWarpOptions *WO=GDALCreateWarpOptions( );
if(WO)
{
WO->hSrcDS=(GDALDatasetH)(inimg); WO->nBandCount=Band;
// In a sample image I wish to use, Band =3, checked
WO->hDstDS=(GDALDatasetH)(outimg); WO->hCutline=myshp; // OGRLayer *myshp;
WO->panSrcBands=(int *) CPLMalloc(sizeof(int)*Band);
WO->panSrcBands[0]=Band;
WO->panDstBands=(int *) CPLMalloc(sizeof(int)*Band);
WO->panDstBands[0]=Band;
WO->pfnProgress=GDALTermProgress;
GDALWarpOperation *operation=new GDALWarpOperation;
if(operation)
{
operation->Initialize(WO); // the speed breaker
operation->ChunkAndWarpImage(0, 0, NewCol, NewRow);
GDALDestroyWarpOptions(WO); WO=NULL; delete operation; operation=NULL;
}
GDALClose((GDALDatasetH) outimg); outimg=NULL;
}
Referring to the above,
What is inimg?
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.
What (exactly) are you passing as filename?
Ans. char *filename (such as e:\sub\subimage.img. There are no other
characters in the 'filename')
Can you try posting an actual, compilable example?
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.
With thanks,
Yours sincerely,
B.
Ramesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150909/3337017d/attachment.html>
More information about the gdal-dev
mailing list