选择 A,因为遇到 j continue跳过了
(严格来说这个程序有个错误,就是== 中间不能分开)
选A,
分析过程: continue 满足条件 i为 J 时,跳过打印的行为,最终只打印了BTU.
导入Python工具箱后,能够以arcpy.<工具名称>形式访问自定义工具
>>>arcpy.ImportToolbox(r"D:\制作GP工具\CommonTools.pyt")
>>>arcpy.Tool(r"D:\制作GP工具\data1706.csv","POINT_X","POINT_Y",r"D:\制作GP工具\scratch.gdb\test")
下述示例介绍如何在Python窗口使用Python工具箱中的工具
具体实现:
Python工具箱:
# -*- coding: utf-8 -*-
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "CSV转点"
self.description = "CSVToPoint"
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
in_table = arcpy.Parameter(
displayName="输入表",
name="输入表",
datatype="DEFile",
parameterType="Required",
direction="Input")
in_table.filter.list = ['csv']
x_coords = arcpy.Parameter(
displayName='x坐标',
name='x坐标',
datatype='Field',
parameterType='Required',
direction='Input')
x_coords.parameterDependencies = [in_table.name]
y_coords = arcpy.Parameter(
displayName='y坐标',
name='y坐标',
datatype='Field',
parameterType='Required',
direction='Input')
y_coords.parameterDependencies = [in_table.name]
outFC = arcpy.Parameter(
displayName='要素类',
name='要素类',
datatype='DEFeatureClass',
parameterType='Required',
direction='Output')
params = [in_table, x_coords, y_coords, outFC]
return params
def isLicensed(self):
return True
def updateParameters(self, parameters):
return
def updateMessages(self, parameters):
return
def execute(self, parameters, messages):
# Get tool parameters
in_table = parameters[0].valueAsText
arcpy.AddMessage("输入表 is {0}".format(in_table))
x_coords = parameters[1].valueAsText
arcpy.AddMessage("x坐标 is {0}".format(x_coords))
y_coords = parameters[2].valueAsText
arcpy.AddMessage("y坐标 is {0}".format(y_coords))
outFC = parameters[3].valueAsText
arcpy.AddMessage("要素类 is {0}".format(outFC))
idws = IDW(in_table, x_coords, y_coords, outFC)
idws.idwByFields()
return
class IDW(object):
def __init__(self, param1, param2, param3, param4):
self.param1 = param1 # 第一个参数
self.param2 = param2 # 第二个参数
self.param3 = param3 # 第三个参数
self.param4 = param4 # 第四个参数
def idwByFields(self):
arcpy.env.overwriteOutput = "true"
# Set the local variables
in_table = self.param1
out_feature_class = self.param4
x_coords = self.param2
y_coords = self.param3
z_coords = ""
# Make the XY event layer...
arcpy.management.XYTableToPoint(in_table, out_feature_class,
x_coords, y_coords, z_coords,
arcpy.SpatialReference(4326))
Python窗口使用Python工具箱:
第三方Python编辑器,例如:pycharm,也是可以这样调用Python工具箱中的工具
import arcpy
# Import custom toolbox
arcpy.ImportToolbox(r"D:\制作GP工具\CommonTools.pyt")
try:
# Run tool in the custom toolbox. The tool is identified by
# the tool name and the toolbox alias.
arcpy.Tool(r"D:\制作GP工具\data1706.csv","POINT_X","POINT_Y",r"D:\制作GP工具\scratch.gdb\test11222")
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
其中arcpy.Tool中的这个“Tool”是Python工具箱某个工具的名称,对应Python工具箱代码部分的self.tools = [Tool]中的这个“Tool”。
参考资料:
https://pro.arcgis.com/zh-cn/pro-app/arcpy/functions/importtoolbox.htm