Opened 13 years ago

Closed 7 years ago

#859 closed defect (fixed)

gdalwarp from VRTRasterBand SimpleSource to VRTRawRasterBand should create/update raw output file

Reported by: dkleiner@… Owned by: warmerdam
Priority: high Milestone: 1.9.0
Component: GDAL_Raster Version: unspecified
Severity: major Keywords:

Description (last modified by Even Rouault)

Overview Description:

Trying to write to a VRT dataset that uses VRTRawRasterBands does not properly 
create or update the file named by <SourceFilename>.  Using gdalwarp, either the 
whole VRT file is overwritten as a GeoTIFF file if the <SourceFilename> does not 
exists, or an read-only error is generated if <SourceFilename> does exists.

Steps to Reproduce:

1) Create a small grey-scale TIFF file, 512 x 512, named 'test-in.tif'.

2) Create 'test-in.vrt' to add some (meaningless) georeferencing:

<VRTDataset rasterXSize="512" rasterYSize="512">
  <GeoTransform>0.0, 0.1, 0.0, 0.0, 0.0, -0.1</GeoTransform>
  <VRTRasterBand dataType="Byte" band="1">
      <SourceFilename relativeToVRT="1">test-in.tif</SourceFilename>
      <SrcRect xOff="0" yOff="0" xSize="512" ySize="512"/>
      <DstRect xOff="0" yOff="0" xSize="512" ySize="512"/>

3) Create 'test-out.vrt' to specify a raw output file:

<VRTDataset rasterXSize="512" rasterYSize="512">
  <VRTRasterBand dataType="Byte" band="1" subClass="VRTRawRasterBand">
    <SourceFilename relativetoVRT="1">test-out.raw</SourceFilename>

4) $ gdalwarp test-in.vrt test-out.vrt
Creating output file that is 512P x 512L.
:0...10...20...30...40...50...60...70...80...90...100 - done.

5) $ file test-out.vrt
test-out.vrt: TIFF image data, little-endian

6) Make test-out.vrt again as in step 3.

7) $ touch test-out.raw

8) $ gdalwarp test-in.vrt test-out.vrt
ERROR 5: Destination band 1 appears to be read-only.

Actual Results:

Either the output VRT file is overwritten as a GeoTIFF file, or an error message 
indicating read-only state of the output is given.

Expected Results:

The test-out.raw file should be created or updated with the raw image data.  The 
file should be of size 262144 bytes.  Each byte should be the gray-scale 
equivalent of the corresponding pixel in the original source TIFF.

Build Version:

$ gdalinfo --version
GDAL, released 2005/03/13


Red Hat Fedora Core 1

Change History (2)

comment:1 Changed 13 years ago by dkleiner@…

VRTDataset does not override default eAccess of GDALDataset (GA_ReadOnly).

I changed VRTRawRasterBand constructor to set eAccess to GA_Update, still had 
read-only error as described.

Seems that GDALDataset->SetBand forces band access to that of the dataset, thus 
when VRTRawRasterBands are added to VRTDatasets, they're forced to GA_ReadOnly.

Setting eAccess to GA_Update in VRTDataset constructor fixes problem, but is 
probably not the right way, since not all VRTDatasets support update - but this 
appears to be the crux of the described bug.

Still does not explain why a GeoTIFF is created if the raw file named by 
SourceFilename does not exist.

comment:2 Changed 7 years ago by Even Rouault

Description: modified (diff)
Milestone: 1.9.0
Resolution: fixed
Status: newclosed

gdalwarp byte.tif test.vrt

where test.vrt is :

<VRTDataset rasterXSize="20" rasterYSize="20">
  <SRS>PROJCS[&quot;NAD27 / UTM zone 11N&quot;,GEOGCS[&quot;NAD27&quot;,DATUM[&quot;North_American_Datum_1927&quot;,SPHEROID[&quot;Clarke 1866&quot;,6378206.4,294.9786982139006,AUTHORITY[&quot;EPSG&quot;,&quot;7008&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6267&quot;]],PRIMEM[&quot;Greenwich&quot;,0],UNIT[&quot;degree&quot;,0.0174532925199433],AUTHORITY[&quot;EPSG&quot;,&quot;4267&quot;]],PROJECTION[&quot;Transverse_Mercator&quot;],PARAMETER[&quot;latitude_of_origin&quot;,0],PARAMETER[&quot;central_meridian&quot;,-117],PARAMETER[&quot;scale_factor&quot;,0.9996],PARAMETER[&quot;false_easting&quot;,500000],PARAMETER[&quot;false_northing&quot;,0],UNIT[&quot;metre&quot;,1,AUTHORITY[&quot;EPSG&quot;,&quot;9001&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;26711&quot;]]</SRS>
  <GeoTransform>  4.4072000000000000e+05,  6.0000000000000000e+01,  0.0000000000000000e+00,  3.7513200000000000e+06,  0.0000000000000000e+00, -6.0000000000000000e+01</GeoTransform>
  <VRTRasterBand dataType="Byte" band="1" subClass="VRTRawRasterBand">
    <SourceFilename relativetoVRT="1">test.raw</SourceFilename>


And I've jsut fixed the case where test.raw didn't yet exist in r22776

Note: See TracTickets for help on using tickets.