ArcMap 10.2:自定义 ArcGIS 工具。

ArcMap 10.2: Custom ArcGIS tool.

我正在尝试修改第一个脚本并将其转换为自定义 ArcGIS 工具。第一个脚本获取 shapefile 并将它们转换为要素图层,然后与新要素图层相交,最后将输出复制到一个 ne shapefile。脚本的这一部分有效。

第二个脚本应该是第一个脚本的修改版本。大多数脚本似乎都有效,除了 count= int(arcpy.GetCount_management("output_features").getOutput(0)),arcpy.AddMessage 和 arcpy.AddWarning 部分。

我不确定脚本是否正确 count = int(arcpy.GetCount_management("output_features").getOutput(0))

目前 arcpy.AddMessage returns "A new feature class (the full path of the output_features) the out has been created!"

我想让它说 "A new feature class 'selected_parcels' has been created!"

此外,我希望 arcpy.AddWarning 到 return selected_parcels 中的行数。目前我收到一条错误消息,指出该计数不存在。

#Current code:

#Part I


try:
    userWorkspace = raw_input("What is the workspace location?")
    input_class = raw_input("What is the input feature class name?")
    select_class = raw_input("What is the select feature class name?")
    output_class = raw_input("What is the output feature class name?")

    arcpy.env.workspace = userWorkspace
    arcpy.env.overwriteOutput = True
    arcpy.MakeFeatureLayer_management(input_class,"lyr")
    arcpy.MakeFeatureLayer_management(select_class,"select_lyr")
    arcpy.SelectLayerByLocation_management('lyr','intersect','select_lyr')
    arcpy.CopyFeatures_management("lyr",output_class)
    print "A new feature class",output_class," has been created!"
except:
    print arcpy.GetMessages()

#Part II


import arcpy

arcpy.env.workspace = r"C:\Users\tpmorris\ProgramingAndScripting\Lab 5 Data\Lab 5 Data"
arcpy.env.overwriteOutput = True

input_features = arcpy.GetParameterAsText(0) 
selected_parcels = arcpy.GetParameterAsText(1)
output_features = arcpy.GetParameterAsText(2)



arcpy.MakeFeatureLayer_management("coa_parcels.shp","lyr") 
arcpy.MakeFeatureLayer_management("floodplains.shp","select_lyr") 
arcpy.SelectLayerByLocation_management('lyr','intersect','select_lyr') 
arcpy.CopyFeatures_management("lyr","selected_parcels")


count = int(arcpy.GetCount_management("output_features").getOutput(0))
arcpy.AddMessage("A new feature class" + output_features + "has been created!")
arcpy.AddWarning("There are" + count + "in the new feature class.")

任何指导将不胜感激!

我认为您的代码的问题在于,当您调用 arcpy.GetCount_management 时,您提供的是字符串 ("output_features") 作为参数,而不是您的变量 output_features。

像这样的东西应该可以工作:

result = arcpy.GetCount_management(output_features)
count = int(result.getOutput(0))
arcpy.AddWarning("There are {0} in the new feature class.".format(count))

祝你好运!

汤姆