Opened 14 years ago

Closed 14 years ago

#3327 closed enhancement (fixed)

Add support to the VRT driver to specify a background color instead of the the nodata value.

Reported by: chaitanya Owned by: chaitanya
Priority: normal Milestone: 1.7.0
Component: Utilities Version: svn-trunk
Severity: normal Keywords: VRT, gdalbuildvrt
Cc: warmerdam, Even Rouault


As requested by Greg Coats in I am adding a patch to the VRT driver and gdalbuildvrt. This works similar to the -init option in the script.

Attachments (1)

gregcoatsvrt.2.diff (8.1 KB ) - added by chaitanya 14 years ago.
The patch

Download all attachments as: .zip

Change History (7)

by chaitanya, 14 years ago

Attachment: gregcoatsvrt.2.diff added

The patch

comment:1 by chaitanya, 14 years ago

Status: newassigned

Applied the patch in r18561 in trunk.

Waiting for reviews.

comment:2 by warmerdam, 14 years ago

I don't seem to be fully grasping the point of this. Why the special hidenodata thing in the vrtrasterband?

As far as I can tell the hidenodata action just causes the VRTRasterBand to pretend it does not have a nodata value set. Does the nodata value get used for anything else?

Couldn't the user just not pass -vrtnodata to gdalbuildvrt? I'd like to hear a fully explanation of how this mechanism works, and is intended to be used.

comment:3 by chaitanya, 14 years ago

VRTRasterBand has a new subelement "HideNoDataValue". Default value is 0.

If this value is 1, the nodata value will not be reported. VRTRasterBand::GetNoDataValue(int *pbSuccess) will return the nodata value, but the variable pbSuccess will be set to FALSE. Essentially, the caller will not be aware of a nodata pixel when it reads one.

The background will be initialised using the value specified by the NoDataValue element. NoDataValue will be the background.

This is useful when you want to specify a fixed background value for the dataset.

By not passing the -vrtnodata to gdalbuildvrt, we will not have the ability to set the background value/color.

Updated the docs in trunk in r18563.

comment:4 by Even Rouault, 14 years ago

Frank, here's how I've understood the working and purpose of the patch :

Imagine that I have several raster tiles which can contain white areas or a pixel with one of its R,G,B component being 255), that the tiles don't completely fill their global bounding box and I want the empty areas to look white instead of black.

gdalbuildvrt -vrtnodata 255 -hidenodata dest.vrt src1.tif src2.tif ... srcN.tif

will use 255 as the value to fill empty areas between tiles (see VRTSourcedRasterBand::IRasterIO()), but not report it to the application processing the VRT. Without -hidenodata being specified, an application aware of nodata would display empty areas between tiles, and even valid areas with pixels at value 255 as transparent.

When Greg mentionned this need on the mailing list, I was hesitant to go further because I didn't see a nice solution. I had imagined adding a <BackgroundValue> element to the <VRTRasterBand> which could have been used to initialize the buffer in VRTSourcedRasterBand::IRasterIO(), but this would also have been confusing if <NoDataValue> was used at the same time.

Dealing with nodata is always confusing, especially for VRT when you have the notion of nodata for the source files (-srcnodata option of gdalbuildvrt) and nodata exposed by the VRT band (-vrtnodata). Let's hope this new option won't add too much confusion.

comment:5 by warmerdam, 14 years ago

Ok, I generally get it though it seems like a very specialized requirement. Something similar could have been accomplished with a normal run of gdalbuildvrt and then create another layer of VRT that would just omit the nodata value.

But I won't interfere. Within it's parameters the implementation seems ok, if a bit fragile.

comment:6 by chaitanya, 14 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.