Here is what i use, i found this in a thread in this forum but i can't find the link. I had a hard time understanding field mapping until i cam across this code. Since i can't find the thread i can't explain all the syntax. Maybe someone can shine in and explain the syntax please?
UG1A = "C:/Temp/Scratchworkspace.gdb/lyr1"
IRRG = "D:/GIS Folder/lyr2"
def Layers2(FZon1,UG1A,IRRG):
FieldMapString = "" \
+ """PIN "PIN" true true false 13 Text 0 0 ,First,#,""" + UG1A + """,Pin,-1,-1;"""\
+ """ACRES "ACRES" true true false 4 Double 0 0 ,First,#,""" + UG1A + """,ACRES,-1,-1;"""\
+ """Instrument "Instrument" true true false 10 Text 0 0 ,First,#,""" + UG1A + """,Instrument,-1,-1;"""\
+ """SiteAddres "SiteAddres" true true false 106 Text 0 0 ,First,#,""" + UG1A + """,SiteAddres,-1,-1;"""\
+ """SiteCity "SiteCity" true true false 32 Text 0 0 ,First,#,""" + UG1A+ """,SiteCity,-1,-1;"""\
+ """SiteZip "SiteZip" true true false 10 Text 0 0 ,First,#,""" + UG1A + """,SiteZip,-1,-1;"""\
+ """UG_NAME "UG_NAME" true false false 20 Text 0 0 ,First,#,"""+ UG1A + """,UG_NAME,-1,-1;"""\
+ """IRRIG_DIST "IRRIG_DIST" true false false 60 Text 0 0 ,First,#,"""+ IRRG + """,NAME,-1,-1;"""\
fieldmappings = arcpy.FieldMappings()
fieldmappings.loadFromString(FieldMapString)
return fieldmappings
def main(args=None):
if args is None:
args = sys.argv
arcpy.SpatialJoin_analysis(UG1A, IRRG, "C:\Temp\Scratchworkspace.gdb\lyr3",
"JOIN_ONE_TO_ONE", "KEEP_ALL", Layers2(FZon1,UG1A,IRRG), "INTERSECT")