1

I have the following code however I need the outputs in a table which can be analysed further. How can I take the outputs from the code below and input into the table. Ive used insert cursor but am getting the following error:

Runtime error Traceback (most recent call last): File "< string >", line 11, in TypeError: value #1 - unsupported type: Result

import arcpy
arcpy.env.workspace = r"D:\Zahir\AIS\Raw_AIS_Data\2013\Test\\"
gdblist = arcpy.ListWorkspaces()
table = arcpy.CreateTable_management("D:\Zahir\AIS\Raw_AIS_Data\Test\\", "Table.dbf")
arcpy.AddField_management(table, "Name", "TEXT")
arcpy.AddField_management(table, "PosCount", "SHORT")
arcpy.AddField_management(table, "TransCount", "SHORT")
fieldlist = ["Name", "PosCount", "TransCount"]

for g in gdblist:
    desc = arcpy.Describe(g)
    name  = desc.basename
    print name
    trans_table = "main.tblTransit"
    pos_table = "main.tblPositions"
    position_count = arcpy.GetCount_management(g + "\\" + pos_table)
    transits = arcpy.Frequency_analysis(g + "\\" + trans_table, "Trans_freq", "MMSI_ID")
    transit_count = arcpy.GetCount_management(transits)
    print g + " Unique Positions = " + str(position_count) + " and Vessel Count = " + str(transit_count)
    with arcpy.da.InsertCursor(table, fieldlist) as cursor:
        cursor.insertRow((name, position_count, transit_count))
  • Look at the Create Table tool to create a dbf file, you then need to add fields to it and within your loop you would have an insert cursor inserting the results into each row as you loop. – Hornbydd Jul 20 '16 at 11:52
  • I think it may be time for you to edit your question and revise it heavily so that you can focus it on just the place that you are now stuck. To me it is not clear what the results are that you want to export into a table nor what you mean by "average statistics". – PolyGeo Jul 24 '16 at 9:02
  • Thanks @PolyGeo, I have edited the question now to just focus on the part I need – MacroZED Jul 25 '16 at 10:41
  • What are you expecting to see in your table? Have you tried CreateTable then AddField to get the table schema right first? Then you can use ArcPy.da.InsertCursor to populate it. – PolyGeo Jul 25 '16 at 10:45
  • Ive updated the question having tried update.da.cursor, but the table isnt being updated with the information – MacroZED Jul 26 '16 at 10:42
1

I managed to get the insert cursor to work using arcpy.insertcursor...

import arcpy
arcpy.env.workspace = r"D:\Zahir\AIS\Raw_AIS_Data\2013\Test\\"
gdblist = arcpy.ListWorkspaces()
table = arcpy.CreateTable_management("D:\Zahir\AIS\Raw_AIS_Data\Test\\", "Table.dbf")
arcpy.AddField_management(table, "Name", "TEXT")
arcpy.AddField_management(table, "PosCount", "LONG")
arcpy.AddField_management(table, "TransCount", "LONG")
cursor = arcpy.insertcursor(table)

for g in gdblist:
    desc = arcpy.Describe(g)
    name  = desc.basename
    print name
    trans_table = "main.tblTransit"
    pos_table = "main.tblPositions"
    position_count = arcpy.GetCount_management(g + "\\" + pos_table)
    transits = arcpy.Frequency_analysis(g + "\\" + trans_table, "Trans_freq", "MMSI_ID")
    transit_count = arcpy.GetCount_management(transits)
    print g + " Unique Positions = " + str(position_count) + " and Vessel Count = " + str(transit_count)
    row = cursor.newRow()
    row.setValue("Name", name)
    row.setValue("PosCount", position_count)
    row.setValue("TransCount", transit_count)
    cursor.insertRow(row)

del cursor
del row

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.