首先请注意我是Python的初学者。在ArcGIS环境中学习当前处理Python的课程。我当前的项目是一个简单的程序来创建文件并将其他文件复制到它们。但是,部分赋值是让print语句说明发生了什么,例如最终的print语句应如下所示:
处理Polygon FeatureClasses ....
处理FeatureClass>>建筑
现场信息:
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
答案 0 :(得分:0)
您忘记将该点传递给ListFields()
pointfield = arcpy.ListFields(pl)
for pf in pointfield:
print "Field Name:" + pf.name