3

Is there a way to concatenate features in ArcGIS by using ArcPy, or field calculator, to produce the following output? I am aware of the concatenate tool that Esri created, however it doesn't keep the Features and the Values in the same order.

I need Feature A, to line up with the appropriate Value. And the tool also condenses multiple values. If there are two 0's in the output, the tool will get rid of the extra ones.

enter image description here

After talking to Craig. Here is the python code that I have been testing, this is from the link that he provided in the comments: I reset the links to my personal folders, however the error that I keep receiving states, "RuntimeError: cannot open" for the link of the new_table. When I do create a copy of the source table to be used as the new_table, and rename it as table2.dbf, it deletes the information.

import os  
import arcpy  
arcpy.env.workspace = r"c:\users\Desktop\test" 
table = r"c:\users\Desktop\test\GridforPython.dbf" # source_table  
new_table = r"table.dbf" # new table name + extension only  
tempTable = r"\\in_memory\temp_table"  
outPath = r"c:\users\Desktop\test" # path to output location on disk  
keyField = "ID_Input" 
valField = "Value_Input"

tableDict = {}  
arcpy.MakeTableView_management(table, tempTable)  
with arcpy.da.SearchCursor(table, [keyField, valField]) as cursor:   
    for row in cursor:  
        tableDict.setdefault(row[0], []).append(row[1])  

insertCursor = arcpy.da.InsertCursor(os.path.join(outPath, new_table), [keyField, valField])  
for key, val in tableDict.iteritems():  
    insertCursor.insertRow((key, ', '.join(str(item) for item in val)))  
16
  • 2
    I had a similar issue a year or so ago. Essentially, you can use arcpy and SearchCursor and InsertCursor to do what you are looking for: geonet.esri.com/message/…
    – Craig
    Sep 15, 2014 at 15:12
  • Could you please define the input values and the desired output after the operation? Will the "Feature" field (e.g. A,B,C,D,C) already be populated?
    – Aaron
    Sep 15, 2014 at 15:15
  • Thank you, I'm looking at that link now. @Aaron, I changed the image to reflect the input and output values. Sep 15, 2014 at 17:20
  • @Craig, I tried using the code from the link that you gave me, however, all it did was give me an empty table. Do you have any advice on using that code correctly? Sep 15, 2014 at 18:26
  • 1
    It seems odd to me that you would use an in_memory table as your output from MakeTableView so I think you should just give it a name like "table_view" instead. Also, remove the r from in front of r"table.dbf" too. Now I think you should run the code and if you receive an error include precisely what it is in your question (with the code updated to match). Assuming we get an error we can make debugging that single error the subject of this question, and if any others are found then research/ask them separately.
    – PolyGeo
    Sep 16, 2014 at 2:58

0

Browse other questions tagged or ask your own question.