I am trying to append ~10,000 tables together using an ArcPy script.
I believe the method I am using does not work as the script is attempting to append too many tables at the same time. Would a possible work-around be a script that appends using looping?
import os
import sys
import string
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("spatial")
WD = "C:/workspace"
arcpy.env.workspace = WD
#selects the 10,000 tables and tries to append them all together at the same time
arcpy.CreateTable_management(out_path=WD, out_name="append", template="C:/Workspace/template", config_keyword="")
tables1 = [table for table in arcpy.ListTables() if not table.startswith('append')]
arcpy.Append_management(inputs=tables1, target="ndvi_append", schema_type="TEST", field_mapping="", subtype="")
Answer
Here's a code sample to implement crmackey's suggestion above. 1)Open an insert cursor for your final location, 2) loop each table, 3) check if table doesn't start with append, 4) read table data with a search cursor, consumed in a list, 5) use insert cursor to push table data into final table.
insertCursor = arcpy.da.InsertCursor("ndvi_append", "*")
for table in arcpy.ListTables():
if not table.startswith('append'):
tableData = list(arcpy.da.SearchCursor(table, "*"))
for data in tableData:
insertCursor.insertRow(data)
No comments:
Post a Comment