-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reusable python scripts (now gdal_calc.py) #121
Conversation
… clean way commit 4b6a415 (30-01-2015) removed it in a cleanup (accidentally), so for examle 'log10(A)' didn't work (in gdal 2.0/2.1)
Some other points: - raise exceptions on errors - --quiet option to suppress progress messages
7ab2481
to
9c2af60
Compare
Would be good if autotest/pyscripts/test_gdal_calc.py could be enhanced to demonstrate the bug fix for functions in expressions, and the use of gdal_calc.Calc() |
Old default was confusing and could easily be used accidentally
For numpy functions and new python interface
Ok, added tests. Also while testing found that the default Float32 NoDataValue can be very confusing, so changed that to the more standard maximum float Any ideas about including the Calc() funtion in the osgeo.gdal namespace? |
…gain, now in a clean way, to fix 2.0 regression that made for examle 'log10(A)' to no longer work (patch by Piers Titus van der Torren, OSGeo/gdal#121) git-svn-id: https://svn.osgeo.org/gdal/trunk/gdal@34034 f0d54148-0727-0410-94bb-9a71ac55c965
trunk r34034, branches/2.1 r34035, branches/2.0 r34036 "gdal_calc.py: Add * from gdalnumeric to gdal_calc.py eval namespace again, now in a clean way, to fix 2.0 regression that made for examle 'log10(A)' to no longer work (patch by Piers Titus van der Torren, #121)" trunk r34037 "gdal_calc.py: Add function to gdal_calc.py to make it callable from python (gdal_calc.Calc()), raise exceptions on errors, --quiet option to suppress progress messages, change default Float32 NoDataValue to more standard 3.402823466E+38 (patch by Piers Titus van der Torren, #121)" Not sure about how/f including Calc() into osgeo.gdal. Perhaps should be raised on gdal-dev mailing list |
…ython (gdal_calc.Calc()), raise exceptions on errors, --quiet option to suppress progress messages, change default Float32 NoDataValue to more standard 3.402823466E+38 (patch by Piers Titus van der Torren, OSGeo/gdal#121) git-svn-id: https://svn.osgeo.org/gdal/trunk/gdal@34037 f0d54148-0727-0410-94bb-9a71ac55c965
How transform a gdal_calc.py command line to gdal_calc.calc(). My command : I try : I have "Calc() got multiple values for argument 'calc'" Thanks |
@alavenant You should provide the filenames in a pythonic way too, and the calculation should be a string:
|
The same way as the GDAL utilities are made available as library (https://trac.osgeo.org/gdal/wiki/rfc59.1_utilities_as_a_library) it would be nice have the python utilities also available for calling directly from python. Judging from Stack Exchange there is quite some interest in this possibility.
I now implemented an interface for gdal_calc.py, so it can be used from python for example as
import gdal_calc
gdal_calc.Calc("-log10(A)", outfile="output.tif", A="raster.tif", A_band=1)
This could be done for the other python utilities as well. For some (gdal_edit and gdal_pansharpen) there is already a very basic (not documented) interface which just takes the command line arguments, it would be nice to make them more pythonic too.
There are some open questions:
Furthermore I fixed a bug which came in in GDAL 2.0, namely that functions are not directly available for use in expressions anymore, so for example "log10(A)" fails. This is the first commit and should be merged to version 2.0 and 2.1 also.