-2

I created a Python script to join multible tables to a feature class from a GDB. Some parameters (TabelaE2 and TabelaE3) are optional, so I put some conditions for a blank field. The script join perfectly the fields, but for some reason the columns are has been duplicate.

No errors appears after the join.

import arcpy

TabelaP1 = arcpy.GetParameterAsText(0)
TabelaE1 = arcpy.GetParameterAsText(1)
TabelaE2 = arcpy.GetParameterAsText(2)
TabelaE3 = arcpy.GetParameterAsText(3)
CampoChave1 = arcpy.GetParameterAsText(4)
CampoSaida = arcpy.GetParameterAsText(5)

arcpy.AddMessage('Tabelas Selecionadas...Efetuando Joins')

if TabelaE2 == "":

    arcpy.MakeFeatureLayer_management(TabelaP1, "brasilmunlyrt2")
    arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE1, CampoSaida, "")
    arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE3, CampoSaida, "")

elif TabelaE3 == "":

    arcpy.MakeFeatureLayer_management(TabelaP1, "brasilmunlyrt2")
    arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE1, CampoSaida, "")
    arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE2, CampoSaida, "")

else:

    arcpy.MakeFeatureLayer_management(TabelaP1, "brasilmunlyrt2")
    arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE1, CampoSaida, "")
    arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE2, CampoSaida, "")
    arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE3, CampoSaida, "")

arcpy.CopyFeatures_management("brasilmunlyrt2", "F:\AgroBD.gdb\BrasilMunJ")
arcpy.AddMessage('Concluido')
  • 1
    Can you provide a screenshot of your results. – whyzar Jun 29 '17 at 18:10
  • ArcGIS does not support duplicate field names, but there might be duplicate aliases. – Vince Jun 30 '17 at 0:56
  • Do the tables have fields in common other than the join field? If so you might want to delete these in your code – preardon Jun 30 '17 at 1:05
  • I'd check to see that only one condition is being called within your if statements. Duplication might occur if E2 and E3 tables are both empty. – preardon Jun 30 '17 at 1:10
  • 1
    @preardon I have moved your comments from the answer section to the comment section. Please only use the answer area for answers. – Aaron Jun 30 '17 at 1:14
1

Problem Solved! Many thanks for the comments and suggestions. Here is the code.

import arcpy

TabelaP1 = arcpy.GetParameterAsText(0)
TabelaE1 = arcpy.GetParameterAsText(1)
TabelaE2 = arcpy.GetParameterAsText(2)
TabelaE3 = arcpy.GetParameterAsText(3)
CampoChave1 = arcpy.GetParameterAsText(4)
CampoSaida = arcpy.GetParameterAsText(5)

arcpy.AddMessage('Tabelas Selecionadas...Efetuando Joins')

if TabelaE2 == "" and TabelaE3 == "":

    arcpy.AddMessage("Tabelas 2 e 3 ausentes. Executando Join com "         
+TabelaE1+'.')
    arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE1, CampoSaida, "")

elif TabelaE2 == "":

    arcpy.AddMessage("Tabelas 2 ausente. Executando Join com "+TabelaE1+" e"+TabelaE3)
arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE1, CampoSaida, "")
arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE3, CampoSaida, "")

elif TabelaE3 == "":

    arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE1, CampoSaida, "")
    arcpy.JoinField_management(TabelaP1, CampoChave1, TabelaE2, CampoSaida, "")

arcpy.AddMessage('Concluido')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.