因为想要在Spyder中直接调用GRASS的Python包,实现在外部的IDE中运行GRASS,直接在Spyder中输入官网给出的实现代码,根据实际情况更改gisdb,grassbin目录等:
import os
import sys
import subprocess
#定义GRASS数据库
#添加自己的grassdb数据库路径
gisdb = os.path.join(os.path.expanduser("~"), "grassdata")
# the following path is the default path on MS Windows
# gisdb = os.path.join(os.path.expanduser("~"), "Documents/grassdata")
#指定现有location和mapset
location = "nc_spm_08"
mapset = "user1"
#指定GRASS的启动文件
grass7bin = 'grass78'
if sys.platform.startswith('win'):
# MS Windows
grass7bin = r'C:Program FilesGRASS GIS 7.8grass78.bat'
# uncomment when using standalone WinGRASS installer
# grass7bin = r'C:Program Files (x86)GRASS GIS 7.8.0grass78.bat'
# this can be avoided if GRASS executable is added to PATH
elif sys.platform == 'darwin':
# Mac OS X
# TODO: this have to be checked, maybe unix way is good enough
grass7bin = '/Applications/GRASS/GRASS-7.8.app/'
# query GRASS GIS itself for its GISBASE
startcmd = [grass7bin, '--config', 'path']