在python中调用grass的模块

来源:互联网 发布:关于网络直播的作文800 编辑:程序博客网 时间:2024/05/22 17:37

在安装好grass之后,只需设置如下的环境变量,便可在python中调用grass中的模块功能:

GISBASE= D:\Program Files (x86)\GRASS GIS 7.0.svnPATH=%GISBASE%\etc;%GISBASE%\etc\python;%GISBASE%\lib;%GISBASE%\bin;%GISBASE%\extrabin;C:\Python27\ArcGIS10.1;%GISBASE%\scripts;%GISBASE%\msys\bin;%GISBASE%\Python27\libLD_LIBRARY_PATH= %GISBASE%\libPYTHONPATH= %GISBASE%\etc\pythonPYTHONLIB= C:\Python27\ArcGIS10.1GRASS_SH= %GISBASE%\msys\bin\sh.exe

示例Python程序如下:

import sysimport osimport grass.script as grasskk = r"E:\Exercise\test\grasstest\dem2.tif"r = grass.run_command('r.in.gdal',                  flags='o',                  input=kk,                  output="mm",                  overwrite=True)print rr = grass.run_command("g.region", rast="mm")print r

但是我们需要注意的几个问题:

  1. 目前grass官网上能下载的最新版本的wingrass(Stand-alone Installer) 版本为7.0.4,https://grass.osgeo.org/download/software/ms-windows/,但是安装之后安装目录下没有文件夹msys,因此环境变量中凡是与msys有关的无法进行设置。本文的解决办法是下载一个旧版本的grass即可,我用的是WinGRASS-7.0.svn版。
  2. 有时候在安装旧版本的grass(指的是7.0.3之前的版本)后,启动时会报错。如下图:

第一幅图是启动grass时报错 unable to get current geographic extent. Force quiting wxGUI.,然后根据提示在grass的cmd中运行命令g.region,又报错:g.region.exe无法找到入口,无法定位程序输入点sqlite3_prepare_v2于动态链接库sqlite3.dll上。此时的解决办法是

The issue is caused by different sqlite3.dll files accessible “on path” to all application. In case of GRASS GIS, some incompatible sqlite3 DLL is picked up by the system rather than using the correct one shipped with GRASS GIS.

Solution: search for all sqlite3.dll files on your computer and remove rename them one by one while trying at the same time to start GRASS GIS successfully. Note that removing some of the other sqlite3.dll files may break the applications which use them (say, while this is possible it has never actually been reported by any user). So, it is a good idea to just rename the DLL file in case you discover that another application needs that particular sqlite3 DLL and you have to reverse the process.

0 0
原创粉丝点击