Hello GRASS-people!!

I face a problem when I try to run mapcalculator in a pyhton script.

I attached a sample test script which i tried on the subset of the spearfish 
data set (http://grass.fbk.eu/sampledata/north_carolina/nc_basic_spm.tar.gz)

I just tried to multiply geology * elevation (just to try, in reality this 
wouldn't make sense, I know) and a new map should be created...but I fail and 
nothing is created. But the script itself can be loaded and I get to the 
interactive menu to choose the maps I want to process.

Is the script working on your GRASS? what is wrong with the script syntax?

cheers
/johannes


-------- Original-Nachricht --------
> Datum: Fri, 25 Mar 2011 12:45:18 +0100
> Von: "Johannes Radinger" <jradin...@gmx.at>
> An: Nick Cahill <ndcah...@wisc.edu>, grass-user@lists.osgeo.org
> Betreff: Re: [GRASS-user] Running a Pyhton Script on Mac (Mapcalc)

> Thank you nick for the tipp with the line breaks!
> 
> I opend the script with text wrangler and there were indeed
> mac line endings. So I saved it with unix line endings and
> now it seems to work. Maybe GRASS should be able to handle 
> line endings from various platforms if that is possible...
> 
> Now I get the menu for setting input and output for the script
> after launching it...seems to work...anyway I have to play around
> because no output is created at the moment from my script...hmmm?
> 
> /johannes
> 
> 
> -------- Original-Nachricht --------
> > Datum: Wed, 23 Mar 2011 05:06:51 -0500
> > Von: Nick Cahill <ndcah...@wisc.edu>
> > An: GRASS user list <grass-user@lists.osgeo.org>
> > Betreff: Re: [GRASS-user] Running a Pyhton Script on Mac (Mapcalc)
> 
> > 
> > 
> > I haven't run python scripts from within GRASS, but have found that they
> > won't run if the line breaks are not unix line breaks, rather than Mac
> or
> > Windows - which you'll get if you write the script in some applications.
> > 
> > BBEdit is a very good editor on the Mac and will run python scripts
> within
> > the editor. I think there's a free version too - text wrangler. 
> > 
> > Nick Cahill
> > 
> > 
> > On Mar 23, 2011, at 2:29 AM, Johannes Radinger wrote:
> > 
> > > 
> > > Am 23.03.2011 um 05:22 schrieb Glynn Clements:
> > > 
> > >> 
> > >> Johannes Radinger wrote:
> > >> 
> > >>> I'd like to run a python script on my GRASS6.5 on MacOS.
> > >>> 
> > >>> I saved a *.py script for testing with following content on my
> > desktop:
> > >> 
> > >>> All the needed files (upstream_part, shreve) are existing in the
> > >>> location and mapset that is open. Then I tried to execute
> > >>> File-->Launch Script and choose it. Then I just get back:
> > >>> 
> > >>> Launching script '/Users/Johannes
> Radinger/Desktop/mapcalc-test.py'...
> >          
> > >>> (Tue Mar 22 10:57:15 2011)                                          
>  
> >          
> > >>> /Users/Johannes Radinger/Desktop/mapcalc-test.py                    
>  
> >          
> > >>> (Tue Mar 22 10:57:15 2011) Command finished (0 sec)
> > >>> 
> > >>> and nothing happend and no map was created...
> > >>> 
> > >>> what is wrong with my script?
> > >> 
> > >> Does the script have execute permission ("chmod +x ...")?
> > > 
> > > The script has execute permission so far as I think, but anyway I ran
> > chmod +x on the file...
> > > 
> > >> 
> > >> Does MacOSX have the Python interpreter at /usr/bin/python?
> > >> 
> > >> It's common practice for Python scripts to use:
> > >> 
> > >>  #!/usr/bin/env python
> > > 
> > > my first script included #!/usr/bin/env python, but it failed (error
> > message) it couldn't find python, thats why I googled  and found:
> > http://macosx.com/forums/unix-x11/46163-how-do-i-run-python-script.html
> > > that is why i used /usr/bin/python.
> > > 
> > > I just got the tip in forum to check for the line-endings in the file,
> > they might cause the problem, so I will check that.
> > > 
> > > But anyway, is there any other possible reason why I fail?
> > > Is there any Mac-User with Python-Script-Mapcalc experience?
> > > 
> > > 
> > >> 
> > >> which only requires that "python" is somewhere in $PATH, rather than
> > >> assuming a fixed location. The Python scripts in 7.0 use this
> > >> mechanism.
> > >> 
> > >> -- 
> > >> Glynn Clements <gl...@gclements.plus.com>
> > > 
> > > 
> > > _______________________________________________
> > > grass-user mailing list
> > > grass-user@lists.osgeo.org
> > > http://lists.osgeo.org/mailman/listinfo/grass-user
> > 
> > _______________________________________________
> > grass-user mailing list
> > grass-user@lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/grass-user
> 
> -- 
> NEU: FreePhone - kostenlos mobil telefonieren und surfen!                     
> Jetzt informieren: http://www.gmx.net/de/go/freephone
> _______________________________________________
> grass-user mailing list
> grass-user@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user

-- 
Ihr GMX Postfach immer dabei: die kostenlose GMX Mail App für Android.
Komfortabel, sicher und schnell: www.gmx.de/android
#!/usr/bin/env python
#
############################################################################
#
# MODULE:       Modell
#
# AUTHOR(S):	Johannes Radinger
#               
# PURPOSE:      
#
# DATE:         Tue Feb 01 14:00:50 2011
#
#############################################################################
#%Module
#% description: mapcalc test
#%End
#%option
#% key: newmap
#% type: string
#% gisprompt: new,cell,raster
#% description: output
#% required: yes
#%end
#%option
#% key: elevation
#% type: string
#% gisprompt: old,cell,raster
#% description: input 1
#% required: yes
#%end
#%option
#% key: geology
#% type: string
#% gisprompt: old,cell,raster
#% description: input 2
#% required: yes
#%end


import sys
import os

import grass.script as grass


def main():
    grass.mapcalc("${newmap} = ${elevation} * ${geology}",
                   newmap = options['newmap'],
                   elevation = options['elevation'],
                   geology = options['geology'])

if __name__ == "__main__":
    options, flags = grass.parser()
    main()



_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Reply via email to