I need some help with some nested Search/Insert Cursors adding data to a table and to a point feature class.
- What I have:
- I have one big table with stations 1-n with for example 10,000 rows for each station.
- A point feature class in a file geodatabase.
- What I want:
- I want to copy the rows for each station into a newly created table (all attributes).
- AND I want to copy the first row from this new table into the point feature class but only with the relevant fields (5 attributes) adding its point to the geometry of course.
- What I get:
I managed to create one new table and copy the table content into the new table. The script runs without giving an error but in the end I don't have a new point in my feature class.
When I try to let it run for more than one station I get the RuntimeError: workspace already in transaction mode (below in Row 14).
When I remove the part with creating the point I can create as many tables as I want.
Printing the values that are supposed to be inserted into the point feature class (fillValues) they look good to me.
- What I also already tried:
I just tried also with removing the table relevant part (since they are all created now). Now I get an IndexError: list index out of range pointing to my FirstObject. But it first runs through the whole script - but again without adding my point :-(
I also tried without adding the OBJECTID but with the same result.
I would be very happy if someone could push me in the right direction to make this work.
Here is simplified version of my module:
fieldnames = [field names from input table except OBJECTID]
fillnames=[field names for point feature class, manually created, not OBJECTID, not SHAPE]
# Create cursors and insert new rows
for profile in profile_nrs:
with arcpy.da.SearchCursor(table,fieldnames,expression) as sCursor:
for sRow in sCursor:
with arcpy.da.InsertCursor(table_name,fieldnames) as iCursor:
for sRow in sCursor: -> This is where I get the RuntimeError
print("Table "+table_name+" filled")
# From here starts the point feature creation
#Identify first OBJECTID used in new table
#Define expression to limit the extracted rows to the first row
#Define field names used for point table
pfieldnames=['Cruise','Station', 'Type', 'Date', 'Longitude', 'Latitude']
for pname in pfieldnames:
with arcpy.da.SearchCursor(table_name, pname, pexpression) as pCursor:
for pRow in pCursor:
#take the values extracted from the first row in the new table and put
#them into a new array adding OBJECTID and Shape (Geometry)
fillValues=[pfieldsvalues, ShapeVal, pfieldsvalues, pfieldsvalues, pfieldsvalues, pfieldsvalues, pfieldsvalues, pfieldsvalues]
print("point added to All_points")