是否有 bash 脚本来安装 GRASS GIS 并在 Linux 机器中将其与 python 一起使用?
sudo apt update
sudo apt -y install grass-dev
export GRASSBIN=$(which grass)
pip install grass-session
curl https://sh.rustup.rs -sSf | sh -s -- -y
source "$HOME/.cargo/env"
pip install pygrass
# >>> from grass_session import Session
# >>> import grass
从 GRASS GIS 版本 8.4+ 开始,不再需要 pip 包,但现在提供内部 Python API。
示例:导入 GRASS GIS Python 绑定(需要 8.4+)并测试 r.in.pdal
export PYTHONPATH=$(grass --config python-path)
python
import grass.script as gs
import urllib.request
# download a small sample data file (LiDAR points)
urllib.request.urlretrieve(
"https://github.com/OSGeo/grass/raw/main/docker/testdata/simple.laz",
"/tmp/simple.laz",
)
# full path to new project
project = "/tmp/grassproject_epsg_25832"
gs.create_project(project, epsg="25832")
with gs.setup.init(project):
print("GRASS GIS session: tests for PROJ, GDAL, PDAL, GRASS GIS")
print(gs.parse_command("g.gisenv", flags="s"))
# simple test: scan the LAZ file for boundary extent
gs.run_command(
"r.in.pdal",
input="/tmp/simple.laz",
output="count_1",
method="n",
flags="g",
resolution=1,
overwrite=True,
)