Opened 7 years ago

Closed 3 years ago

#5548 closed enhancement (wontfix)

[FEATURE] add --asarray option to gdal_calc.py, which will enable it to handle more than 26 input files and simplify its usage

Reported by: xg1990 Owned by: warmerdam
Priority: normal Milestone: closed_because_of_github_migration
Component: Utilities Version: unspecified
Severity: normal Keywords: gdal
Cc:

Description

When the option --asarray is toggled, value of the input files will be stored in a list named A like this:

[

[ value_of_Dataset1_Band1, value_of_Dataset1_Band2, ..., ]

[ value_of_Dataset2_Band1, value_of_Dataset2_Band2, ..., ]

....

[ value_of_Datasetn_Band1, value_of_Datasetn_Band2, ..., ]

]

Besides, all the trailing arguments will be treated as input files. And the alpha list is not necessary any more.

For example, user can calculate the maximum of the 1st band of all the TIFF files in some folder by:

gdal_calc.py --asarray --calc="numpy.max([a[0] for a in A])" ./some_folder/*.tif

or calculate the average of all the bands by:

gdal_calc.py --asarray  --calc="sum([sum(a) for a in A]) / sum([len(a) for a in A])" ./some_folder/*.tif

Simple operation such as addition is also possible:

gdal_calc.py --asarray --calc="A[0][0] + A[1][0]"  F1.tif F2.tif

Most importantly, many numpy functions can be useful now.

Attachments (2)

gdal_calc.py.patch (7.1 KB) - added by xg1990 7 years ago.
gdal_calc.py (16.2 KB) - added by xg1990 7 years ago.
This is the modified file

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by xg1990

Attachment: gdal_calc.py.patch added

Changed 7 years ago by xg1990

Attachment: gdal_calc.py added

This is the modified file

comment:1 Changed 7 years ago by Even Rouault

Cc: etourigny added

It would also be necessary to enhance swig/python/scripts/gdal_calc.dox and autotest/pyscripts/test_gdal_calc.py

comment:2 Changed 7 years ago by etourigny

Cc: etourigny removed

sorry Even I don't have time to look into this, in fact I will be unavailable for a pretty long time.

comment:3 in reply to:  1 Changed 7 years ago by xg1990

Replying to rouault:

It would also be necessary to enhance swig/python/scripts/gdal_calc.dox and autotest/pyscripts/test_gdal_calc.py

Maybe I can help. But I'm not sure what to do with them.

comment:4 Changed 6 years ago by Jukka Rahkonen

Related discussion in the gdal-dev list: http://thread.gmane.org/gmane.comp.gis.gdal.devel/40781

comment:5 Changed 3 years ago by Even Rouault

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: newclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub?. If you believe this ticket is still valid, you may file it to https://github.com/OSGeo/gdal/issues if it is not already reported there.

Note: See TracTickets for help on using tickets.