GRASS and Java: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
m (+cats)
No edit summary
Line 15: Line 15:
==== Examples ====
==== Examples ====


It seems that calling grass in java by using java.Lang.Runtime.exec() can be implemented easily in Linux platform(Tests in Ubuntu 9.10 passed yet).
First install the grass use the apt-get:
sudo apt-get install grass  //it will install the latest stable version
After the installation completed you can:
1)Test it in the terminal without java(make sure that you have the GisDataBase installed,,):
open a terminal and enter:
grass or grass64 or grass63 -text, the following the instruction in the screen.
2)Test using grass command directly in the terminal:
#set the environment // the grass is installed under /usr/lib/grass64.
export GISBASE=/usr/lib/grass64
export GISRC=/home/kk/gisrc
export ldLibraryPath=$GISBASE/lib
export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
Then try the grass command directly, for example:
g.version
g.gisenv
........
3)Easily call grass in java if the test 2 passed.
Just use the Runtime.getRuntime.exec(String cmd,String[] env):
String cmd="g.version";
String[] exe = { "bash", "-c", cmd };
String[] env={"GISBASE=..","GISRC="".......}; the environment variables which you used in the
Process p=Runtime.getRuntime.exec(exe,env);
//FIXME for the format.
TODO
TODO



Revision as of 01:56, 8 March 2010

ADD MORE PLEASE

Define:

       public String run(String[] cmd)  {
       ...
                       Process p1=rt.exec(cmd, env);

and use:

       gm.run({"r.info", "map=roads"});

Examples

It seems that calling grass in java by using java.Lang.Runtime.exec() can be implemented easily in Linux platform(Tests in Ubuntu 9.10 passed yet).

First install the grass use the apt-get: sudo apt-get install grass //it will install the latest stable version After the installation completed you can: 1)Test it in the terminal without java(make sure that you have the GisDataBase installed,,): open a terminal and enter: grass or grass64 or grass63 -text, the following the instruction in the screen.

2)Test using grass command directly in the terminal:

  1. set the environment // the grass is installed under /usr/lib/grass64.

export GISBASE=/usr/lib/grass64 export GISRC=/home/kk/gisrc export ldLibraryPath=$GISBASE/lib export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts

Then try the grass command directly, for example: g.version g.gisenv ........


3)Easily call grass in java if the test 2 passed. Just use the Runtime.getRuntime.exec(String cmd,String[] env): String cmd="g.version"; String[] exe = { "bash", "-c", cmd }; String[] env={"GISBASE=..","GISRC="".......}; the environment variables which you used in the Process p=Runtime.getRuntime.exec(exe,env);

//FIXME for the format. TODO