首先请注意,我是 Python 的初学者。在 ArcGIS 环境中学习当前处理 Python 的课程。我当前的项目是一个简单的程序,用于创建文件并将其他文件复制到其中。然而,部分任务是让 print 语句在它发生时说明正在发生的事情,例如最终的 print 语句应该如下所示:
处理面要素类....
处理要素类 >> 建筑
字段信息:
etc.
这是我应该这样做的一小部分代码:
pointlist = arcpy.ListFeatureClasses("*", "Point")
print "Processing Point FeatureClasses..."
for pl in pointlist:
arcpy.MakeFeatureLayer_management(pl, "Point" + 1)
pointlayer = arcpy.SelectLayerByLocation_management(pl, "intersect", MapGridID)
pointcount = int(arcpy.GetCount_management(pointlayer).getOutput(0))
if pointcount >= 1:
arcpy.CopyFeatures_management(pointlayer, OutputGDB)
for pl in pointlist:
print "Processing FeatureClass:" + pl
pointfield = arcpy.ListFields()
for pf in pointfield:
print "Field Name:" + pf
出现的问题是它打印了第一个打印语句“Processing Point FeatureClasses”,但不执行其余部分,然后跳到我的下一部分代码并执行它。知道为什么吗?抱歉,如果我的格式或措辞不正确/听起来很奇怪。谢谢你。
编辑
我也给我的教授发了电子邮件,寻求一些指导,他写回了我上面代码块的一个稍微编辑过的版本。我现在可以打印除点场打印语句之外的所有内容,这些语句现在被跳过了。这是代码:
pointlist = arcpy.ListFeatureClasses("*", "Point")
print "Processing Point FeatureClasses...\n"
i = 1
for pl in pointlist:
print "Processing FeatureClass: " + pl
featlayernamepoint = "Point" + str(i)
arcpy.MakeFeatureLayer_management(pl, featlayernamepoint)
arcpy.SelectLayerByLocation_management(featlayernamepoint, "intersect", featurelayerMG2)
pointcount = int(arcpy.GetCount_management(featlayernamepoint).getOutput(0))
if pointcount >= 1:
arcpy.CopyFeatures_management(featlayernamepoint, OutputGDB)
pointfield = arcpy.ListFields(featlayernamepoint)
for pf in pointfield:
print "Field Name: " + pf.name
i += 1