Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#5087 closed defect (fixed)

[PATCH] gdalwarp does not apply source nodata value to destination

Reported by: etourigny Owned by: etourigny
Priority: normal Milestone: 1.11.0
Component: Utilities Version: unspecified
Severity: normal Keywords: warp, nodata
Cc:

Description

I have just noticed that destination nodata value is not set when -dstnodata option is not used in gdalwarp.

This can be problematic when warping a dataset with no data values, as the result can be different from expected, if -dstnodata is not set. gdalwarp does use source nodata pixels if -srcnodata is not used.

I consider this as a bug (or at the very least a limitation), because one cannot warp a dataset in an automatic fashion and get expected output (with same nodata value as input).

Would it be OK to copy them over if -dstnodata is not used, or would there be problems with doing this? Or perhaps a new argument -copynodata could be added if there is fear of disruption.

Attaching a patch wich copies over nodata values if -dstnodata argument is not used, and if source nodata exists.

Attachments (3)

warp-nodata.txt (2.7 KB) - added by etourigny 5 years ago.
warp-nodata2.txt (4.9 KB) - added by etourigny 5 years ago.
warp-nodata3.txt (6.1 KB) - added by etourigny 5 years ago.

Download all attachments as: .zip

Change History (13)

Changed 5 years ago by etourigny

Attachment: warp-nodata.txt added

comment:1 Changed 5 years ago by Even Rouault

In case there's a use for not setting nodata to the target dataset, perhaps "-dstnodata none" could be recognized.

comment:2 in reply to:  1 ; Changed 5 years ago by etourigny

Owner: changed from warmerdam to etourigny

Replying to rouault:

In case there's a use for not setting nodata to the target dataset, perhaps "-dstnodata none" could be recognized.

I think this happens already with srcnodata. Your suggestion is to copy nodata from source to destination, unless another value is given in dstnodata (use those values) or 'none' (do not set nodata).

Can I apply this to 1.10 also?

thanks

comment:3 in reply to:  2 Changed 5 years ago by Even Rouault

I think this happens already with srcnodata. Your suggestion is to copy nodata from source to destination, unless another value is given in dstnodata (use those values) or 'none' (do not set nodata).

Yes

Can I apply this to 1.10 also?

Changing behaviour seems a bit risky for a maintenance version.

Changed 5 years ago by etourigny

Attachment: warp-nodata2.txt added

comment:4 Changed 5 years ago by etourigny

Milestone: 2.0

Attached a new patch which explicitly does not set nodata when argument "none" is given. If there are less than #bands arguments, then the last value is used (if "none" remaining bands do not have a nodata value). I have not touched srcnodata. None of this is documented (including srcnodata=none), I will update.

Please review. Will not apply to 1.10, thanks!

comment:5 Changed 5 years ago by etourigny

Actually just noticed that None is mentioned in the docs, but the parsing should be fixed (tests for n*).

Changed 5 years ago by etourigny

Attachment: warp-nodata3.txt added

comment:6 Changed 5 years ago by etourigny

attached new patch which updates docs and fixes nodata parsing

comment:7 Changed 5 years ago by Even Rouault

The printf( "Copying nodata values from source %s to destination %s.\n" should be conditionalized by if (!bQuiet )

comment:8 Changed 5 years ago by etourigny

Resolution: fixed
Status: newclosed

ok thanks for your suggestions

applied in trunk (r26009)

comment:9 Changed 4 years ago by Even Rouault

Milestone: 2.01.11.0

comment:10 Changed 3 years ago by Even Rouault

"-dstnodata none" was kind of broken. Fixed by #5915

Note: See TracTickets for help on using tickets.