Assign Field values via Python

404
1
10-27-2012 10:57 PM
RoyMartinez1
New Contributor
Greetings,

I am attempting to calculate point stationing (footage) along a pipeline at a set interval via python script.  Thing is I'm just now learning to code in Python, I have a VBA programming background.  In regards to this exercise I will be creating an empty file geodatabase, within this database I will be creating an empty feature class.  This feature class will contain an empty field/column named, "Calculated Footage".

I have been successful in obtaining the desired results within a python list as shown below but when attempting to do so in a file geodatabase I seem to be at a lost. Simply put how do I go about applying the logic below to the "Calculated Footage" field in my feature class table? In other words how do I populate the "Calculated Footage" field with the result of my while loop?


B_Measure = 0; E_Measure = 5280
Curr_Measure = 0; Interval = 1000
My_List=[]

C_Measure = 0

# Body of the Main program
while abs(E_Measure-C_Measure)>Interval:
    if My_List==[]:
        My_List.append(C_Measure)
        print C_Measure
    else:
        C_Measure=C_Measure + Interval
        My_List.append(C_Measure)
        print C_Measure


I've done this exercise in Excel as well, using the following VBA Code.

Sub Calculate_Footage()
'Declaring variables
Dim X, Y, Beginning_Point, Ending_Point, Interval, Current_Point As Integer

'Assigning initial value to variables
X = 2
Y = 1
Beginning_Point = 0
Ending_Point = 5280
Interval = 1000
Current_Point = 0

'Assign Field/Column Name
Cells(1, 1).Value = "Calculated Footage"

'This While Loop will populate my "Calculated Footage" field
Do While (Ending_Point - Current_Point) > Interval
Current_Point = Current_Point + Interval
Cells(X, Y).Value = Current_Point

'Move to the next row but same column
X = X + 1
Loop

End Sub
Tags (2)
0 Kudos
1 Reply
RoyMartinez1
New Contributor
Greetings,

I am attempting to calculate point stationing (footage) along a pipeline at a set interval via python script,  thing is I'm just now learning to code in Python, I come from a VBA programming background.  In regards to this exercise I will be creating an empty file geodatabase, within this database I will be creating an empty feature class table.  This feature class table will contain an empty field/column named, "Calculated Footage".  My desired result is to populate the content of my feature clas table via Python script such as the ones below.

I have been successful in obtaining the desired results within a python list as shown below but when attempting to do so in a file geodatabase I seem to be at a lost. Simply put how do I go about applying the logic below to the "Calculated Footage" field in my feature class table? In other words how do I populate the "Calculated Footage" field with the result of my while loop?


B_Measure = 0; E_Measure = 5280
Curr_Measure = 0; Interval = 1000
My_List=[]

C_Measure = 0

# Body of the Main program
while abs(E_Measure-C_Measure)>Interval:
    if My_List==[]:
        My_List.append(C_Measure)
        print C_Measure
    else:
        C_Measure=C_Measure + Interval
        My_List.append(C_Measure)
        print C_Measure


I've done this exercise in Excel as well, using the following VBA Code.

Sub Calculate_Footage()
'Declaring variables
Dim X, Y, Beginning_Point, Ending_Point, Interval, Current_Point As Integer

'Assigning initial value to variables
X = 2
Y = 1
Beginning_Point = 0
Ending_Point = 5280
Interval = 1000
Current_Point = 0

'Assign Field/Column Name
Cells(1, 1).Value = "Calculated Footage"

'This While Loop will populate my "Calculated Footage" field
Do While (Ending_Point - Current_Point) > Interval
Current_Point = Current_Point + Interval
Cells(X, Y).Value = Current_Point

'Move to the next row but same column
X = X + 1
Loop

End Sub


Can I use the Calculate Field function to iterate through the subject field or should I somehow use the List.append method to add values and iterate through the subject field?
0 Kudos