Python 工具箱的缓冲区参数

问题描述 投票:0回答:1

我正在尝试为 ArcGIS 创建一个缓冲工具 python 脚本。我的输入、输出和缓冲距离参数工作正常。但是,我无法使方法参数起作用。我想选择 PLANAR 或 GEODESIC。

我的代码:

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 = "My_Buffer"
        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 = "Tool"
        self.description = "Tool creates a buffer"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        # First parameter
        param0 = arcpy.Parameter(
            displayName = "Input Feature Class",
            name = "in_features",
            datatype = "GPFeatureLayer",
            parameterType = "Required",
            direction = "Input")
        
        # Second parameter
        param1 = arcpy.Parameter(
            displayName = "Output Feature Class",
            name = "out_features",
            datatype = "GPFeatureLayer",
            parameterType = "Required",
            direction = "Output")
        
        # Third parameter
        param2 = arcpy.Parameter(
            displayName = "Buffer Distance",
            name = "bf_distance",
            datatype = "GPLinearUnit",
            parameterType = "Required",
            direction = "Input")
        param2.parameterDependencies = [param0.name]
        
        # Fourth parameter
        param3 = arcpy.Parameter(
            displayName = "Method",
            name = "bf_method",
            datatype = "GPString",
            parameterType = "Optional",
            direction = "Input")
        
        param3.filter.type = "Value List"
        param3.filter.list = ["PLANAR", "GEODESIC"]
        
        param3.parameterDependencies = [param0.name]
        
        
        # List of parameter
        params = [param0, param1, param2, param3]
        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        in_features = parameters[0].valueAsText
        out_features = parameters[1].valueAsText
        bf_distance = parameters[2].valueAsText
        bf_method = parameters[3].valueAsText
        
        arcpy.Buffer_analysis(in_features, out_features, bf_distance, bf_method)
        return

    def postExecute(self, parameters):
        """This method takes place after outputs are processed and
        added to the display."""
        return

我收到的错误信息是:

ERROR 000800: The value is not a member of Full | Left | Right.Failed to execute (Buffer).

不确定如何继续解决这个问题。

python parameters buffer arcgis arcpy
1个回答
0
投票

Buffer 工具在方法参数之前要求其他参数。因此,应该指定'method'关键字:

arcpy.Buffer_analysis(in_features, out_features, bf_distance, method=bf_method)
© www.soinside.com 2019 - 2024. All rights reserved.