I know there already are posts about this subject, I tried to derive a solution for my own problem but the code for field mapping is very complex to me.
I have a Raster 100x100m and point layers that I want to join using a python script. I need the SUM of a field called "weight" (point layer) added to the grid, but I don't know how to define the field mapping.
So far the script looks like this (but doesn't sum up my weight field):
import arcpy
from arcpy import env
env.workspace = r"C:\Users\Daniela\Desktop\test"
fc_list = arcpy.ListFeatureClasses()
for fc in fc_list:
arcpy.SpatialJoin_analysis("grid100.shp",fc,"C:/Users/Daniela/Desktop/test/test" + "_" + str(fc),"JOIN_ONE_TO_ONE","KEEP_ALL","sum","INTERSECT","","")
Best Answer
Field mappings are kind of cumbersome in ArcGIS. First you create a fieldmappings object, then create fieldmap, then add input fields and define output fields. Also, you can add the entire table to the mapping like:
I found the following example that I used some time ago when building custom mappings: