[Qgis-user] Writing Python loop for Raster calculator

Rainer M Krug r.m.krug at gmail.com
Fri Apr 6 03:10:43 PDT 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/04/12 11:27, Swapnil Chaudhari wrote:
> Hi Nathan,
> 
> Thanks for your response. In fact I was reading your blog yesterday itself. gdal_calc.py may be
> of my help. I will explore that option.
> 
> I would be happy to receive a little more elaboration on how to write shell script for
> automating this calculation for entire directory? I am aware that you have already written it
> in on your blog at DEM generation. However, if you can suggest how to write shell script
> specific to once need would be really great.

in a shell you can use the for construct to iterate through all files in a directory:


for FILE in *.asc
do
  echo $FILE
done



and in the loop you can do whatever you want.

Cheers,

Rainer


> 
> Thanks a ton!
> 
> Swapnil o__ _> /__ (_) \(_)....... live healthy
> 
> 
> 
> On Fri, Apr 6, 2012 at 12:58 PM, Nathan Woodrow <madmanwoo at gmail.com
> <mailto:madmanwoo at gmail.com>> wrote:
> 
> You can try gdal_calc.py
> 
> http://smathermather.wordpress.com/2011/12/01/gdal_calc-py-raster-calculator-using-numby-functions/
>
>  - Nathan
> 
> On Fri, Apr 6, 2012 at 4:35 PM, Swapnil Chaudhari <swapsslan at gmail.com 
> <mailto:swapsslan at gmail.com>> wrote:
> 
> Dear QGIS User Team,
> 
> I have sets of grid files, corresponding to monthly mean temperature for few years.
> 
> I am working on scaling the raw data and modifying the extent of output file from 
> -180,180,-90,90 to -180,180,-60, 90.
> 
> The process of doing this with Raster Calculator is straight and very simple, where you have to
> give raster calculation expression, output extent and name of output with its format. The
> scaling equation for doing so e.g. is, (cru_tmp_clim_1961-1970 <tel:1961-1970>_05 at 1*0.51)-85
> 
> Although very simple, its very time consuming since I have data for around 6 to 7 dacads.
> 
> I would be very glad if some one can help me find the python script for doing this in loop. So
> that I can process whole directory in single go.
> 
> In addition to that, I would also request you to inform mannaul, guide to learn python 
> scripting for simple raster and vector operations.
> 
> You efforts in helping with this is much appreciated.
> 
> Thank you very much.
> 
> Best,
> 
> Swapnil o__ _> /__ (_) \(_)....... live healthy
> 
> 
> _______________________________________________ Qgis-user mailing list 
> Qgis-user at lists.osgeo.org <mailto:Qgis-user at lists.osgeo.org> 
> http://lists.osgeo.org/mailman/listinfo/qgis-user
> 
> 
> 
> 
> 
> _______________________________________________ Qgis-user mailing list 
> Qgis-user at lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-user


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys.
(Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer at krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9+wSMACgkQoYgNqgF2egq9YACgjL6qD4PkTzR/2cd7tzEyJHxw
kaYAoIedcXvZ2V1Wo9doUcV48qHQ4oMU
=cSSv
-----END PGP SIGNATURE-----



More information about the Qgis-user mailing list