1

I have a table (T1) which I need to populate (using python for ArcGIS) the fields Val1, Val2 and Val3

ID Val1 Val2 Val3
0
1
2

with data from another table (T2):

ID Data
0 V1
1 V1
2 V1
0 V2
1 V2
2 V2
0 V3
1 V3
2 V3

so the original table (T1) becomes:

ID Val1 Val2 Val3
0 V1 V2 V3
1 V1 V2 V3
2 V1 V2 V3

I currently do this using a SearchCursor nested in the UpdateCursor.

I thought a quicker solution would be to split T2 into three columns or a temporary table, and then update T1 using the update cursor.

Can anyone help me with this?

My code currently:

rows = arcpy.UpdateCursor(Flow_Paths) 
for row in rows:
 X_A = row.X_Cord_A # First X Cord
 Y_A = row.Y_Cord_A # First Y Cord 
 rows_i = arcpy.SearchCursor(point_shp) 
 for row_i in rows_i: 
 if X_A == row_i.xCentroid and Y_A == row_i.yCentroid: #Find upstream path lengths and extract maximum lengths, elevations, and min area
 ElevationMax = row_i.DEM
 AreaMin = row_i.CatchArea
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Oct 31, 2013 at 2:11
0

1 Answer 1

1

My answer is quite specific to the situation but will post in case it helps anyone else.

def SplitCol(Column,Splits):
Length = len(Column)/Splits
ta = np.zeros((Length,Splits))
tv = 0
for i in range(Splits):
 for j in range(Length):
 ta[j,i] = Column[tv]
 tv += 1
return ta
ColDEM =[]
rows_i = arcpy.SearchCursor(point_shp) 
for row_i in rows_i: 
 ColDEM.append(row_i.DEM)
del row_i
del rows_i
taDEM = SplitCol(ColDEM, 3)
tv = 0
rows = arcpy.UpdateCursor(Flow_Paths) 
for row in rows:
 row.El_Max = taDEM[tv,0]
 row.El_Min = taDEM[tv,1]
 tv += 1
del row
del rows

I loop over the dbf and add the values to a vector (or column). Then the SplitCol splits my T2 table in the question above into 3 columns. I then loop over the dbf file and add the indexed results from the matrix as required.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Nov 5, 2013 at 1:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.