Opened 15 years ago

Closed 15 years ago

#2728 closed defect (fixed)

VRTSourcedRasterBand fails if there are no sources

Reported by: warmerdam Owned by: warmerdam
Priority: normal Milestone: 1.6.1
Component: GDAL_Raster Version: 1.5.0
Severity: normal Keywords: VRT
Cc:

Description

The following code fails to produce an output file because the CopyCreate() fails when trying to read from the VRT file. This is because VRTSourcedRasterBand() returns CE_Failure when there are no sources.

...
GDALDriver *poDriver = (GDALDriver *) GDALGetDriverByName( "VRT" );
GDALDataset *poVRTDS;
poVRTDS = poVRTDriver->Create("", xSize, ySize,
                             3, GDT_Byte,
                             NULL);
if(poVRTDS == NULL) {
 cerr << "Error: unable to create virtual GDAL dataset " \
      << endl;
 return false;
}

if(poVRTDS->SetProjection(pProjRef) == CE_Failure ||
  poVRTDS->SetGeoTransform(adfGeoTransform) == CE_Failure) {
 cerr << "Error: unable to set projection for the virtual dataset" \
      << endl;
 return false;
}

GDALDriver *poDriver = (GDALDriver *) GDALGetDriverByName( "Gtiff" );
GDALDataset *poDesDS;
poDesDS= poDriver->CreateCopy("myGTIFF.tif",
                             poVRTDS,
                             FALSE, NULL,
                             NULL, NULL);
 if(poDesDS== NULL) {
   cerr << "Error: unable to create GDAL dataset" << endl;
   GDALClose(poVRTDS);
   return false;
 }
 GDALClose(poVRTDS); 

Change History (1)

comment:1 by warmerdam, 15 years ago

Milestone: 1.5.41.6.1
Resolution: fixed
Status: newclosed

In trunk (r15932) and 1.6 branch (r15933) I have modified VRTSourcedRasterBand to permit operation of bands with no sources.

This change could be back ported to 1.5 if there was reason.

Note: See TracTickets for help on using tickets.