Reclass(!WELL_YIELD!,!Field_A!)
def Reclass(WellYield, Field_A): if (WellYield >= 0 and WellYield <= 10): return Field_A +90 elif (WellYield > 10 and WellYield <= 20): return 2 elif (WellYield > 20 and WellYield <= 30): return 3 elif (WellYield > 30): return 4
Unfortunately using return !Field A! does not return the value from Field A.
I tried this as well and it didn't work. Keeps telling me there is a syntax error at line 3.
expression
DirectionCalc( !TestNeg!, !Angle! )
Code:
def DirectionCalc(TestNeg,Angle):
if (TestNeg == 1):
return float(!Angle!)
elif (TestNeg >1):
return 0
This did work
def DirectionCalc(TestNeg,Angle):
if (TestNeg == 1):
return Angle
elif (TestNeg >1):
return 0
Im using chrome and i selected advanced editor but there is no option for "code wrap"
How do you return the value from a different field? There is no "#" button to click in this new geonet.
It isn't called "code wrap" but Insert > Syntax Highlighting
You are getting the syntax error on line 3 because there is no variable !Angle! in the Python function you defined. This also explains why the second block of code doesn't give you an error.
Are you saying the second code block above, the one that works, doesn't return the correct result?
Joshua,
the second code block did work in terms of puling in the value from the Angle field and returning into the Field I am calculating.
So angle + 1 would add the value from the angle field +1 into the target field.
This is the final code I came up with to convert the angle from a previous calculation into quadrant bearings.
def DirectionCalc(TestNeg,Angle): if (TestNeg == 1): return 90-Angle elif (TestNeg == 2): return (Angle*-1)+90 elif (TestNeg == 3): return 270 - Angle elif (TestNeg == 4): return (Angle*-1)+270 elif (TestNeg == 5): return 0 elif (TestNeg == 6): return 90
Lower Box:
DirectionCalc( !TestNeg!, !Angle! )
I started with a polyline layer added 4 fields... start(X,Y) and end(X,Y). Then I calculated a DeltaX and DeltaY, And used these to calculate the angle of the line from the start point. I then created TestNEG to classify which quadrant each angle fell in based on which Delta was negative...so
def TestNegative(DeltaX,DeltaY): if (float(DeltaX) > 0 and float(DeltaY) > 0): return 1 elif (float(DeltaX) < 0 and float(DeltaY) > 0): return 4 elif (float(DeltaX) > 0 and float(DeltaY) < 0): return 2 elif (float(DeltaX) < 0 and float(DeltaY) < 0): return 3 elif (float(DeltaX) == 0): return 5 elif (float(DeltaY) == 0): return 6
Lower Box:
TestNegative(!DeltaX! , !DeltaY!)
Then apply the first box of code based on this calculation.
I could probably now combine the two codes by replacing the classification numbers with the Angle field and the calculations from the first block and that would save having to classify the values.
So your initial response helped a lot Joshua and i feel like a made some major headway in using python today!
Dan