ArcGIS 10.5 python 脚本集成到 'script/tool' 不输出数据
ArcGIS 10.5 python script integration to 'script/tool' not outputting data
在 ArcGIS 10.5
我有一个 python 脚本在 python window 中运行良好,但是,我试图将它集成到一个工具中,主要是为了对输入和输出文件 names/paths 使用 arcpy.GetParametersAsText()
输入功能。
该脚本的基本意图是将来自特定功能的一些属性字段 class 输出为非常特定的文本文件的非常特定的格式(如果有人知道,WinFrog 的 .PTS 调查线文件它)。
最初,尝试 .write()
使用 .open()
创建的文件对象时由于 Unicode 错误而失败。正如您在下面看到的,我尝试了很多方法来确保文件对象 'outfile' 确实是一个常规文件对象,而不是 Unicode,它仅由字符串中的路径定义。
无论如何,现在脚本将 运行 并完成 'successfully',在 tool/script 输入指示的目录中创建文件。但是现在它没有填充任何数据!同样,每次从 python window 运行ning 时脚本都有效
任何帮助都是极好的。完全理解这是用户错误,我可能忽略了一些简单的事情。
以下脚本,对任何显示问题深表歉意,Stack Overflow 的新手。
import arcp
fcpath = str(arcpy.GetParameterAsText(0))
fc = "r\"" + fcpath + "\""
fields = ["LineName", "Lat_SOL" , "Lon_SOL", "Lat_EOL", "Lon_EOL", "Northing_SOL", "Easting_SOL", "Northing_EOL", "Easting_EOL", "Shape_Length"]
filelocation = str(arcpy.GetParameterAsText(1))
outfile = open("r\"" + filelocation + ".PTS", 'w')
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
r1 = ("0,{0},0,0.000,0.000,1,2,65280,0,0.200,0,0,1.000,1,0\n".format(row[0]))
r2 = ("1,{0},{1},0.0m,0.0m,{2},{3},0.000\n".format(row[1], row[2], row[5], row[6]))
r3 = ("1,{0},{1},0.0m,0.0m,{2},{3},{4}\n".format(row[3], row[4], row[7], row[8], row[9]))
outfile.write(r1 + r2 + r3)
在您的工具箱参数中,将参数 0 数据类型设置为 FeatureClass
,将参数 1 设置为 File
。两者都必须是输入。
import arcpy
fcpath = arcpy.GetParameterAsText(0)
fields = ["LineName", "Lat_SOL" , "Lon_SOL", "Lat_EOL", "Lon_EOL", "Northing_SOL", "Easting_SOL", "Northing_EOL", "Easting_EOL", "Shape_Length"]
filelocation = arcpy.GetParameterAsText(1)
outfile = open(filelocation, 'w')
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
r1 = ("0,{0},0,0.000,0.000,1,2,65280,0,0.200,0,0,1.000,1,0\n".format(row[0]))
r2 = ("1,{0},{1},0.0m,0.0m,{2},{3},0.000\n".format(row[1], row[2], row[5], row[6]))
r3 = ("1,{0},{1},0.0m,0.0m,{2},{3},{4}\n".format(row[3], row[4], row[7], row[8], row[9]))
outfile.write(r1 + r2 + r3)
在 ArcGIS 10.5
我有一个 python 脚本在 python window 中运行良好,但是,我试图将它集成到一个工具中,主要是为了对输入和输出文件 names/paths 使用 arcpy.GetParametersAsText()
输入功能。
该脚本的基本意图是将来自特定功能的一些属性字段 class 输出为非常特定的文本文件的非常特定的格式(如果有人知道,WinFrog 的 .PTS 调查线文件它)。
最初,尝试 .write()
使用 .open()
创建的文件对象时由于 Unicode 错误而失败。正如您在下面看到的,我尝试了很多方法来确保文件对象 'outfile' 确实是一个常规文件对象,而不是 Unicode,它仅由字符串中的路径定义。
无论如何,现在脚本将 运行 并完成 'successfully',在 tool/script 输入指示的目录中创建文件。但是现在它没有填充任何数据!同样,每次从 python window 运行ning 时脚本都有效 任何帮助都是极好的。完全理解这是用户错误,我可能忽略了一些简单的事情。
以下脚本,对任何显示问题深表歉意,Stack Overflow 的新手。
import arcp
fcpath = str(arcpy.GetParameterAsText(0))
fc = "r\"" + fcpath + "\""
fields = ["LineName", "Lat_SOL" , "Lon_SOL", "Lat_EOL", "Lon_EOL", "Northing_SOL", "Easting_SOL", "Northing_EOL", "Easting_EOL", "Shape_Length"]
filelocation = str(arcpy.GetParameterAsText(1))
outfile = open("r\"" + filelocation + ".PTS", 'w')
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
r1 = ("0,{0},0,0.000,0.000,1,2,65280,0,0.200,0,0,1.000,1,0\n".format(row[0]))
r2 = ("1,{0},{1},0.0m,0.0m,{2},{3},0.000\n".format(row[1], row[2], row[5], row[6]))
r3 = ("1,{0},{1},0.0m,0.0m,{2},{3},{4}\n".format(row[3], row[4], row[7], row[8], row[9]))
outfile.write(r1 + r2 + r3)
在您的工具箱参数中,将参数 0 数据类型设置为 FeatureClass
,将参数 1 设置为 File
。两者都必须是输入。
import arcpy
fcpath = arcpy.GetParameterAsText(0)
fields = ["LineName", "Lat_SOL" , "Lon_SOL", "Lat_EOL", "Lon_EOL", "Northing_SOL", "Easting_SOL", "Northing_EOL", "Easting_EOL", "Shape_Length"]
filelocation = arcpy.GetParameterAsText(1)
outfile = open(filelocation, 'w')
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
r1 = ("0,{0},0,0.000,0.000,1,2,65280,0,0.200,0,0,1.000,1,0\n".format(row[0]))
r2 = ("1,{0},{1},0.0m,0.0m,{2},{3},0.000\n".format(row[1], row[2], row[5], row[6]))
r3 = ("1,{0},{1},0.0m,0.0m,{2},{3},{4}\n".format(row[3], row[4], row[7], row[8], row[9]))
outfile.write(r1 + r2 + r3)