Ok I think I’m close but need a little more help. I have atable like the one attached. I’m trying to create a line segment from itthat goes from 22.473 to 27.346 but they are on separate lines. I need apython script to calculate the to_measure from OBJECTID 1 equal to theto_measure from OBJECTID2. Do you think that is possible?
I created sever types of table and set the table variable but seems to keep throwing the syntax at line 1. Here is an example of an exported table and the code I used.
table = "Export_Output" ridList = [] with arcpy.da.SearchCursor(table, ["RID"]) as cursor: for row in cursor: ridList.append(row[0]) del cursor ridList = set(ridList) for RID in ridList: toMeasList = [] with arcpy.da.SearchCursor(table, ["RID", "to_MEAS"], "RID = '" + RID + "'") as cursor: for row in cursor: toMeasList.append(row[1]) del cursor toMeasList.sort() with arcpy.da.UpdateCursor(table, ["to_MEAS"], "RID = '" + RID + "'") as cursor: for row in cursor: row[0] = toMeasList[-1] cursor.updateRow(row) del cursor
I did that, the table is called result. Does it have to be a certain type of table?
Yes, you will need to update the 'table' variable with the feature class/table in the Table of Contents. Ex:
table = 'RoutingTable'
Says syntax error line 1 which is declaring the table correct?
I get a 000539 : Error message from Python. It seems like it should work. At the end its taking the row[0] array and setting the toMeasList equal to it minus 1 record correct?
You can iterate through each RID and update the to_MEAS field. Ex:
table = "Sample" ridList = [] with arcpy.da.SearchCursor(table, ["RID"]) as cursor: for row in cursor: ridList.append(row[0]) del cursor ridList = set(ridList) for RID in ridList: toMeasList = [] with arcpy.da.SearchCursor(table, ["RID", "to_MEAS"], "RID = '" + RID + "' ") as cursor: for row in cursor: toMeasList.append(row[1]) del cursor toMeasList.sort() with arcpy.da.UpdateCursor(table, ["to_MEAS"], "RID = '" + RID + "'") as cursor: for row in cursor: row[0] = toMeasList[-1] cursor.updateRow(row) del cursor
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.