Ticket #4064 (new enhancement)

Opened 4 years ago

Last modified 4 years ago

New option for gdal_calc.py

Reported by: CYesson Owned by: warmerdam
Priority: low Milestone:
Component: default Version: unspecified
Severity: minor Keywords:
Cc: hobu.inc@…

Description

I have implemented a new option to gdal_calc.py to deal with a specific request about processing layers of different data types.

The old version performs calculations using the native data type of the original input layers, which can be problematic if, say, you are dividing two integers and expect a float output.

The new feature --CalcAsDT will convert the input data to the output data type prior to calculation and thus bypass the above problem. I have not implemented this as the default option because of the potential hit to performance for larger files.

I have attached the new version of gdal_calc.py and a diff from the previous version

- Chris Yesson

Attachments

gdal_calc.py Download (12.6 KB) - added by CYesson 4 years ago.
New version of gdal_calc.py with new option
gdal_calc.diff Download (1.2 KB) - added by CYesson 4 years ago.
diff of old gdal_calc.py and new version
gdal_calc.2.py Download (12.5 KB) - added by CYesson 4 years ago.
gdal_calc.py with working type option as --wt and other options changed for consistency (--ot and --of)

Change History

Changed 4 years ago by CYesson

New version of gdal_calc.py with new option

Changed 4 years ago by CYesson

diff of old gdal_calc.py and new version

Changed 4 years ago by rouault

For consistency with other utilities, I would instead suggest -ot (output type) for the name of the option, like in gdal_translate or gdalwarp, if that type is the type of the output file. If it is just an indermediate working type, -wt (working type) could be more appropriate (like in gdalwarp).

Changed 4 years ago by CYesson

gdal_calc.py with working type option as --wt and other options changed for consistency (--ot and --of)

Changed 4 years ago by CYesson

Thanks for the comment.

I have implemented the notation changes mentioned above for greater consistency with other gdal tools. I have used --wt for working data type and --of for format and --ot for output data type. Note that the optparse package used by gdal_calc to handle options does not accept 2 character options with the single dash "-" notation.

I have uploaded a new version of gdal_calc with these options.

Changed 4 years ago by warmerdam

In terms of consistency it is not helpful to use --ot, --of and --wt instead of -ot, -of and -wt. I would suggest dispatching with optparse and doing the option processing more conventionally.

Note: See TracTickets for help on using tickets.