(九)arcpy开发&arcpy开发中获取工具箱中的参数

52 篇文章 79 订阅
37 篇文章 17 订阅

平时制图中用到的arcgis工具箱,或多或少会有各种各样的参数。经常在arcpy的二次开发中会遇到参数的获取。比如之前写的这段代码中。

import arcpy

from OrderByID import excute


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 = "自动编号(测绘科技)"
        self.description = "自动编号(测绘科技)"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        shapePath = arcpy.Parameter(
            displayName="需要修改的shapefile数据",
            name="shapePath",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input"
        )

        params = [shapePath]
        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."""
        shapePath = parameters[0].valueAsText
        excute(shapePath)
        return

在execute方法中就有获取参数的时候,可以看得出,parameters是一个数组,而这个数组getParameterInfo函数相对应。

来看一下arcgis的帮助文档:

在 Python 工具箱中,工具的主要部分位于 execute 方法中。该部分负责各种分析、转换和数据创建。在 execute 方法中,可调用其他工具并访问 ArcPy、其他自定义功能或第三方 Python 功能。

execute 方法本身具有的参数可用于处理参数和消息,包括 parameter 对象列表和 messages 对象。

def execute(self, parameters, messages):

在 execute 方法中,可使用 valueAsText 方法从列表中访问每个参数的值。可根据需要访问其他 Parameter 对象属性。

使用参数对象的 valueAsText 方法访问参数值:

def execute(self, parameters, messages):
    inFeatures      = parameters[0].valueAsText
    outFeatureClass = parameters[1].valueAsText

                                                                                  更多内容,请关注公众号

                                                                                 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yGIS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值