ArcGIS Pro任务是否支持可在地图框架上运行的Python Toolbox工具?


10

ArcGIS Pro任务是否支持可在地图框架上运行的Python Toolbox工具?

我问的原因是我在尝试执行以下操作时被卡住:

  1. 启动ArcGIS Pro 1.1.1
  2. 创建一个新项目-我叫mine TestProject并放在C:\ Temp中
  3. 使用“项目”窗格将“文件夹连接”添加到我拥有“自然地球”(Natural Earth)世界国家/地区的shapefile的位置
  4. 将ne_10m_admin_0_countries.shp拖放到地图中以创建名为ne_10m_admin_0_countries的图层
  5. 插入新的布局-我使用了A3横向
  6. 在布局上插入新的地图框
  7. 在“项目”窗格中,在TestProject文件夹中创建一个New Python Toolbox-我称为mine TestPYT
  8. 在“项目”窗格中右键单击“ TestPYT”以对其进行编辑
  9. 将代码替换为下面的代码,为Python Toolbox提供两个名为Chile和Switzerland的工具
  10. 保存脚本并刷新Python Toolbox以查看两个新工具
  11. 运行智利工具以查看布局图上的地图框缩放至智利
  12. 运行Switzerland工具,以查看版图上的地图框放大到Switzerland
  13. 插入新任务项
  14. 在任务项1中插入一个新任务,并将其命名为Chile
  15. 在智利任务中,插入一个新步骤,并将其命名为Zoom to Chile
  16. 对于“步骤行为”,将其设置为“自动”和“隐藏”
  17. 在“操作”选项卡上,我尝试选择“智利”工具将“命令/地理处理”设置为“地理处理工具”

在此处输入图片说明

  1. 当我选择“确定”时似乎会粘住

在此处输入图片说明

  1. 当我单击“完成”时,似乎“丢失”了该工具

具体来说,我要创建的工作流包含两个任务,可以单击以放大到智利或缩放到瑞士,但在上面的第19步中遇到了麻烦。

我总体上想做的是找到一个与ArcPy(对于ArcGIS 10.x体系结构)中的Python AddIn工具栏等效的ArcPy(对于ArcGIS Pro),并使用两个按钮(智利和瑞士)来放大这些国家/地区。

我已经执行了几次此程序,有一次我能够使智利和瑞士的工具作为任务使用,但即使那样,它们似乎也没有与地图框架交互(没有错误,只是没有变化)到它们在运行时在“地图框架”中显示的位置),即使从Python工具箱运行时这些工具仍然可以正常工作。

在此处输入图片说明

这是要复制/粘贴到Python工具箱(TestPYT)中的代码。

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 = [Slide1,Slide2]


class Slide1(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Chile"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        params = None
        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."""
        aprx = arcpy.mp.ArcGISProject("CURRENT")
        mapx = aprx.listMaps()[0]
        lyt = aprx.listLayouts()[0]
        lyr = mapx.listLayers("ne_10m_admin_0_countries")[0]
        lyr.definitionQuery = '"ADMIN" = ' + "'Chile'"
        mFrame = lyt.listElements("MAPFRAME_ELEMENT")[0]
        mFrame.camera.setExtent(mFrame.getLayerExtent(lyr, False, True))
        lyr.definitionQuery = ""
        return

class Slide2(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Switzerland"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        params = None
        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."""
        aprx = arcpy.mp.ArcGISProject("CURRENT")
        mapx = aprx.listMaps()[0]
        lyt = aprx.listLayouts()[0]
        lyr = mapx.listLayers("ne_10m_admin_0_countries")[0]
        lyr.definitionQuery = '"ADMIN" = ' + "'Switzerland'"
        mFrame = lyt.listElements("MAPFRAME_ELEMENT")[0]
        mFrame.camera.setExtent(mFrame.getLayerExtent(lyr, False, True))
        lyr.definitionQuery = ""
        return

不管它在做什么,这似乎不适用于任何Python工具箱。还可能值得注意的是,选择工具并启用嵌入时未显示工具箱参数(换句话说,实际上并未正确加载工具箱)。
Evil Genius

Answers:


4

* .PYT工具箱不适用于ArcGIS Pro 1.0和1.1中的任务。

但是,自ArcGIS Pro 1.2以来已支持它们。

解决方法是尝试将工具插入到地理处理模型中,然后使用任务步骤调用模型。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.