예제 #1
0
    def test_create_tool(self):
        """Verify create tool generates a GPTool"""
        result = arcpy.CreateENVIToolbox_envi(self.task_name_iso,
                                              self.output_toolbox)

        self.assertEqual(result[0], self.output_toolbox)
        self.assertTrue(os.path.isfile(self.output_toolbox))

        arcpy.ImportToolbox(self.output_toolbox)
        toolbox_list = arcpy.ListToolboxes()
        toolbox_name = '('.join((self.output_toolbox_name, self.alias)) + ')'
        self.assertTrue(toolbox_name in toolbox_list,
                        'Toolbox failed to import')

        envi_tools_list = arcpy.ListTools('*_envi')
        self.assertTrue(self.tool_name_iso in envi_tools_list,
                        'GPTool not created: ' + self.tool_name_iso)
예제 #2
0
 def _executePostProcess(self):
     try:
         print "Running post process GP"
         for process in self.postExtractGP:
             if process["ToolType"].upper() == "MODEL":
                 arcpy.ImportToolbox(process["ToolPath"])
                 arcpy.gp.toolbox = process["ToolPath"]
                 tools = arcpy.ListTools()
                 for tool in process["Tools"]:
                     if tool in tools:
                         customCode = "arcpy." + tool + "()"
                         print eval(customCode)
                         print "Finished executing model {0}".format(tool)
             elif process["ToolType"].upper() == "SCRIPT":
                 for tool in process["Tools"]:
                     scriptPath = process["ToolPath"] + "/" + tool
                     subprocess.call(
                         [sys.executable,
                          os.path.join(scriptPath)])
                     print "Finished executing script {0}".format(tool)
             else:
                 print "Sorry, not a valid tool"
         return True
     except arcpy.ExecuteError:
         line, filename, synerror = trace()
         raise DataPrepError({
             "function": "CopyData",
             "line": line,
             "filename": filename,
             "synerror": synerror,
             "arcpyError": arcpy.GetMessages(2),
         })
     except:
         line, filename, synerror = trace()
         raise DataPrepError({
             "function": "CopyData",
             "line": line,
             "filename": filename,
             "synerror": synerror,
         })
예제 #3
0
import arcpy

for tool in arcpy.ListTools():
    for p in arcpy.GetParameterInfo(tool):
        if p.parameterType == 'Derived' and p.datatype == 'Long':
            print('Tool: {}\n\tparameter: {}'.format(tool, p.displayName))
            
예제 #4
0
# 实验内容
# 1、	使用ListTools()函数查看特定工具箱(例如分析工具箱)包含的工具;
# 2、	使用Clip_analysis()函数进行裁切分析;
# 3、 ☆使用脚本实现一个工具的输出作为另一个工具的输入(工具链);
# 4、 ☆创建自定义地理处理工具实现从逗号分割的文本文件中读取数据,并将数据写入到已定义好的要素类中。

# 1 使用ListTools()函数查看特定工具箱(例如分析工具箱)包含的工具
import arcpy
tools = arcpy.ListTools('*_analysis')
for tool in tools:
    print(tool)

# 获取工具箱别名
import arcpy
boxlist = arcpy.ListToolboxes()
for box in boxlist:
    print(box)

# 2 使用Clip_analysis()函数进行裁切分析
import arcpy
in_feature = r'E:\ArcPyStudy\Data\ArcpyBook\data\CityOfSanAntonio.gdb\Burglary'
clip_feature = r'E:\ArcPyStudy\Data\ArcpyBook\Ch5\EdgewoodSD.shp'
out_feature_class = r'E:\ArcPyStudy\Data\ArcpyBook\Ch5\ClpBurglary2.shp'
arcpy.Clip_analysis(in_feature, clip_feature, out_feature_class)
print("Output Done")

# ☆3 使用脚本实现一个工具的输出作为另一个工具的输入(工具链)
import arcpy
arcpy.env.workspace = r'E:\ArcPyStudy\Data\ArcpyBook\data\TravisCounty'
streams = r'E:\ArcPyStudy\Data\ArcpyBook\data\TravisCounty\Streams.shp'
streamsBuffer = r'StreamsBuffer.shp'
"""
If you are ever searching for specific parameter information, combine the
ListTools and GetParameterInfo functions.

I use this frequently when hunting for different geoprocessing tools may have
been set up.
"""

import arcpy

search = '*_management'

for tool in arcpy.ListTools(wild_card=search):
    for p in arcpy.GetParameterInfo(tool):
        if p.parameterType == 'Derived' and p.datatype == 'Long':
            print('Tool: {}\n    parameter: {}'.format(tool, p.displayName))
예제 #6
0
import arcpy

tbx = arcpy.GetParameterAsText(0)
wildcard = arcpy.GetParameterAsText(1)

if wildcard != "*":
    arcpy.ImportToolbox(tbx)
else:
    arcpy.ImportToolbox(tbx)

thetools = arcpy.ListTools(wildcard)
for t in thetools:
    arcpy.AddMessage(t)