AnsweredAssumed Answered

Moving values within FC works, but not for a List of FCs

Question asked by Gabino011 on Jan 21, 2015
Latest reply on Jan 23, 2015 by Gabino011

Hi Everyone -

 

I have a code that moves values around within a FC [which is the result of an intersection] from one field to another so that I will have them all previously intersected values aligned in one single row. The code works well when I apply it to one FC at a time, but when I extend it to a List of FCs, it does not work.  I've tried fixing it by playing with the indentation of the UpdateCursor lines, but it didn't work. Any idea what might be happening/missing ?

 

On another token, it seems to me that what I am trying to do, it could be done a lot simpler, any ideas on how to optimize it ?

 

Thanks much !

Gabriel

 

import arcpy, os

from arcpy import env

 

# Set environment settings

env.workspace = r"C:\GIS\Track1\1_Orig\int2"

 

# Set local variables

copyFields = ("PorousMed","K_1","Pity_1","Leng_m")

insertFd1 = ['PM1','K1','P1','leng_m1']

insertFd2 = ['PM2','K2','P2','leng_m2']

insertFd3 = ['PM3','K3','P3','leng_m3']

insertFd4 = ['PM4','K4','P4','leng_m4']

insertFd5 = ['PM5','K5','P5','leng_m5']

 

valueList = []

 

try:

    fcList = arcpy.ListFeatureClasses("","POLYLINE")

    for fc in fcList:

        print fc

        rows = arcpy.da.SearchCursor(fc, copyFields)

        for row in rows:

            valueList.append(row[0])

            valueList.append(row[1])

            valueList.append(row[2])

            valueList.append(row[3])

 

            cursor = arcpy.UpdateCursor(fc, insertFd1)

            for row in cursor:

                    row.setValue("PM1",valueList[0])

                    row.setValue("K1",valueList[1])

                    row.setValue("poros1",valueList[2])

                    row.setValue("leng_m1",valueList[3])

                    cursor.updateRow(row)

            del cursor, row

 

            cursor = arcpy.UpdateCursor(fc, insertFd2)

            for row in cursor:

                    row.setValue("PM2",valueList[4])

                    row.setValue("K2",valueList[5])

                    row.setValue("poros2",valueList[6])

                    row.setValue("leng_m2",valueList[7])

                    cursor.updateRow(row)

            del cursor, row

 

            cursor = arcpy.UpdateCursor(fc, insertFd3)  

            for row in cursor:

                    row.setValue("PM3",valueList[8])

                    row.setValue("K3",valueList[9])

                    row.setValue("poros3",valueList[10])

                    row.setValue("leng_m3",valueList[11])

                    cursor.updateRow(row)

            del cursor, row

 

            cursor = arcpy.UpdateCursor(fc, insertFd4)      

            for row in cursor:

                    row.setValue("PM4",valueList[12])

                    row.setValue("K4",valueList[13])

                    row.setValue("poros4",valueList[14])

                    row.setValue("leng_m4",valueList[15])

                    cursor.updateRow(row)

            del cursor, row

 

            cursor = arcpy.UpdateCursor(fc, insertFd5)      

            for row in cursor:

                    row.setValue("PM5",valueList[16])

                    row.setValue("K5",valueList[17])

                    row.setValue("poros5",valueList[18])

                    row.setValue("leng_m5",valueList[19])

                    cursor.updateRow(row)

            del cursor, row

   

except:

    print arcpy.GetMessages(0)

    print arcpy.GetMessages(1)

    print arcpy.GetMessages(2)

Outcomes