Calculations in if statementHow to tranform a column field into a list using Field CalculatorDebugging error 000539 from ArcGIS Field Calculator?Elseif Conditional Statement in QGIS Field CalculatorRemoving return/newline (n) character from Field using Python and Field Calculator?Debugging ERROR 000539 from CalculateField in ArcPy?Python script in ArcMap Field Calculator giving Error 000539: SyntaxError: Invalid Syntax?Using Calculate Field to get acreage in ArcGIS ModelBuilder?Field Calculator Expression Assistance - Return Value Based on a Text String in Another FieldPython syntax error with If/elif statement in field calculator when using concatenationUsing Python to convert string values with Calculate Field in ArcGIS ModelBuilder?
What typically incentivizes a professor to change jobs to a lower ranking university?
How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?
What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)
"You are your self first supporter", a more proper way to say it
What's the point of deactivating Num Lock on login screens?
What are the differences between the usage of 'it' and 'they'?
Is a conference paper whose proceedings will be published in IEEE Xplore counted as a publication?
Languages that we cannot (dis)prove to be Context-Free
Are the number of citations and number of published articles the most important criteria for a tenure promotion?
Is it legal for company to use my work email to pretend I still work there?
Finding the repeating unit of polymerisation given two constituent molecules
Today is the Center
Adding span tags within wp_list_pages list items
How much RAM could one put in a typical 80386 setup?
Why is consensus so controversial in Britain?
Dragon forelimb placement
How can bays and straits be determined in a procedurally generated map?
How to find program name(s) of an installed package?
Why is Minecraft giving an OpenGL error?
Why do falling prices hurt debtors?
Pattern match does not work in bash script
Why Is Death Allowed In the Matrix?
What is the word for reserving something for yourself before others do?
Equivalence principle before Einstein
Calculations in if statement
How to tranform a column field into a list using Field CalculatorDebugging error 000539 from ArcGIS Field Calculator?Elseif Conditional Statement in QGIS Field CalculatorRemoving return/newline (n) character from Field using Python and Field Calculator?Debugging ERROR 000539 from CalculateField in ArcPy?Python script in ArcMap Field Calculator giving Error 000539: SyntaxError: Invalid Syntax?Using Calculate Field to get acreage in ArcGIS ModelBuilder?Field Calculator Expression Assistance - Return Value Based on a Text String in Another FieldPython syntax error with If/elif statement in field calculator when using concatenationUsing Python to convert string values with Calculate Field in ArcGIS ModelBuilder?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to perform a simple calculation with the Field Calculator using this piece of script (note that all the elif statements are attempts for another syntax and non of the worked):
def change(OldFor_Com):
if (OldFor_Com) == "OHWH":
return shape.area@Hectares / 40
elif (OldFor_Com) == "OHWH":
return !shape.area@Hectares / 30!
elif (OldFor_Com) == "OHWH":
return (!shape.area@Hectares / 30!)
elif (OldFor_Com) == "OHWH":
return !shape.area@Hectares! / 30
elif (OldFor_Com) == "OHWH":
return (!shape.area@Hectares! / 30)
if (OldFor_Com == "OTHH"):
return !shape.area@hectares! / 40
If the field is populated with OTHH
I want another field to be populated with the area of the field, divided by 40, or 30, or... and so on.
I modified my syntax a couple of times (as you can see) but it still says Invalid Syntax
.
Is a calculation possible with these if statement or do I need a workaround?
Note that the shape.area@Hectares is an expression to calculate the area of the field, and not another field in my attributetable!
EDIT: 7/15/2014 around 11pm
I modified the script. I added a field to the table and calculate the area of the shape first (with !shape.area@Hectares!) and then I try to run this
def change(OldFor_Com):
if OldFor_Com == "OTHH":
return Area_Ha / 40
if OldFor_Com == "OHWH":
return Area_Ha / 30
if OldFor_Com == "OSFH":
return Area_Ha / 375
if OldFor_Com == "PINE":
return Area_Ha / 10
if OldFor_Com == "OOFH":
return Area_Ha / 375
if OldFor_Com == "None":
return Area_Ha
else:
return 0
It bounces back with the following:
ERROR 000539: Error running expression: change(u"OTHH", 7)
Traceback (most recent call last):
File "<expression>", line 1, in <module>
TypeError: change() takes exactly 1 argument (2 given)
Failed to execute (Calculate Field (10)).
Is it not possible to do any calculations in the if statement?
EDIT: 7/15/14 12:30pm
This how the attributestable looks like before I add the field SizeScore
After I add the field SizeScore
(FLOAT).
And the following screen comes up if I use this code:
def change(OldFor_Com, Area_Ha):
if OldFor_Com == "OTHH":
x = Area_Ha / 40
return x
if OldFor_Com == "OHWH":
x = Area_Ha / 30
return x
if OldFor_Com == "OOFH":
x = Area_Ha / 375
return x
if OldFor_Com == "OSFH":
x = Area_Ha / 375
return x
if OldFor_Com == "PINE":
x = Area_Ha / 10
return x
if OldFor_Com == "None":
return Area_Ha
else:
return 0
It only populates the rows where it does not need to calculate.
The only statement that is working is that one.
if OldFor_Com == "None":
return Area_Ha
But for the others are no error messages coming back!
SOLVED, SEE ACCEPTED ANSWERE
Thanks a lot to everybody who went through this with me!
arcgis-desktop arcgis-10.2 field-calculator python-parser error-000539
|
show 5 more comments
I want to perform a simple calculation with the Field Calculator using this piece of script (note that all the elif statements are attempts for another syntax and non of the worked):
def change(OldFor_Com):
if (OldFor_Com) == "OHWH":
return shape.area@Hectares / 40
elif (OldFor_Com) == "OHWH":
return !shape.area@Hectares / 30!
elif (OldFor_Com) == "OHWH":
return (!shape.area@Hectares / 30!)
elif (OldFor_Com) == "OHWH":
return !shape.area@Hectares! / 30
elif (OldFor_Com) == "OHWH":
return (!shape.area@Hectares! / 30)
if (OldFor_Com == "OTHH"):
return !shape.area@hectares! / 40
If the field is populated with OTHH
I want another field to be populated with the area of the field, divided by 40, or 30, or... and so on.
I modified my syntax a couple of times (as you can see) but it still says Invalid Syntax
.
Is a calculation possible with these if statement or do I need a workaround?
Note that the shape.area@Hectares is an expression to calculate the area of the field, and not another field in my attributetable!
EDIT: 7/15/2014 around 11pm
I modified the script. I added a field to the table and calculate the area of the shape first (with !shape.area@Hectares!) and then I try to run this
def change(OldFor_Com):
if OldFor_Com == "OTHH":
return Area_Ha / 40
if OldFor_Com == "OHWH":
return Area_Ha / 30
if OldFor_Com == "OSFH":
return Area_Ha / 375
if OldFor_Com == "PINE":
return Area_Ha / 10
if OldFor_Com == "OOFH":
return Area_Ha / 375
if OldFor_Com == "None":
return Area_Ha
else:
return 0
It bounces back with the following:
ERROR 000539: Error running expression: change(u"OTHH", 7)
Traceback (most recent call last):
File "<expression>", line 1, in <module>
TypeError: change() takes exactly 1 argument (2 given)
Failed to execute (Calculate Field (10)).
Is it not possible to do any calculations in the if statement?
EDIT: 7/15/14 12:30pm
This how the attributestable looks like before I add the field SizeScore
After I add the field SizeScore
(FLOAT).
And the following screen comes up if I use this code:
def change(OldFor_Com, Area_Ha):
if OldFor_Com == "OTHH":
x = Area_Ha / 40
return x
if OldFor_Com == "OHWH":
x = Area_Ha / 30
return x
if OldFor_Com == "OOFH":
x = Area_Ha / 375
return x
if OldFor_Com == "OSFH":
x = Area_Ha / 375
return x
if OldFor_Com == "PINE":
x = Area_Ha / 10
return x
if OldFor_Com == "None":
return Area_Ha
else:
return 0
It only populates the rows where it does not need to calculate.
The only statement that is working is that one.
if OldFor_Com == "None":
return Area_Ha
But for the others are no error messages coming back!
SOLVED, SEE ACCEPTED ANSWERE
Thanks a lot to everybody who went through this with me!
arcgis-desktop arcgis-10.2 field-calculator python-parser error-000539
I don't believe you can mix/match 4 and 2 spaces. Stick with one or the other.
– Paul
Jul 14 '14 at 20:12
If I add four spaces (not six) to the third line it says intendent error. If I add six or eight it says error in the syntax. I did this intendation (four and six) in other calculations before and it worked fine.
– Stophface
Jul 14 '14 at 20:13
Try multiples of 2 or multiples of 4. First indent block is 2, then 4, then 6, etc. OR it should be 4 -> 8 -> 12 -> etc. See here, first bullet point under Note.
– Paul
Jul 14 '14 at 20:18
@ Paul thanks for the link. I will keep this in mind. There is still a mistake in the Syntax though.
– Stophface
Jul 14 '14 at 20:21
What's in your parser? And what is the field type? Is it a shapefile, SDE? etc.
– GISKid
Jul 14 '14 at 20:24
|
show 5 more comments
I want to perform a simple calculation with the Field Calculator using this piece of script (note that all the elif statements are attempts for another syntax and non of the worked):
def change(OldFor_Com):
if (OldFor_Com) == "OHWH":
return shape.area@Hectares / 40
elif (OldFor_Com) == "OHWH":
return !shape.area@Hectares / 30!
elif (OldFor_Com) == "OHWH":
return (!shape.area@Hectares / 30!)
elif (OldFor_Com) == "OHWH":
return !shape.area@Hectares! / 30
elif (OldFor_Com) == "OHWH":
return (!shape.area@Hectares! / 30)
if (OldFor_Com == "OTHH"):
return !shape.area@hectares! / 40
If the field is populated with OTHH
I want another field to be populated with the area of the field, divided by 40, or 30, or... and so on.
I modified my syntax a couple of times (as you can see) but it still says Invalid Syntax
.
Is a calculation possible with these if statement or do I need a workaround?
Note that the shape.area@Hectares is an expression to calculate the area of the field, and not another field in my attributetable!
EDIT: 7/15/2014 around 11pm
I modified the script. I added a field to the table and calculate the area of the shape first (with !shape.area@Hectares!) and then I try to run this
def change(OldFor_Com):
if OldFor_Com == "OTHH":
return Area_Ha / 40
if OldFor_Com == "OHWH":
return Area_Ha / 30
if OldFor_Com == "OSFH":
return Area_Ha / 375
if OldFor_Com == "PINE":
return Area_Ha / 10
if OldFor_Com == "OOFH":
return Area_Ha / 375
if OldFor_Com == "None":
return Area_Ha
else:
return 0
It bounces back with the following:
ERROR 000539: Error running expression: change(u"OTHH", 7)
Traceback (most recent call last):
File "<expression>", line 1, in <module>
TypeError: change() takes exactly 1 argument (2 given)
Failed to execute (Calculate Field (10)).
Is it not possible to do any calculations in the if statement?
EDIT: 7/15/14 12:30pm
This how the attributestable looks like before I add the field SizeScore
After I add the field SizeScore
(FLOAT).
And the following screen comes up if I use this code:
def change(OldFor_Com, Area_Ha):
if OldFor_Com == "OTHH":
x = Area_Ha / 40
return x
if OldFor_Com == "OHWH":
x = Area_Ha / 30
return x
if OldFor_Com == "OOFH":
x = Area_Ha / 375
return x
if OldFor_Com == "OSFH":
x = Area_Ha / 375
return x
if OldFor_Com == "PINE":
x = Area_Ha / 10
return x
if OldFor_Com == "None":
return Area_Ha
else:
return 0
It only populates the rows where it does not need to calculate.
The only statement that is working is that one.
if OldFor_Com == "None":
return Area_Ha
But for the others are no error messages coming back!
SOLVED, SEE ACCEPTED ANSWERE
Thanks a lot to everybody who went through this with me!
arcgis-desktop arcgis-10.2 field-calculator python-parser error-000539
I want to perform a simple calculation with the Field Calculator using this piece of script (note that all the elif statements are attempts for another syntax and non of the worked):
def change(OldFor_Com):
if (OldFor_Com) == "OHWH":
return shape.area@Hectares / 40
elif (OldFor_Com) == "OHWH":
return !shape.area@Hectares / 30!
elif (OldFor_Com) == "OHWH":
return (!shape.area@Hectares / 30!)
elif (OldFor_Com) == "OHWH":
return !shape.area@Hectares! / 30
elif (OldFor_Com) == "OHWH":
return (!shape.area@Hectares! / 30)
if (OldFor_Com == "OTHH"):
return !shape.area@hectares! / 40
If the field is populated with OTHH
I want another field to be populated with the area of the field, divided by 40, or 30, or... and so on.
I modified my syntax a couple of times (as you can see) but it still says Invalid Syntax
.
Is a calculation possible with these if statement or do I need a workaround?
Note that the shape.area@Hectares is an expression to calculate the area of the field, and not another field in my attributetable!
EDIT: 7/15/2014 around 11pm
I modified the script. I added a field to the table and calculate the area of the shape first (with !shape.area@Hectares!) and then I try to run this
def change(OldFor_Com):
if OldFor_Com == "OTHH":
return Area_Ha / 40
if OldFor_Com == "OHWH":
return Area_Ha / 30
if OldFor_Com == "OSFH":
return Area_Ha / 375
if OldFor_Com == "PINE":
return Area_Ha / 10
if OldFor_Com == "OOFH":
return Area_Ha / 375
if OldFor_Com == "None":
return Area_Ha
else:
return 0
It bounces back with the following:
ERROR 000539: Error running expression: change(u"OTHH", 7)
Traceback (most recent call last):
File "<expression>", line 1, in <module>
TypeError: change() takes exactly 1 argument (2 given)
Failed to execute (Calculate Field (10)).
Is it not possible to do any calculations in the if statement?
EDIT: 7/15/14 12:30pm
This how the attributestable looks like before I add the field SizeScore
After I add the field SizeScore
(FLOAT).
And the following screen comes up if I use this code:
def change(OldFor_Com, Area_Ha):
if OldFor_Com == "OTHH":
x = Area_Ha / 40
return x
if OldFor_Com == "OHWH":
x = Area_Ha / 30
return x
if OldFor_Com == "OOFH":
x = Area_Ha / 375
return x
if OldFor_Com == "OSFH":
x = Area_Ha / 375
return x
if OldFor_Com == "PINE":
x = Area_Ha / 10
return x
if OldFor_Com == "None":
return Area_Ha
else:
return 0
It only populates the rows where it does not need to calculate.
The only statement that is working is that one.
if OldFor_Com == "None":
return Area_Ha
But for the others are no error messages coming back!
SOLVED, SEE ACCEPTED ANSWERE
Thanks a lot to everybody who went through this with me!
arcgis-desktop arcgis-10.2 field-calculator python-parser error-000539
arcgis-desktop arcgis-10.2 field-calculator python-parser error-000539
edited Apr 2 at 20:43
Glorfindel
2831311
2831311
asked Jul 14 '14 at 19:55
StophfaceStophface
1,19811539
1,19811539
I don't believe you can mix/match 4 and 2 spaces. Stick with one or the other.
– Paul
Jul 14 '14 at 20:12
If I add four spaces (not six) to the third line it says intendent error. If I add six or eight it says error in the syntax. I did this intendation (four and six) in other calculations before and it worked fine.
– Stophface
Jul 14 '14 at 20:13
Try multiples of 2 or multiples of 4. First indent block is 2, then 4, then 6, etc. OR it should be 4 -> 8 -> 12 -> etc. See here, first bullet point under Note.
– Paul
Jul 14 '14 at 20:18
@ Paul thanks for the link. I will keep this in mind. There is still a mistake in the Syntax though.
– Stophface
Jul 14 '14 at 20:21
What's in your parser? And what is the field type? Is it a shapefile, SDE? etc.
– GISKid
Jul 14 '14 at 20:24
|
show 5 more comments
I don't believe you can mix/match 4 and 2 spaces. Stick with one or the other.
– Paul
Jul 14 '14 at 20:12
If I add four spaces (not six) to the third line it says intendent error. If I add six or eight it says error in the syntax. I did this intendation (four and six) in other calculations before and it worked fine.
– Stophface
Jul 14 '14 at 20:13
Try multiples of 2 or multiples of 4. First indent block is 2, then 4, then 6, etc. OR it should be 4 -> 8 -> 12 -> etc. See here, first bullet point under Note.
– Paul
Jul 14 '14 at 20:18
@ Paul thanks for the link. I will keep this in mind. There is still a mistake in the Syntax though.
– Stophface
Jul 14 '14 at 20:21
What's in your parser? And what is the field type? Is it a shapefile, SDE? etc.
– GISKid
Jul 14 '14 at 20:24
I don't believe you can mix/match 4 and 2 spaces. Stick with one or the other.
– Paul
Jul 14 '14 at 20:12
I don't believe you can mix/match 4 and 2 spaces. Stick with one or the other.
– Paul
Jul 14 '14 at 20:12
If I add four spaces (not six) to the third line it says intendent error. If I add six or eight it says error in the syntax. I did this intendation (four and six) in other calculations before and it worked fine.
– Stophface
Jul 14 '14 at 20:13
If I add four spaces (not six) to the third line it says intendent error. If I add six or eight it says error in the syntax. I did this intendation (four and six) in other calculations before and it worked fine.
– Stophface
Jul 14 '14 at 20:13
Try multiples of 2 or multiples of 4. First indent block is 2, then 4, then 6, etc. OR it should be 4 -> 8 -> 12 -> etc. See here, first bullet point under Note.
– Paul
Jul 14 '14 at 20:18
Try multiples of 2 or multiples of 4. First indent block is 2, then 4, then 6, etc. OR it should be 4 -> 8 -> 12 -> etc. See here, first bullet point under Note.
– Paul
Jul 14 '14 at 20:18
@ Paul thanks for the link. I will keep this in mind. There is still a mistake in the Syntax though.
– Stophface
Jul 14 '14 at 20:21
@ Paul thanks for the link. I will keep this in mind. There is still a mistake in the Syntax though.
– Stophface
Jul 14 '14 at 20:21
What's in your parser? And what is the field type? Is it a shapefile, SDE? etc.
– GISKid
Jul 14 '14 at 20:24
What's in your parser? And what is the field type? Is it a shapefile, SDE? etc.
– GISKid
Jul 14 '14 at 20:24
|
show 5 more comments
4 Answers
4
active
oldest
votes
After your newest updates to the question, this should work:
def change(OldFor_Com, Area_Ha):
if OldFor_Com == "OTHH":
return Area_Ha / 40.0
elif OldFor_Com == "OHWH":
return Area_Ha / 30.0
elif OldFor_Com == "OOFH":
return Area_Ha / 375.0
elif OldFor_Com == "OSFH":
return Area_Ha / 375.0
elif OldFor_Com == "PINE":
return Area_Ha / 10.0
elif OldFor_Com == "None":
return Area_Ha
else:
return 0
The reason you were seeing all 0
s (except for the "None" case) was not that the function wasn't working, but rather that you were dividing integers by integers. The results were always less than 1, and Python always rounds down for integer math. Adding .0
to each of the denominators forces decimal math, and the results will be decimals.
(Alternatively -- and this is probably better -- is to make the "Area_Ha" field a float/double instead of an integer. Then your function would work exactly as you've written it.)
Awesome dude. Thats working now! Thanks a lot for the explanation! Now I am a little bit more pythionic again :) Till he next problem which is probably just waiting around the corner. Could you explain why I need the variable x though?
– Stophface
Jul 15 '14 at 17:05
You don't, I added that in there to see what was going on in the original cod. it should work if you take out the x and just usereturn area / 10.0
– GISKid
Jul 15 '14 at 17:09
Yeah, you don't need an intermediate variable. I cleaned up the code in the answer and added theelif
s back in to make the code more efficient.
– nmpeterson
Jul 15 '14 at 17:12
add a comment |
You need to send your area field into your calculation as a parameter.
Expression: change(!OldFor_Com!, !shape.area@hectares!)
Code Block:
def change(OldFor_Com, area):
if OldFor_Com == "OTHH":
return area / 40
elif OldFor_Com == "OHWH":
return area / 30
The setting of the!
I tried in my thirdelif
statement. Does not work.
– Stophface
Jul 14 '14 at 20:08
Is the invalid syntax being reported before the third line? If so, the calculation never gets there to attempt that syntax.
– evv_gis
Jul 14 '14 at 20:08
Edit my question. With this syntax I added to the post the error is in the third line.
– Stophface
Jul 14 '14 at 20:10
I updated the indentation, looks like I was off by one.
– evv_gis
Jul 14 '14 at 20:17
The intendation is fine. I get a different error message if the intendation is wrong. It is still the syntax
– Stophface
Jul 14 '14 at 20:19
|
show 2 more comments
Your exclamation marks need to be wrapped around the field name:
def change(OldFor_Com):
if OldFor_Com == "OTHH":
return !shape.area@Hectares! / 40
elif OldFor_Com == "OHWH":
return !shape.area@Hectares! / 30
Also, make sure Python is the defined Parser.
Thats what I tried in my thirdelif
statement. Does not work. Python is defined as parser.
– Stophface
Jul 14 '14 at 20:07
Updated, removed some unnecessary parentheses.
– artwork21
Jul 14 '14 at 20:09
@artwork21 you only need one if statement for "OHWH" as well. I think OP was just testing multiple formattings to see if it would work.
– GISKid
Jul 14 '14 at 20:11
Yep GISKid, that what I did
– Stophface
Jul 14 '14 at 20:11
2
In the python code block the !shape.area! is out of scope this is a very common misconception. See this page resources.arcgis.com/en/help/main/10.2/index.html#//… for explanation. The exclamation marks go in the expression not the code block. the answer by @ew_gis is correct except the expression should be change(OldFor_Com!, !shape.area@Hectares!)
– Michael Stimson
Jul 14 '14 at 22:15
|
show 4 more comments
Going off of your latest edit and ew_GIS try this:
Expression: change(!OldFor_Com!, !Area_Ha!)
Code Block:
def change(OldFor_Com, area):
if OldFor_Com == "OTHH":
return area / 40
elif OldFor_Com == "OHWH":
return area / 30
elif OldFor_Com in ("OOFH", "OSFH", "OOFH"):
return area / 375
elif OldFor_Com == "PINE":
return area / 10
elif OldFor_Com == "None":
return area
else:
return 0
Thanks for your effort. I edited my post! TheOR
statement does not work, Field Calculator does not like the syntax so I made it an extraelif
argument.
– Stophface
Jul 15 '14 at 15:30
Strange, could you try running it as a stand-alone script instead of in the field calculator? I'm out of touch with ArcGIS 9.3. It's been some time.
– GISKid
Jul 15 '14 at 15:35
It should work in the Field Calculator shouldnt it? I could try running it as a standalone script but it needs to be included in the modelbuilder. Its ArcGis 10.2 I am working with
– Stophface
Jul 15 '14 at 15:39
OR
does not work because it should beor
. Alternatively, useelif OldFor_Com in ("OSFH", "OOFH"):
– Paul
Jul 15 '14 at 16:07
Thanks Paul! I'm still a rookie @Stophface See my edit, I just tested it and it worked.
– GISKid
Jul 15 '14 at 16:13
|
show 2 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f107155%2fcalculations-in-if-statement%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
After your newest updates to the question, this should work:
def change(OldFor_Com, Area_Ha):
if OldFor_Com == "OTHH":
return Area_Ha / 40.0
elif OldFor_Com == "OHWH":
return Area_Ha / 30.0
elif OldFor_Com == "OOFH":
return Area_Ha / 375.0
elif OldFor_Com == "OSFH":
return Area_Ha / 375.0
elif OldFor_Com == "PINE":
return Area_Ha / 10.0
elif OldFor_Com == "None":
return Area_Ha
else:
return 0
The reason you were seeing all 0
s (except for the "None" case) was not that the function wasn't working, but rather that you were dividing integers by integers. The results were always less than 1, and Python always rounds down for integer math. Adding .0
to each of the denominators forces decimal math, and the results will be decimals.
(Alternatively -- and this is probably better -- is to make the "Area_Ha" field a float/double instead of an integer. Then your function would work exactly as you've written it.)
Awesome dude. Thats working now! Thanks a lot for the explanation! Now I am a little bit more pythionic again :) Till he next problem which is probably just waiting around the corner. Could you explain why I need the variable x though?
– Stophface
Jul 15 '14 at 17:05
You don't, I added that in there to see what was going on in the original cod. it should work if you take out the x and just usereturn area / 10.0
– GISKid
Jul 15 '14 at 17:09
Yeah, you don't need an intermediate variable. I cleaned up the code in the answer and added theelif
s back in to make the code more efficient.
– nmpeterson
Jul 15 '14 at 17:12
add a comment |
After your newest updates to the question, this should work:
def change(OldFor_Com, Area_Ha):
if OldFor_Com == "OTHH":
return Area_Ha / 40.0
elif OldFor_Com == "OHWH":
return Area_Ha / 30.0
elif OldFor_Com == "OOFH":
return Area_Ha / 375.0
elif OldFor_Com == "OSFH":
return Area_Ha / 375.0
elif OldFor_Com == "PINE":
return Area_Ha / 10.0
elif OldFor_Com == "None":
return Area_Ha
else:
return 0
The reason you were seeing all 0
s (except for the "None" case) was not that the function wasn't working, but rather that you were dividing integers by integers. The results were always less than 1, and Python always rounds down for integer math. Adding .0
to each of the denominators forces decimal math, and the results will be decimals.
(Alternatively -- and this is probably better -- is to make the "Area_Ha" field a float/double instead of an integer. Then your function would work exactly as you've written it.)
Awesome dude. Thats working now! Thanks a lot for the explanation! Now I am a little bit more pythionic again :) Till he next problem which is probably just waiting around the corner. Could you explain why I need the variable x though?
– Stophface
Jul 15 '14 at 17:05
You don't, I added that in there to see what was going on in the original cod. it should work if you take out the x and just usereturn area / 10.0
– GISKid
Jul 15 '14 at 17:09
Yeah, you don't need an intermediate variable. I cleaned up the code in the answer and added theelif
s back in to make the code more efficient.
– nmpeterson
Jul 15 '14 at 17:12
add a comment |
After your newest updates to the question, this should work:
def change(OldFor_Com, Area_Ha):
if OldFor_Com == "OTHH":
return Area_Ha / 40.0
elif OldFor_Com == "OHWH":
return Area_Ha / 30.0
elif OldFor_Com == "OOFH":
return Area_Ha / 375.0
elif OldFor_Com == "OSFH":
return Area_Ha / 375.0
elif OldFor_Com == "PINE":
return Area_Ha / 10.0
elif OldFor_Com == "None":
return Area_Ha
else:
return 0
The reason you were seeing all 0
s (except for the "None" case) was not that the function wasn't working, but rather that you were dividing integers by integers. The results were always less than 1, and Python always rounds down for integer math. Adding .0
to each of the denominators forces decimal math, and the results will be decimals.
(Alternatively -- and this is probably better -- is to make the "Area_Ha" field a float/double instead of an integer. Then your function would work exactly as you've written it.)
After your newest updates to the question, this should work:
def change(OldFor_Com, Area_Ha):
if OldFor_Com == "OTHH":
return Area_Ha / 40.0
elif OldFor_Com == "OHWH":
return Area_Ha / 30.0
elif OldFor_Com == "OOFH":
return Area_Ha / 375.0
elif OldFor_Com == "OSFH":
return Area_Ha / 375.0
elif OldFor_Com == "PINE":
return Area_Ha / 10.0
elif OldFor_Com == "None":
return Area_Ha
else:
return 0
The reason you were seeing all 0
s (except for the "None" case) was not that the function wasn't working, but rather that you were dividing integers by integers. The results were always less than 1, and Python always rounds down for integer math. Adding .0
to each of the denominators forces decimal math, and the results will be decimals.
(Alternatively -- and this is probably better -- is to make the "Area_Ha" field a float/double instead of an integer. Then your function would work exactly as you've written it.)
edited Jul 15 '14 at 17:11
answered Jul 15 '14 at 16:43
nmpetersonnmpeterson
7,4002555
7,4002555
Awesome dude. Thats working now! Thanks a lot for the explanation! Now I am a little bit more pythionic again :) Till he next problem which is probably just waiting around the corner. Could you explain why I need the variable x though?
– Stophface
Jul 15 '14 at 17:05
You don't, I added that in there to see what was going on in the original cod. it should work if you take out the x and just usereturn area / 10.0
– GISKid
Jul 15 '14 at 17:09
Yeah, you don't need an intermediate variable. I cleaned up the code in the answer and added theelif
s back in to make the code more efficient.
– nmpeterson
Jul 15 '14 at 17:12
add a comment |
Awesome dude. Thats working now! Thanks a lot for the explanation! Now I am a little bit more pythionic again :) Till he next problem which is probably just waiting around the corner. Could you explain why I need the variable x though?
– Stophface
Jul 15 '14 at 17:05
You don't, I added that in there to see what was going on in the original cod. it should work if you take out the x and just usereturn area / 10.0
– GISKid
Jul 15 '14 at 17:09
Yeah, you don't need an intermediate variable. I cleaned up the code in the answer and added theelif
s back in to make the code more efficient.
– nmpeterson
Jul 15 '14 at 17:12
Awesome dude. Thats working now! Thanks a lot for the explanation! Now I am a little bit more pythionic again :) Till he next problem which is probably just waiting around the corner. Could you explain why I need the variable x though?
– Stophface
Jul 15 '14 at 17:05
Awesome dude. Thats working now! Thanks a lot for the explanation! Now I am a little bit more pythionic again :) Till he next problem which is probably just waiting around the corner. Could you explain why I need the variable x though?
– Stophface
Jul 15 '14 at 17:05
You don't, I added that in there to see what was going on in the original cod. it should work if you take out the x and just use
return area / 10.0
– GISKid
Jul 15 '14 at 17:09
You don't, I added that in there to see what was going on in the original cod. it should work if you take out the x and just use
return area / 10.0
– GISKid
Jul 15 '14 at 17:09
Yeah, you don't need an intermediate variable. I cleaned up the code in the answer and added the
elif
s back in to make the code more efficient.– nmpeterson
Jul 15 '14 at 17:12
Yeah, you don't need an intermediate variable. I cleaned up the code in the answer and added the
elif
s back in to make the code more efficient.– nmpeterson
Jul 15 '14 at 17:12
add a comment |
You need to send your area field into your calculation as a parameter.
Expression: change(!OldFor_Com!, !shape.area@hectares!)
Code Block:
def change(OldFor_Com, area):
if OldFor_Com == "OTHH":
return area / 40
elif OldFor_Com == "OHWH":
return area / 30
The setting of the!
I tried in my thirdelif
statement. Does not work.
– Stophface
Jul 14 '14 at 20:08
Is the invalid syntax being reported before the third line? If so, the calculation never gets there to attempt that syntax.
– evv_gis
Jul 14 '14 at 20:08
Edit my question. With this syntax I added to the post the error is in the third line.
– Stophface
Jul 14 '14 at 20:10
I updated the indentation, looks like I was off by one.
– evv_gis
Jul 14 '14 at 20:17
The intendation is fine. I get a different error message if the intendation is wrong. It is still the syntax
– Stophface
Jul 14 '14 at 20:19
|
show 2 more comments
You need to send your area field into your calculation as a parameter.
Expression: change(!OldFor_Com!, !shape.area@hectares!)
Code Block:
def change(OldFor_Com, area):
if OldFor_Com == "OTHH":
return area / 40
elif OldFor_Com == "OHWH":
return area / 30
The setting of the!
I tried in my thirdelif
statement. Does not work.
– Stophface
Jul 14 '14 at 20:08
Is the invalid syntax being reported before the third line? If so, the calculation never gets there to attempt that syntax.
– evv_gis
Jul 14 '14 at 20:08
Edit my question. With this syntax I added to the post the error is in the third line.
– Stophface
Jul 14 '14 at 20:10
I updated the indentation, looks like I was off by one.
– evv_gis
Jul 14 '14 at 20:17
The intendation is fine. I get a different error message if the intendation is wrong. It is still the syntax
– Stophface
Jul 14 '14 at 20:19
|
show 2 more comments
You need to send your area field into your calculation as a parameter.
Expression: change(!OldFor_Com!, !shape.area@hectares!)
Code Block:
def change(OldFor_Com, area):
if OldFor_Com == "OTHH":
return area / 40
elif OldFor_Com == "OHWH":
return area / 30
You need to send your area field into your calculation as a parameter.
Expression: change(!OldFor_Com!, !shape.area@hectares!)
Code Block:
def change(OldFor_Com, area):
if OldFor_Com == "OTHH":
return area / 40
elif OldFor_Com == "OHWH":
return area / 30
edited Jul 15 '14 at 12:43
answered Jul 14 '14 at 20:01
evv_gisevv_gis
2,5051123
2,5051123
The setting of the!
I tried in my thirdelif
statement. Does not work.
– Stophface
Jul 14 '14 at 20:08
Is the invalid syntax being reported before the third line? If so, the calculation never gets there to attempt that syntax.
– evv_gis
Jul 14 '14 at 20:08
Edit my question. With this syntax I added to the post the error is in the third line.
– Stophface
Jul 14 '14 at 20:10
I updated the indentation, looks like I was off by one.
– evv_gis
Jul 14 '14 at 20:17
The intendation is fine. I get a different error message if the intendation is wrong. It is still the syntax
– Stophface
Jul 14 '14 at 20:19
|
show 2 more comments
The setting of the!
I tried in my thirdelif
statement. Does not work.
– Stophface
Jul 14 '14 at 20:08
Is the invalid syntax being reported before the third line? If so, the calculation never gets there to attempt that syntax.
– evv_gis
Jul 14 '14 at 20:08
Edit my question. With this syntax I added to the post the error is in the third line.
– Stophface
Jul 14 '14 at 20:10
I updated the indentation, looks like I was off by one.
– evv_gis
Jul 14 '14 at 20:17
The intendation is fine. I get a different error message if the intendation is wrong. It is still the syntax
– Stophface
Jul 14 '14 at 20:19
The setting of the
!
I tried in my third elif
statement. Does not work.– Stophface
Jul 14 '14 at 20:08
The setting of the
!
I tried in my third elif
statement. Does not work.– Stophface
Jul 14 '14 at 20:08
Is the invalid syntax being reported before the third line? If so, the calculation never gets there to attempt that syntax.
– evv_gis
Jul 14 '14 at 20:08
Is the invalid syntax being reported before the third line? If so, the calculation never gets there to attempt that syntax.
– evv_gis
Jul 14 '14 at 20:08
Edit my question. With this syntax I added to the post the error is in the third line.
– Stophface
Jul 14 '14 at 20:10
Edit my question. With this syntax I added to the post the error is in the third line.
– Stophface
Jul 14 '14 at 20:10
I updated the indentation, looks like I was off by one.
– evv_gis
Jul 14 '14 at 20:17
I updated the indentation, looks like I was off by one.
– evv_gis
Jul 14 '14 at 20:17
The intendation is fine. I get a different error message if the intendation is wrong. It is still the syntax
– Stophface
Jul 14 '14 at 20:19
The intendation is fine. I get a different error message if the intendation is wrong. It is still the syntax
– Stophface
Jul 14 '14 at 20:19
|
show 2 more comments
Your exclamation marks need to be wrapped around the field name:
def change(OldFor_Com):
if OldFor_Com == "OTHH":
return !shape.area@Hectares! / 40
elif OldFor_Com == "OHWH":
return !shape.area@Hectares! / 30
Also, make sure Python is the defined Parser.
Thats what I tried in my thirdelif
statement. Does not work. Python is defined as parser.
– Stophface
Jul 14 '14 at 20:07
Updated, removed some unnecessary parentheses.
– artwork21
Jul 14 '14 at 20:09
@artwork21 you only need one if statement for "OHWH" as well. I think OP was just testing multiple formattings to see if it would work.
– GISKid
Jul 14 '14 at 20:11
Yep GISKid, that what I did
– Stophface
Jul 14 '14 at 20:11
2
In the python code block the !shape.area! is out of scope this is a very common misconception. See this page resources.arcgis.com/en/help/main/10.2/index.html#//… for explanation. The exclamation marks go in the expression not the code block. the answer by @ew_gis is correct except the expression should be change(OldFor_Com!, !shape.area@Hectares!)
– Michael Stimson
Jul 14 '14 at 22:15
|
show 4 more comments
Your exclamation marks need to be wrapped around the field name:
def change(OldFor_Com):
if OldFor_Com == "OTHH":
return !shape.area@Hectares! / 40
elif OldFor_Com == "OHWH":
return !shape.area@Hectares! / 30
Also, make sure Python is the defined Parser.
Thats what I tried in my thirdelif
statement. Does not work. Python is defined as parser.
– Stophface
Jul 14 '14 at 20:07
Updated, removed some unnecessary parentheses.
– artwork21
Jul 14 '14 at 20:09
@artwork21 you only need one if statement for "OHWH" as well. I think OP was just testing multiple formattings to see if it would work.
– GISKid
Jul 14 '14 at 20:11
Yep GISKid, that what I did
– Stophface
Jul 14 '14 at 20:11
2
In the python code block the !shape.area! is out of scope this is a very common misconception. See this page resources.arcgis.com/en/help/main/10.2/index.html#//… for explanation. The exclamation marks go in the expression not the code block. the answer by @ew_gis is correct except the expression should be change(OldFor_Com!, !shape.area@Hectares!)
– Michael Stimson
Jul 14 '14 at 22:15
|
show 4 more comments
Your exclamation marks need to be wrapped around the field name:
def change(OldFor_Com):
if OldFor_Com == "OTHH":
return !shape.area@Hectares! / 40
elif OldFor_Com == "OHWH":
return !shape.area@Hectares! / 30
Also, make sure Python is the defined Parser.
Your exclamation marks need to be wrapped around the field name:
def change(OldFor_Com):
if OldFor_Com == "OTHH":
return !shape.area@Hectares! / 40
elif OldFor_Com == "OHWH":
return !shape.area@Hectares! / 30
Also, make sure Python is the defined Parser.
edited Jul 14 '14 at 20:53
nmpeterson
7,4002555
7,4002555
answered Jul 14 '14 at 20:00
artwork21artwork21
31.1k554120
31.1k554120
Thats what I tried in my thirdelif
statement. Does not work. Python is defined as parser.
– Stophface
Jul 14 '14 at 20:07
Updated, removed some unnecessary parentheses.
– artwork21
Jul 14 '14 at 20:09
@artwork21 you only need one if statement for "OHWH" as well. I think OP was just testing multiple formattings to see if it would work.
– GISKid
Jul 14 '14 at 20:11
Yep GISKid, that what I did
– Stophface
Jul 14 '14 at 20:11
2
In the python code block the !shape.area! is out of scope this is a very common misconception. See this page resources.arcgis.com/en/help/main/10.2/index.html#//… for explanation. The exclamation marks go in the expression not the code block. the answer by @ew_gis is correct except the expression should be change(OldFor_Com!, !shape.area@Hectares!)
– Michael Stimson
Jul 14 '14 at 22:15
|
show 4 more comments
Thats what I tried in my thirdelif
statement. Does not work. Python is defined as parser.
– Stophface
Jul 14 '14 at 20:07
Updated, removed some unnecessary parentheses.
– artwork21
Jul 14 '14 at 20:09
@artwork21 you only need one if statement for "OHWH" as well. I think OP was just testing multiple formattings to see if it would work.
– GISKid
Jul 14 '14 at 20:11
Yep GISKid, that what I did
– Stophface
Jul 14 '14 at 20:11
2
In the python code block the !shape.area! is out of scope this is a very common misconception. See this page resources.arcgis.com/en/help/main/10.2/index.html#//… for explanation. The exclamation marks go in the expression not the code block. the answer by @ew_gis is correct except the expression should be change(OldFor_Com!, !shape.area@Hectares!)
– Michael Stimson
Jul 14 '14 at 22:15
Thats what I tried in my third
elif
statement. Does not work. Python is defined as parser.– Stophface
Jul 14 '14 at 20:07
Thats what I tried in my third
elif
statement. Does not work. Python is defined as parser.– Stophface
Jul 14 '14 at 20:07
Updated, removed some unnecessary parentheses.
– artwork21
Jul 14 '14 at 20:09
Updated, removed some unnecessary parentheses.
– artwork21
Jul 14 '14 at 20:09
@artwork21 you only need one if statement for "OHWH" as well. I think OP was just testing multiple formattings to see if it would work.
– GISKid
Jul 14 '14 at 20:11
@artwork21 you only need one if statement for "OHWH" as well. I think OP was just testing multiple formattings to see if it would work.
– GISKid
Jul 14 '14 at 20:11
Yep GISKid, that what I did
– Stophface
Jul 14 '14 at 20:11
Yep GISKid, that what I did
– Stophface
Jul 14 '14 at 20:11
2
2
In the python code block the !shape.area! is out of scope this is a very common misconception. See this page resources.arcgis.com/en/help/main/10.2/index.html#//… for explanation. The exclamation marks go in the expression not the code block. the answer by @ew_gis is correct except the expression should be change(OldFor_Com!, !shape.area@Hectares!)
– Michael Stimson
Jul 14 '14 at 22:15
In the python code block the !shape.area! is out of scope this is a very common misconception. See this page resources.arcgis.com/en/help/main/10.2/index.html#//… for explanation. The exclamation marks go in the expression not the code block. the answer by @ew_gis is correct except the expression should be change(OldFor_Com!, !shape.area@Hectares!)
– Michael Stimson
Jul 14 '14 at 22:15
|
show 4 more comments
Going off of your latest edit and ew_GIS try this:
Expression: change(!OldFor_Com!, !Area_Ha!)
Code Block:
def change(OldFor_Com, area):
if OldFor_Com == "OTHH":
return area / 40
elif OldFor_Com == "OHWH":
return area / 30
elif OldFor_Com in ("OOFH", "OSFH", "OOFH"):
return area / 375
elif OldFor_Com == "PINE":
return area / 10
elif OldFor_Com == "None":
return area
else:
return 0
Thanks for your effort. I edited my post! TheOR
statement does not work, Field Calculator does not like the syntax so I made it an extraelif
argument.
– Stophface
Jul 15 '14 at 15:30
Strange, could you try running it as a stand-alone script instead of in the field calculator? I'm out of touch with ArcGIS 9.3. It's been some time.
– GISKid
Jul 15 '14 at 15:35
It should work in the Field Calculator shouldnt it? I could try running it as a standalone script but it needs to be included in the modelbuilder. Its ArcGis 10.2 I am working with
– Stophface
Jul 15 '14 at 15:39
OR
does not work because it should beor
. Alternatively, useelif OldFor_Com in ("OSFH", "OOFH"):
– Paul
Jul 15 '14 at 16:07
Thanks Paul! I'm still a rookie @Stophface See my edit, I just tested it and it worked.
– GISKid
Jul 15 '14 at 16:13
|
show 2 more comments
Going off of your latest edit and ew_GIS try this:
Expression: change(!OldFor_Com!, !Area_Ha!)
Code Block:
def change(OldFor_Com, area):
if OldFor_Com == "OTHH":
return area / 40
elif OldFor_Com == "OHWH":
return area / 30
elif OldFor_Com in ("OOFH", "OSFH", "OOFH"):
return area / 375
elif OldFor_Com == "PINE":
return area / 10
elif OldFor_Com == "None":
return area
else:
return 0
Thanks for your effort. I edited my post! TheOR
statement does not work, Field Calculator does not like the syntax so I made it an extraelif
argument.
– Stophface
Jul 15 '14 at 15:30
Strange, could you try running it as a stand-alone script instead of in the field calculator? I'm out of touch with ArcGIS 9.3. It's been some time.
– GISKid
Jul 15 '14 at 15:35
It should work in the Field Calculator shouldnt it? I could try running it as a standalone script but it needs to be included in the modelbuilder. Its ArcGis 10.2 I am working with
– Stophface
Jul 15 '14 at 15:39
OR
does not work because it should beor
. Alternatively, useelif OldFor_Com in ("OSFH", "OOFH"):
– Paul
Jul 15 '14 at 16:07
Thanks Paul! I'm still a rookie @Stophface See my edit, I just tested it and it worked.
– GISKid
Jul 15 '14 at 16:13
|
show 2 more comments
Going off of your latest edit and ew_GIS try this:
Expression: change(!OldFor_Com!, !Area_Ha!)
Code Block:
def change(OldFor_Com, area):
if OldFor_Com == "OTHH":
return area / 40
elif OldFor_Com == "OHWH":
return area / 30
elif OldFor_Com in ("OOFH", "OSFH", "OOFH"):
return area / 375
elif OldFor_Com == "PINE":
return area / 10
elif OldFor_Com == "None":
return area
else:
return 0
Going off of your latest edit and ew_GIS try this:
Expression: change(!OldFor_Com!, !Area_Ha!)
Code Block:
def change(OldFor_Com, area):
if OldFor_Com == "OTHH":
return area / 40
elif OldFor_Com == "OHWH":
return area / 30
elif OldFor_Com in ("OOFH", "OSFH", "OOFH"):
return area / 375
elif OldFor_Com == "PINE":
return area / 10
elif OldFor_Com == "None":
return area
else:
return 0
edited Jul 15 '14 at 17:03
answered Jul 15 '14 at 15:11
GISKidGISKid
2,6201235
2,6201235
Thanks for your effort. I edited my post! TheOR
statement does not work, Field Calculator does not like the syntax so I made it an extraelif
argument.
– Stophface
Jul 15 '14 at 15:30
Strange, could you try running it as a stand-alone script instead of in the field calculator? I'm out of touch with ArcGIS 9.3. It's been some time.
– GISKid
Jul 15 '14 at 15:35
It should work in the Field Calculator shouldnt it? I could try running it as a standalone script but it needs to be included in the modelbuilder. Its ArcGis 10.2 I am working with
– Stophface
Jul 15 '14 at 15:39
OR
does not work because it should beor
. Alternatively, useelif OldFor_Com in ("OSFH", "OOFH"):
– Paul
Jul 15 '14 at 16:07
Thanks Paul! I'm still a rookie @Stophface See my edit, I just tested it and it worked.
– GISKid
Jul 15 '14 at 16:13
|
show 2 more comments
Thanks for your effort. I edited my post! TheOR
statement does not work, Field Calculator does not like the syntax so I made it an extraelif
argument.
– Stophface
Jul 15 '14 at 15:30
Strange, could you try running it as a stand-alone script instead of in the field calculator? I'm out of touch with ArcGIS 9.3. It's been some time.
– GISKid
Jul 15 '14 at 15:35
It should work in the Field Calculator shouldnt it? I could try running it as a standalone script but it needs to be included in the modelbuilder. Its ArcGis 10.2 I am working with
– Stophface
Jul 15 '14 at 15:39
OR
does not work because it should beor
. Alternatively, useelif OldFor_Com in ("OSFH", "OOFH"):
– Paul
Jul 15 '14 at 16:07
Thanks Paul! I'm still a rookie @Stophface See my edit, I just tested it and it worked.
– GISKid
Jul 15 '14 at 16:13
Thanks for your effort. I edited my post! The
OR
statement does not work, Field Calculator does not like the syntax so I made it an extra elif
argument.– Stophface
Jul 15 '14 at 15:30
Thanks for your effort. I edited my post! The
OR
statement does not work, Field Calculator does not like the syntax so I made it an extra elif
argument.– Stophface
Jul 15 '14 at 15:30
Strange, could you try running it as a stand-alone script instead of in the field calculator? I'm out of touch with ArcGIS 9.3. It's been some time.
– GISKid
Jul 15 '14 at 15:35
Strange, could you try running it as a stand-alone script instead of in the field calculator? I'm out of touch with ArcGIS 9.3. It's been some time.
– GISKid
Jul 15 '14 at 15:35
It should work in the Field Calculator shouldnt it? I could try running it as a standalone script but it needs to be included in the modelbuilder. Its ArcGis 10.2 I am working with
– Stophface
Jul 15 '14 at 15:39
It should work in the Field Calculator shouldnt it? I could try running it as a standalone script but it needs to be included in the modelbuilder. Its ArcGis 10.2 I am working with
– Stophface
Jul 15 '14 at 15:39
OR
does not work because it should be or
. Alternatively, use elif OldFor_Com in ("OSFH", "OOFH"):
– Paul
Jul 15 '14 at 16:07
OR
does not work because it should be or
. Alternatively, use elif OldFor_Com in ("OSFH", "OOFH"):
– Paul
Jul 15 '14 at 16:07
Thanks Paul! I'm still a rookie @Stophface See my edit, I just tested it and it worked.
– GISKid
Jul 15 '14 at 16:13
Thanks Paul! I'm still a rookie @Stophface See my edit, I just tested it and it worked.
– GISKid
Jul 15 '14 at 16:13
|
show 2 more comments
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f107155%2fcalculations-in-if-statement%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I don't believe you can mix/match 4 and 2 spaces. Stick with one or the other.
– Paul
Jul 14 '14 at 20:12
If I add four spaces (not six) to the third line it says intendent error. If I add six or eight it says error in the syntax. I did this intendation (four and six) in other calculations before and it worked fine.
– Stophface
Jul 14 '14 at 20:13
Try multiples of 2 or multiples of 4. First indent block is 2, then 4, then 6, etc. OR it should be 4 -> 8 -> 12 -> etc. See here, first bullet point under Note.
– Paul
Jul 14 '14 at 20:18
@ Paul thanks for the link. I will keep this in mind. There is still a mistake in the Syntax though.
– Stophface
Jul 14 '14 at 20:21
What's in your parser? And what is the field type? Is it a shapefile, SDE? etc.
– GISKid
Jul 14 '14 at 20:24