Opened 11 years ago

Closed 11 years ago

Last modified 9 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 11 years ago.
warp-nodata2.txt (4.9 KB ) - added by etourigny 11 years ago.
warp-nodata3.txt (6.1 KB ) - added by etourigny 11 years ago.

Download all attachments as: .zip

Change History (13)

by etourigny, 11 years ago

Attachment: warp-nodata.txt added

comment:1 by Even Rouault, 11 years ago

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

in reply to:  1 ; comment:2 by etourigny, 11 years ago

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

in reply to:  2 comment:3 by Even Rouault, 11 years ago

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.

by etourigny, 11 years ago

Attachment: warp-nodata2.txt added

comment:4 by etourigny, 11 years ago

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 by etourigny, 11 years ago

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

by etourigny, 11 years ago

Attachment: warp-nodata3.txt added

comment:6 by etourigny, 11 years ago

attached new patch which updates docs and fixes nodata parsing

comment:7 by Even Rouault, 11 years ago

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

comment:8 by etourigny, 11 years ago

Resolution: fixed
Status: newclosed

ok thanks for your suggestions

applied in trunk (r26009)

comment:9 by Even Rouault, 10 years ago

Milestone: 2.01.11.0

comment:10 by Even Rouault, 9 years ago

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

Note: See TracTickets for help on using tickets.