addInputField输入的参数到底哪里出错了?

65
3
Wednesday
wenhuizhan
New Contributor
import arcpy 

in_shp= r"D:\dr\ds\gc\TJDL.shp"
out_shp= r"D:\dr\fs"
in_gdb= r"D:\dr\CS.gdb\NTFHYSTHJBC"
ysgx=arcpy.FieldMappings
ly_type=arcpy.FieldMap
md_type=arcpy.FieldMap
for shp_field in arcpy.ListFields(in_shp):
ly_type.addInputField(in_shp,shp_field.name)
执行结果提示:应为类型'FieldMap',但实际为'str'我查了官方说明是“str”类型没错。









addInputField (table_dataset, field_name, {start_position}, {end_position})
但打开原文件看是这个
def addInputField(self, *args):
from ..geoprocessing._base import gp_fixargs
return convertArcObjectToPythonObject(self._arc_object.AddInputField(*gp_fixargs(args)))

是哪里出问题了?
0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

FieldMappings—ArcGIS Pro | Documentation

see the code example in the link

ly_type=arcpy.FieldMap() 
md_type=arcpy.FieldMap()
ysgx=arcpy.FieldMappings()

 


... sort of retired...
0 Kudos
wenhuizhan
New Contributor

刚学的小白,看了你发的链接的说明,但自己在测试的时候,报错了,比如

in_shp= r"D:\dr\ds\gc\TJDL.shp"
out_shp= r"D:\dr\fs"
in_shp= r"D:\dr\ds\gc\TJDL.shp"
out_shp= r"D:\dr\fs"
ly_type=arcpy.FieldMap() 
ly_type.addInputField(in_shp, tree_type)
ly_type.addInputField(out_shp, plant_type)#执行到这一句就报错,我在两个图层都建了tree_type和plant_type两个字段,类型text。我想不明白,为什么上一句不报错,下一句就报错。
 
 
 

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

I can't tell from your code.  but out_shp is not a featureclass in a geodatabase for sure and if it is supposed to be a shape file then it should read

out_shp= r"D:\dr\fs.shp"


... sort of retired...
0 Kudos