[gdal-dev] (no subject)

user gdal userofgdal at gmail.com
Thu Aug 20 01:39:28 PDT 2015


Dear Dr. Brad, Thanks for your kind and prompt reply. Below are my
answers/clarifications.

On Wed, 19 Aug 2015 04:01:32 PM user gdal wrote:
> Dear friends,
>                    I have to programmatically clip (using Visual C++) with
> GDALWarp. I proceeded like this:
>
> GDALDataset *outimg;
>
> outimg->(GDALDataset *) GDALOpen(filename, GA_Update);
> /* I also tried, instead of the above, outimg=driver->Create(filename,
> NewCol, NewRow, Band, DataType, NULL); */
>
> GDALWarpOptions *WO=GDALCreateWarpOptions( );
>
> if(WO)
> {
>   WO->hSrcDS=inimg; WO->nBandCount=Band;

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.

----------------------------------------------------------------------------------------------------------------------------------------------
GDALDataset *inimg, *outimg;

outimg->(GDALDataset *) GDALOpen(filename, GA_Update);
/* 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 */

GDALWarpOptions *WO=GDALCreateWarpOptions( );

if(WO)
{
  WO->hSrcDS=inimg; WO->nBandCount=Band;

  // In a sample image I wish to use, Band =3, checked

  WO->hDstDS=(GDALDatasetH)(outimg); WO->hCutline=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);
    operation->ChunkAndWarpImage(0, 0, NewCol, NewRow);

    GDALDestroyWarpOptions(WO); WO=NULL; delete operation; operation=NULL;

   }

   GDALClose((GDALDatasetH) outimg); outimg=NULL;

  }

----------------------------------------------------------------------------------------------------------------------------------------------
Does the tutorial (just by itself, exactly as written) work on your machine?
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.

______________________________
__________________________________________________

With many thanks,
Yours sincerely,
 T.S. Prasad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150820/a2a350d8/attachment.html>


More information about the gdal-dev mailing list