当前位置: 首页 > 工具软件 > GRASS GIS > 使用案例 >

python同类函数调用_当python函数调用GRASS GIS模块和另一个同类python函数时出错

澹台新知
2023-12-01

我编写了一个python函数a从外部调用GRASSGIS模块,它运行良好。我编写了另一个python函数B包含调用另一个GRASSGIS模块的语句和python函数A,出现了错误。在

功能A:import os

import sys

import numpy

from GRASSGIS_conn import GRASSGIS_conn

def v_edit(map_name, tool, thresh, coords):

cor = [",".join(item) for item in coords.astype(str)]

no_of_cors = len(cor)

i = 0

while i <= no_of_cors - 1:

g.run_command('v.edit', map = map_name, tool = tool, threshold = thresh, coords = cor[i])

i = i + 1

功能B:

^{pr2}$

错误:Traceback (most recent call last):

File "C:\Users\Heinz\Desktop\split_line.py", line 25, in

split_line(r'C:\Users\Heinz\Desktop\all.shp', 'tctest', '50', point_cor)

File "C:\Users\Heinz\Desktop\split_line.py", line 11, in split_line

v_edit(out_name, 'break', thresh, point_cor)

File "C:\Users\Heinz\Desktop\v_edit.py", line 13, in v_edit

g.run_command('v.edit', map = map_name, tool = tool, threshold = thresh, coords = cor[i])

NameError: global name 'g' is not defined

我已经测试了函数B没有语句调用函数A运行良好,没有错误。在

我不知道为什么会这样,也不知道怎么解决。在

 类似资料: