Field Mappings in arcpy
>> YOUR LINK HERE: ___ http://youtube.com/watch?v=mVQE9hmYwCE
#arcpy #python #arcgis • Hello everybody, in this video I'm going to show you how to use field mapping in Arcpy. • ----- python script ----- • import arcpy • arcpy.env.workspace = r C:\\Users\\User\\Desktop\\GIS\\3.test\\NewFeatures.gdb • mainLayer = r C:\\Users\\User\\Desktop\\GIS\\3.test\\Geodatabase.gdb\\mainLayer • fieldMappings = arcpy.FieldMappings() #field mapping variable, thi will store all field mappings • mainTable = [] • for i in arcpy.ListFields(mainLayer): • if i.name not in ( Shape , OBJECTID , FID , Shape_Length , Shape_Area ): • mainTable.append(i.name) • print mainTable • #list all feature classes • f = arcpy.ListFeatureClasses() • print f • for k in mainTable: #loop through main table • fieldMap = arcpy.FieldMap() #create an empty field map variable • fieldMap.addInputField(mainLayer,k) #insert the target layer as the first input into the field map • for feature in f: #loop through fetureclasses • for field in arcpy.ListFields(feature): #loop through field of each feature class • if k in field.name: #check if any field match with our target field and append it as an input field • fieldMap.addInputField(feature,field.name) • fieldMappings.addFieldMap(fieldMap) #add the current field map to the main field map variable • #fieldMap1 = arcpy.FieldMap() • #fieldMap1.addInputField(mainLayer, osm_id ) • #fieldMap1.addInputField( newlayer1 , osm_id ) • #fieldMap1.addInputField( newlayer2 , field_id ) • #fieldMap1.addInputField( newlayer3 , osm_id ) • #fieldMappings.addFieldMap(fieldMap1) • arcpy.Append_management(f,mainLayer, NO_TEST ,fieldMappings) • print kame hame haaaaaaa
#############################
![](http://youtor.org/essay_main.png)