Arcpy脚本不断给出错误“TypeError:预期的字符串或byteslike对象”

2024-10-03 19:28:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我对arcpy和大部分python都是新手。我的新组织有arcpy脚本(由前员工编写),可以将选项卡文件转换为shp,并在shp中创建缓冲区。在我们将ArcGIS Pro升级到2.8.3之前,它一直工作得很好。有了python的基本技能,我将调试这个脚本。 这是我们正在使用的脚本-

#Import libraries
import geopandas as gpd

#Set directory as the same path as where this file is saved/pasted
abspath=os.path.abspath
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)

#Create a subfolder within the directory, folder called siteboundary
ProjectFolder=dname


#Locate the tab file and set as variable
#The script is locating a file that ends with "Site Boundary.TAB"
files=os.listdir(ProjectFolder)
Tabfile=[i for i in files if i.endswith('Site Boundary.TAB')]
def listToString(s): 
    
    # initialize an empty string
    str1 = " " 
    
    # return string  
    return (str1.join(s))
TabfilePath=ProjectFolder+'\\'+listToString(Tabfile)



#This creates the site boundary shapefile
Tabdata=gpd.read_file(TabfilePath,driver="MapInfo File")
ShapefilePath=ProjectFolder+r"\siteboundary.shp"
Tabdata.to_file(ShapefilePath)


#This creates the site's multiring buffer

#set arcpy environment
arcpyenv=ProjectFolder

#Allow arcpy to overwrite
arcpy.env.workspace=arcpyenv
arcpy.env.overwrite=True
arcpy.env.overwriteOutput = True

#Set multi ring buffer parameters 
distances=[200,500,1000,2000]
bufferunit="meters"
arcpy.analysis.MultipleRingBuffer('siteboundary.shp','sitebuffer.shp',distances,bufferunit,"distance","NONE")


#Print end message when done
arcpy.AddMessage("Conversion done,your file is located in"+arcpyenv)
print("Conversion done,your file is located in "+arcpyenv)'```

Here's the image of the error

我们在所有的PC和脚本(json到shp和缓冲区,以及缓冲区创建脚本)中都会遇到相同的错误。 我们使用脚本来半自动化流程,因为我们一天要做很多事情

我试图从其他来源的解决方案中解决这个问题,但没有一个是相关的。 有关更多详细信息,在更新ArcGIS Pro之后,我不得不克隆环境以运行脚本,我假设那里可能发生了一些事情,但当我检查安装的库时,它同时具有运行这些脚本所必需的arcpy 2.8和geopandas 0.8.1

另一件事是,脚本只在一个系统中运行,其中ArcGIS未更新,并且在机器的主配置文件中运行,而其他系统则不运行


Tags: thepath脚本isosasfile缓冲区
1条回答
网友
1楼 · 发布于 2024-10-03 19:28:08

我发现在ArcGIS Pro Python包管理中以及通过anaconda提示符安装geopandas时存在问题。因此,我在esrihttps://support.esri.com/en/technical-article/000024177上找到了这个解决方法。您可以通过Python命令提示符使用以下命令行conda install geopandas libtiff=4.0.10安装geopandas。 但这样一来,ArcGIS Pro中的笔记本将无法工作。 因此,必须在相同的python命令提示符下执行此命令 conda install -c anaconda jupyter_client=5.3.1

在克隆环境中运行这两个代码解决了所有问题

相关问题 更多 >