Creating Python scripts that call GRASS functionality from outside

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating Python scripts that call GRASS functionality from outside

kabs1969
Hi all,

I just installed GRASS 6.4.3svn and Python 2.7.3 in Windows 7. I need to call GRASS functions from outside GRASS. I set the environment variables given
in the grasswiki except:
GISRC= C:\Documents and settings\user\.grassrc6

Because i cannot find this .grassrc6 in the given path or in any other path. However with other variables, i tried to use from grass.lib import grass in Python27 IDLE. Then it gives an error. I think the variables are not set correctly. Could somebody help me to sort this out?

Cheers, Brian.

_______________________________________________
grass-windows mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-windows
Reply | Threaded
Open this post in threaded view
|

Re: Creating Python scripts that call GRASS functionality from outside

Glynn Clements

Brian Sanjeewa Rupasinghe wrote:

> I just installed GRASS 6.4.3svn and Python 2.7.3 in Windows 7. I need to
> call GRASS functions from outside GRASS. I set the environment variables
> given
> in the grasswiki except:
> GISRC= C:\Documents and settings\user\.grassrc6
>
> Because i cannot find this .grassrc6 in the given path or in any other
> path.

A suitable should be created the first time you run GRASS.
Alternatively, you can create the file yourself, e.g.:

GISDBASE: /opt/grass-data
LOCATION_NAME: spearfish57
MAPSET: user1
GRASS_DB_ENCODING: ascii

> However with other variables, i tried to use from grass.lib
> importgrass in Python27 IDLE. Then it gives an error. I think the
> variables are
> not set correctly. Could somebody help me to sort this out?

If GISRC doesn't refer to a valid settings file, nothing will work.

--
Glynn Clements <[hidden email]>
_______________________________________________
grass-windows mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-windows
Reply | Threaded
Open this post in threaded view
|

Re: Creating Python scripts that call GRASS functionality from outside

kabs1969
Could you explain bit more. You mean without .grasssrc6, it will not work. I created a new location and mapset as you instructed. But where to find GRASS_DB_ENCODING: ascii in WinGRASS? 

On Fri, Dec 21, 2012 at 1:30 PM, Glynn Clements <[hidden email]> wrote:

Brian Sanjeewa Rupasinghe wrote:

> I just installed GRASS 6.4.3svn and Python 2.7.3 in Windows 7. I need to
> call GRASS functions from outside GRASS. I set the environment variables
> given
> in the grasswiki except:
> GISRC= C:\Documents and settings\user\.grassrc6
>
> Because i cannot find this .grassrc6 in the given path or in any other
> path.

A suitable should be created the first time you run GRASS.
Alternatively, you can create the file yourself, e.g.:

GISDBASE: /opt/grass-data
LOCATION_NAME: spearfish57
MAPSET: user1
GRASS_DB_ENCODING: ascii

> However with other variables, i tried to use from grass.lib
> importgrass in Python27 IDLE. Then it gives an error. I think the
> variables are
> not set correctly. Could somebody help me to sort this out?

If GISRC doesn't refer to a valid settings file, nothing will work.

--
Glynn Clements <[hidden email]>


_______________________________________________
grass-windows mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-windows
Reply | Threaded
Open this post in threaded view
|

Re: Creating Python scripts that call GRASS functionality from outside

kabs1969
I uninstalled GRASS and then re-installed with spearfish data set with its spearfish60 location and user1 mapset. Still i cannot see .grassrc6 file created. Any idea? Please not i use Grass for Windows 7.

On Fri, Dec 21, 2012 at 5:21 PM, Brian Sanjeewa Rupasinghe <[hidden email]> wrote:
Could you explain bit more. You mean without .grasssrc6, it will not work. I created a new location and mapset as you instructed. But where to find GRASS_DB_ENCODING: ascii in WinGRASS? 


On Fri, Dec 21, 2012 at 1:30 PM, Glynn Clements <[hidden email]> wrote:

Brian Sanjeewa Rupasinghe wrote:

> I just installed GRASS 6.4.3svn and Python 2.7.3 in Windows 7. I need to
> call GRASS functions from outside GRASS. I set the environment variables
> given
> in the grasswiki except:
> GISRC= C:\Documents and settings\user\.grassrc6
>
> Because i cannot find this .grassrc6 in the given path or in any other
> path.

A suitable should be created the first time you run GRASS.
Alternatively, you can create the file yourself, e.g.:

GISDBASE: /opt/grass-data
LOCATION_NAME: spearfish57
MAPSET: user1
GRASS_DB_ENCODING: ascii

> However with other variables, i tried to use from grass.lib
> importgrass in Python27 IDLE. Then it gives an error. I think the
> variables are
> not set correctly. Could somebody help me to sort this out?

If GISRC doesn't refer to a valid settings file, nothing will work.

--
Glynn Clements <[hidden email]>



_______________________________________________
grass-windows mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-windows
Reply | Threaded
Open this post in threaded view
|

Re: Creating Python scripts that call GRASS functionality from outside (UNCLASSIFIED)

kabs1969
I checked the file but it is not available in drive C: However, GRASS works.

On Fri, Dec 21, 2012 at 7:57 PM, Gade, David SWT <[hidden email]> wrote:
'.grassrc6'


_______________________________________________
grass-windows mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-windows
Reply | Threaded
Open this post in threaded view
|

Re: Creating Python scripts that call GRASS functionality from outside (UNCLASSIFIED)

Glynn Clements

Brian Sanjeewa Rupasinghe wrote:

> I checked the file but it is not available in drive C: However, GRASS works.
>
> On Fri, Dec 21, 2012 at 7:57 PM, Gade, David SWT
> <[hidden email]>wrote:
>
> > '.grassrc6'

The normal location for GRASS 6.x on Windows is:

        %APPDATA%\GRASS6\grassrc6

On Windows 7, a typical setting for %APPDATA% is

        C:\Users\<username>\AppData\Roaming

The file needs to contain settings for GISDBASE, LOCATION_NAME and
MAPSET. GRASS_DB_ENCODING may need to be set for vector modules.

--
Glynn Clements <[hidden email]>
_______________________________________________
grass-windows mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-windows
Reply | Threaded
Open this post in threaded view
|

Re: Creating Python scripts that call GRASS functionality from outside (UNCLASSIFIED)

kabs1969

Thanks. It is found in  C:\Users\<username>\AppData\Roaming. However the file name is grassrc6 and not .grassrc6.
Is it ok?


On Fri, Dec 21, 2012 at 9:40 PM, Glynn Clements <[hidden email]> wrote:
C:\Users\<username>\AppData\Roaming


_______________________________________________
grass-windows mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-windows
Reply | Threaded
Open this post in threaded view
|

Re: Creating Python scripts that call GRASS functionality from outside (UNCLASSIFIED)

Glynn Clements

Brian Sanjeewa Rupasinghe wrote:

> Thanks. It is found in  C:\Users\<username>\AppData\Roaming. However the
> file name is grassrc6 and not .grassrc6.
> Is it ok?

Yes.

It doesn't matter what the file is called, so long as %GISRC% points
to it and it contains the necessary settings.

--
Glynn Clements <[hidden email]>
_______________________________________________
grass-windows mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-windows
Reply | Threaded
Open this post in threaded view
|

Re: Creating Python scripts that call GRASS functionality from outside

Markus Neteler
In reply to this post by kabs1969
On Fri, Dec 21, 2012 at 8:51 PM, Brian Sanjeewa Rupasinghe
<[hidden email]> wrote:
> I uninstalled GRASS and then re-installed with spearfish data set with its
> spearfish60 location and user1 mapset. Still i cannot see .grassrc6 file
> created.

It is created during the first session *using* GRASS GIS.
So you  may enter into the Spearfish location, user1 mapset,
then leave GRASS and the file should be there.

Markus
_______________________________________________
grass-windows mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-windows
Reply | Threaded
Open this post in threaded view
|

Re: Creating Python scripts that call GRASS functionality from outside (UNCLASSIFIED)

kabs1969
In reply to this post by Glynn Clements
Hi,

Even if the GISRC environmental variable set, i cannot call GRASS libraries from Python 2.7 IDLE.
For example, when i import grass from grass.lib, it gives the following error in Python IDLE (GUI)

ImportError: No module named grass.lib

Here is the env.bat file i modified. Newly added lines are below rem #---

set GRASS_WISH=%GISBASE%\extrabin\wish.exe
set GRASS_PYTHON=python
set GRASS_PROJSHARE=%GISBASE%\proj
set GRASS_HTML_BROWSER=explorer
set GRASS_SH=%GISBASE%\msys\bin\sh.exe

set PYTHONHOME=%GISBASE%\Python27
set GDAL_DATA=%GISBASE%\share\gdal
set PROJ_LIB=%GISBASE%\proj
set GEOTIFF_CSV=%GISBASE%\share\epsg_csv

set PATH=%GISBASE%\msys\bin;%PATH%
set PATH=%GISBASE%\extrabin;%GISBASE%\extralib;%PATH%
set PATH=%GISBASE%\tcl-tk\bin;%GISBASE%\sqlite\bin;%GISBASE%\gpsbabel;%PATH%
set PATH=%GISBASE%\bin;%PATH%

rem #----

set PATH=%GISBASE%\lib;%PATH%
set PATH= %GISBASE%\etc;%PATH%
set PATH=%GISBASE%\etc\python;%PATH%
set PATH=C:\Python27;%PATH%

set GISRC= C:\Users\KABS\AppData\Roaming\GRASS6\grassrc6
set LD_LIBRARY_PATH = %GISBASE%\lib
set PYTHONLIB= C:\Python27
set PYTHONPATH= %GISBASE%\etc\python;%PYTHONPATH%


On Sat, Dec 22, 2012 at 3:58 PM, Brian Sanjeewa Rupasinghe <[hidden email]> wrote:
Many thanks. I got it.

On Sat, Dec 22, 2012 at 1:39 PM, Glynn Clements <[hidden email]> wrote:


Brian Sanjeewa Rupasinghe wrote:
.
> Thanks. It is found in  C:\Users\<username>\AppData\Roaming. However the
> file name is grassrc6 and not .grassrc6.
> Is it ok?

Yes.

It doesn't matter what the file is called, so long as %GISRC% points
to it and it contains the necessary settings.

--
Glynn Clements <[hidden email]>



_______________________________________________
grass-windows mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-windows