If/Then Field Calculator Return CalculationsClassifying Attribute Table values?Basic If/Then in Python Parser of ArcGIS Field Calculator?If/then Field CalculatorIF THEN statements in ArcGIS Field CalculatorPython if/then Statement in Field Calculator to return 0 or 1 based on numbers divisible by 28?Reclass or other if/then logic expression in field calculatorIf/Then python script in Field Calculator not workingUse field calculator to return the word after “unit”?Creating If Then statement in Field Calculator between 2 values?Field Calculator: Simple Python If-then and mathsField Calculator Expression Assistance - Return Value Based on a Text String in Another Field
Personal Teleportation as a Weapon
What is the intuitive meaning of having a linear relationship between the logs of two variables?
What is paid subscription needed for in Mortal Kombat 11?
Two monoidal structures and copowering
Does "every" first-order theory have a finitely axiomatizable conservative extension?
Is expanding the research of a group into machine learning as a PhD student risky?
Short story about space worker geeks who zone out by 'listening' to radiation from stars
Is this version of a gravity generator feasible?
Failed to fetch jessie backports repository
Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?
How does it work when somebody invests in my business?
What is the difference between "behavior" and "behaviour"?
Go Pregnant or Go Home
Italian words for tools
What is the best translation for "slot" in the context of multiplayer video games?
How does the UK government determine the size of a mandate?
You cannot touch me, but I can touch you, who am I?
How do I find the solutions of the following equation?
How to safely derail a train during transit?
CREATE opcode: what does it really do?
How can we prove that any integral in the set of non-elementary integrals cannot be expressed in the form of elementary functions?
Is exact Kanji stroke length important?
Is a stroke of luck acceptable after a series of unfavorable events?
Balance Issues for a Custom Sorcerer Variant
If/Then Field Calculator Return Calculations
Classifying Attribute Table values?Basic If/Then in Python Parser of ArcGIS Field Calculator?If/then Field CalculatorIF THEN statements in ArcGIS Field CalculatorPython if/then Statement in Field Calculator to return 0 or 1 based on numbers divisible by 28?Reclass or other if/then logic expression in field calculatorIf/Then python script in Field Calculator not workingUse field calculator to return the word after “unit”?Creating If Then statement in Field Calculator between 2 values?Field Calculator: Simple Python If-then and mathsField Calculator Expression Assistance - Return Value Based on a Text String in Another Field
After collecting GPS location for road culverts I would like to calculate the $ values for each culvert based on their diameter and length in ArcMap. Existing number fields in the attribute table are Culvert Diameter, Length and the Value field I would like to populate. Unfortunately I have no programming experience so I'm hoping for your help. I adjusted a basic if/then formula I found in this forum and added a multiplication function in the return line. Unfortunately this doesn't work...
def CulvertValue(Diameter):
if Diameter > 0 and Diameter < 14:
return (Length*50)
elif Diameter > 14 and Diameter < 20:
return (Length*100)
else:
return "N/A"
And the result
CulvertValue(!Diameter!)
So let's say the culvert is under 14 inches in diameter and 20 feet long, knowing that a culvert with this diameter costs $50 per foot, the result would be 1,000. I would obviously have to add more elif lines to cover the different price categories. Any thoughts how this could be realized with a Python script?
arcgis-desktop field-calculator python-parser
add a comment |
After collecting GPS location for road culverts I would like to calculate the $ values for each culvert based on their diameter and length in ArcMap. Existing number fields in the attribute table are Culvert Diameter, Length and the Value field I would like to populate. Unfortunately I have no programming experience so I'm hoping for your help. I adjusted a basic if/then formula I found in this forum and added a multiplication function in the return line. Unfortunately this doesn't work...
def CulvertValue(Diameter):
if Diameter > 0 and Diameter < 14:
return (Length*50)
elif Diameter > 14 and Diameter < 20:
return (Length*100)
else:
return "N/A"
And the result
CulvertValue(!Diameter!)
So let's say the culvert is under 14 inches in diameter and 20 feet long, knowing that a culvert with this diameter costs $50 per foot, the result would be 1,000. I would obviously have to add more elif lines to cover the different price categories. Any thoughts how this could be realized with a Python script?
arcgis-desktop field-calculator python-parser
Welcome to GIS SE! As a new user be sure to take the Tour. Please do not say thank you in your questions or answers. The way to say thanks here is to upvote (or accept answers to your own questions).
– PolyGeo♦
Mar 13 '17 at 22:17
add a comment |
After collecting GPS location for road culverts I would like to calculate the $ values for each culvert based on their diameter and length in ArcMap. Existing number fields in the attribute table are Culvert Diameter, Length and the Value field I would like to populate. Unfortunately I have no programming experience so I'm hoping for your help. I adjusted a basic if/then formula I found in this forum and added a multiplication function in the return line. Unfortunately this doesn't work...
def CulvertValue(Diameter):
if Diameter > 0 and Diameter < 14:
return (Length*50)
elif Diameter > 14 and Diameter < 20:
return (Length*100)
else:
return "N/A"
And the result
CulvertValue(!Diameter!)
So let's say the culvert is under 14 inches in diameter and 20 feet long, knowing that a culvert with this diameter costs $50 per foot, the result would be 1,000. I would obviously have to add more elif lines to cover the different price categories. Any thoughts how this could be realized with a Python script?
arcgis-desktop field-calculator python-parser
After collecting GPS location for road culverts I would like to calculate the $ values for each culvert based on their diameter and length in ArcMap. Existing number fields in the attribute table are Culvert Diameter, Length and the Value field I would like to populate. Unfortunately I have no programming experience so I'm hoping for your help. I adjusted a basic if/then formula I found in this forum and added a multiplication function in the return line. Unfortunately this doesn't work...
def CulvertValue(Diameter):
if Diameter > 0 and Diameter < 14:
return (Length*50)
elif Diameter > 14 and Diameter < 20:
return (Length*100)
else:
return "N/A"
And the result
CulvertValue(!Diameter!)
So let's say the culvert is under 14 inches in diameter and 20 feet long, knowing that a culvert with this diameter costs $50 per foot, the result would be 1,000. I would obviously have to add more elif lines to cover the different price categories. Any thoughts how this could be realized with a Python script?
arcgis-desktop field-calculator python-parser
arcgis-desktop field-calculator python-parser
edited Mar 13 '17 at 22:15
PolyGeo♦
53.8k1781244
53.8k1781244
asked Mar 13 '17 at 22:11
TomTom
284
284
Welcome to GIS SE! As a new user be sure to take the Tour. Please do not say thank you in your questions or answers. The way to say thanks here is to upvote (or accept answers to your own questions).
– PolyGeo♦
Mar 13 '17 at 22:17
add a comment |
Welcome to GIS SE! As a new user be sure to take the Tour. Please do not say thank you in your questions or answers. The way to say thanks here is to upvote (or accept answers to your own questions).
– PolyGeo♦
Mar 13 '17 at 22:17
Welcome to GIS SE! As a new user be sure to take the Tour. Please do not say thank you in your questions or answers. The way to say thanks here is to upvote (or accept answers to your own questions).
– PolyGeo♦
Mar 13 '17 at 22:17
Welcome to GIS SE! As a new user be sure to take the Tour. Please do not say thank you in your questions or answers. The way to say thanks here is to upvote (or accept answers to your own questions).
– PolyGeo♦
Mar 13 '17 at 22:17
add a comment |
3 Answers
3
active
oldest
votes
You need to modify your function definition to include the length of the culvert:
def CulvertValue(Diameter, Length):
and modify the function call in the "Value = " box to pass the diameter and length fields:
CulvertValue(!Diameter!, !Length!)
add a comment |
You would need to add a second paramater, the field Length.
def CulvertValue(Diameter,Length):
I tried this and unfortunately still getting a processing error...
– Tom
Mar 13 '17 at 22:19
That's probably because of return "N/A", you need to return a number for a numeric field. Or it could be that you've changed the script but haven't changed the call, which should now be CulvertValue(!Diameter!,!shape_length!) or whatever your length field is. How accurate to you need to be? Pipes between manholes aren't exactly that length as they don't go to the centre of the manhole but stop at the edge.
– Michael Stimson
Mar 13 '17 at 22:22
Thanks for your comments. After replacing the N/A with a numeric value (or removing it) I still get an error message. I have collected data for hundreds of rural grid road culverts, measuring the length from end to end. I accomplished the value calculations in excel but it would save me a lot of time if I could do it in ArcMap.
– Tom
Mar 13 '17 at 22:30
You still need to return something, even if it's None - which should be <Null> in the table if your database supports null values. Do you get a specific error message in your results tab? resources.arcgis.com/en/help/main/10.2/index.html#//… (Ctrl + F and look for Results) this might contain a specific error which can be addressed specifically.
– Michael Stimson
Mar 13 '17 at 22:53
The error message is ERROR 000539: Error running expression: CulvertValue(10) Traceback (most recent call last): File "<expression>", line 1, in <module> TypeError: CulvertValue() takes exactly 2 arguments (1 given) Failed to execute (CalculateField).
– Tom
Mar 13 '17 at 23:19
|
show 1 more comment
Here's the updated code in case anyone needs this in the future
Script code:
def CulvertValue(Diameter,Length):
if Diameter > 0 and Diameter < 14:
return (Length*50)
elif Diameter > 14 and Diameter < 20:
return (Length*100)
else:
return None
Value
CulvertValue(!Diameter!,!Length!)
add a comment |
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%2f231943%2fif-then-field-calculator-return-calculations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to modify your function definition to include the length of the culvert:
def CulvertValue(Diameter, Length):
and modify the function call in the "Value = " box to pass the diameter and length fields:
CulvertValue(!Diameter!, !Length!)
add a comment |
You need to modify your function definition to include the length of the culvert:
def CulvertValue(Diameter, Length):
and modify the function call in the "Value = " box to pass the diameter and length fields:
CulvertValue(!Diameter!, !Length!)
add a comment |
You need to modify your function definition to include the length of the culvert:
def CulvertValue(Diameter, Length):
and modify the function call in the "Value = " box to pass the diameter and length fields:
CulvertValue(!Diameter!, !Length!)
You need to modify your function definition to include the length of the culvert:
def CulvertValue(Diameter, Length):
and modify the function call in the "Value = " box to pass the diameter and length fields:
CulvertValue(!Diameter!, !Length!)
answered Mar 13 '17 at 22:49
AdamAdam
1,324515
1,324515
add a comment |
add a comment |
You would need to add a second paramater, the field Length.
def CulvertValue(Diameter,Length):
I tried this and unfortunately still getting a processing error...
– Tom
Mar 13 '17 at 22:19
That's probably because of return "N/A", you need to return a number for a numeric field. Or it could be that you've changed the script but haven't changed the call, which should now be CulvertValue(!Diameter!,!shape_length!) or whatever your length field is. How accurate to you need to be? Pipes between manholes aren't exactly that length as they don't go to the centre of the manhole but stop at the edge.
– Michael Stimson
Mar 13 '17 at 22:22
Thanks for your comments. After replacing the N/A with a numeric value (or removing it) I still get an error message. I have collected data for hundreds of rural grid road culverts, measuring the length from end to end. I accomplished the value calculations in excel but it would save me a lot of time if I could do it in ArcMap.
– Tom
Mar 13 '17 at 22:30
You still need to return something, even if it's None - which should be <Null> in the table if your database supports null values. Do you get a specific error message in your results tab? resources.arcgis.com/en/help/main/10.2/index.html#//… (Ctrl + F and look for Results) this might contain a specific error which can be addressed specifically.
– Michael Stimson
Mar 13 '17 at 22:53
The error message is ERROR 000539: Error running expression: CulvertValue(10) Traceback (most recent call last): File "<expression>", line 1, in <module> TypeError: CulvertValue() takes exactly 2 arguments (1 given) Failed to execute (CalculateField).
– Tom
Mar 13 '17 at 23:19
|
show 1 more comment
You would need to add a second paramater, the field Length.
def CulvertValue(Diameter,Length):
I tried this and unfortunately still getting a processing error...
– Tom
Mar 13 '17 at 22:19
That's probably because of return "N/A", you need to return a number for a numeric field. Or it could be that you've changed the script but haven't changed the call, which should now be CulvertValue(!Diameter!,!shape_length!) or whatever your length field is. How accurate to you need to be? Pipes between manholes aren't exactly that length as they don't go to the centre of the manhole but stop at the edge.
– Michael Stimson
Mar 13 '17 at 22:22
Thanks for your comments. After replacing the N/A with a numeric value (or removing it) I still get an error message. I have collected data for hundreds of rural grid road culverts, measuring the length from end to end. I accomplished the value calculations in excel but it would save me a lot of time if I could do it in ArcMap.
– Tom
Mar 13 '17 at 22:30
You still need to return something, even if it's None - which should be <Null> in the table if your database supports null values. Do you get a specific error message in your results tab? resources.arcgis.com/en/help/main/10.2/index.html#//… (Ctrl + F and look for Results) this might contain a specific error which can be addressed specifically.
– Michael Stimson
Mar 13 '17 at 22:53
The error message is ERROR 000539: Error running expression: CulvertValue(10) Traceback (most recent call last): File "<expression>", line 1, in <module> TypeError: CulvertValue() takes exactly 2 arguments (1 given) Failed to execute (CalculateField).
– Tom
Mar 13 '17 at 23:19
|
show 1 more comment
You would need to add a second paramater, the field Length.
def CulvertValue(Diameter,Length):
You would need to add a second paramater, the field Length.
def CulvertValue(Diameter,Length):
answered Mar 13 '17 at 22:14
PiskrPiskr
601419
601419
I tried this and unfortunately still getting a processing error...
– Tom
Mar 13 '17 at 22:19
That's probably because of return "N/A", you need to return a number for a numeric field. Or it could be that you've changed the script but haven't changed the call, which should now be CulvertValue(!Diameter!,!shape_length!) or whatever your length field is. How accurate to you need to be? Pipes between manholes aren't exactly that length as they don't go to the centre of the manhole but stop at the edge.
– Michael Stimson
Mar 13 '17 at 22:22
Thanks for your comments. After replacing the N/A with a numeric value (or removing it) I still get an error message. I have collected data for hundreds of rural grid road culverts, measuring the length from end to end. I accomplished the value calculations in excel but it would save me a lot of time if I could do it in ArcMap.
– Tom
Mar 13 '17 at 22:30
You still need to return something, even if it's None - which should be <Null> in the table if your database supports null values. Do you get a specific error message in your results tab? resources.arcgis.com/en/help/main/10.2/index.html#//… (Ctrl + F and look for Results) this might contain a specific error which can be addressed specifically.
– Michael Stimson
Mar 13 '17 at 22:53
The error message is ERROR 000539: Error running expression: CulvertValue(10) Traceback (most recent call last): File "<expression>", line 1, in <module> TypeError: CulvertValue() takes exactly 2 arguments (1 given) Failed to execute (CalculateField).
– Tom
Mar 13 '17 at 23:19
|
show 1 more comment
I tried this and unfortunately still getting a processing error...
– Tom
Mar 13 '17 at 22:19
That's probably because of return "N/A", you need to return a number for a numeric field. Or it could be that you've changed the script but haven't changed the call, which should now be CulvertValue(!Diameter!,!shape_length!) or whatever your length field is. How accurate to you need to be? Pipes between manholes aren't exactly that length as they don't go to the centre of the manhole but stop at the edge.
– Michael Stimson
Mar 13 '17 at 22:22
Thanks for your comments. After replacing the N/A with a numeric value (or removing it) I still get an error message. I have collected data for hundreds of rural grid road culverts, measuring the length from end to end. I accomplished the value calculations in excel but it would save me a lot of time if I could do it in ArcMap.
– Tom
Mar 13 '17 at 22:30
You still need to return something, even if it's None - which should be <Null> in the table if your database supports null values. Do you get a specific error message in your results tab? resources.arcgis.com/en/help/main/10.2/index.html#//… (Ctrl + F and look for Results) this might contain a specific error which can be addressed specifically.
– Michael Stimson
Mar 13 '17 at 22:53
The error message is ERROR 000539: Error running expression: CulvertValue(10) Traceback (most recent call last): File "<expression>", line 1, in <module> TypeError: CulvertValue() takes exactly 2 arguments (1 given) Failed to execute (CalculateField).
– Tom
Mar 13 '17 at 23:19
I tried this and unfortunately still getting a processing error...
– Tom
Mar 13 '17 at 22:19
I tried this and unfortunately still getting a processing error...
– Tom
Mar 13 '17 at 22:19
That's probably because of return "N/A", you need to return a number for a numeric field. Or it could be that you've changed the script but haven't changed the call, which should now be CulvertValue(!Diameter!,!shape_length!) or whatever your length field is. How accurate to you need to be? Pipes between manholes aren't exactly that length as they don't go to the centre of the manhole but stop at the edge.
– Michael Stimson
Mar 13 '17 at 22:22
That's probably because of return "N/A", you need to return a number for a numeric field. Or it could be that you've changed the script but haven't changed the call, which should now be CulvertValue(!Diameter!,!shape_length!) or whatever your length field is. How accurate to you need to be? Pipes between manholes aren't exactly that length as they don't go to the centre of the manhole but stop at the edge.
– Michael Stimson
Mar 13 '17 at 22:22
Thanks for your comments. After replacing the N/A with a numeric value (or removing it) I still get an error message. I have collected data for hundreds of rural grid road culverts, measuring the length from end to end. I accomplished the value calculations in excel but it would save me a lot of time if I could do it in ArcMap.
– Tom
Mar 13 '17 at 22:30
Thanks for your comments. After replacing the N/A with a numeric value (or removing it) I still get an error message. I have collected data for hundreds of rural grid road culverts, measuring the length from end to end. I accomplished the value calculations in excel but it would save me a lot of time if I could do it in ArcMap.
– Tom
Mar 13 '17 at 22:30
You still need to return something, even if it's None - which should be <Null> in the table if your database supports null values. Do you get a specific error message in your results tab? resources.arcgis.com/en/help/main/10.2/index.html#//… (Ctrl + F and look for Results) this might contain a specific error which can be addressed specifically.
– Michael Stimson
Mar 13 '17 at 22:53
You still need to return something, even if it's None - which should be <Null> in the table if your database supports null values. Do you get a specific error message in your results tab? resources.arcgis.com/en/help/main/10.2/index.html#//… (Ctrl + F and look for Results) this might contain a specific error which can be addressed specifically.
– Michael Stimson
Mar 13 '17 at 22:53
The error message is ERROR 000539: Error running expression: CulvertValue(10) Traceback (most recent call last): File "<expression>", line 1, in <module> TypeError: CulvertValue() takes exactly 2 arguments (1 given) Failed to execute (CalculateField).
– Tom
Mar 13 '17 at 23:19
The error message is ERROR 000539: Error running expression: CulvertValue(10) Traceback (most recent call last): File "<expression>", line 1, in <module> TypeError: CulvertValue() takes exactly 2 arguments (1 given) Failed to execute (CalculateField).
– Tom
Mar 13 '17 at 23:19
|
show 1 more comment
Here's the updated code in case anyone needs this in the future
Script code:
def CulvertValue(Diameter,Length):
if Diameter > 0 and Diameter < 14:
return (Length*50)
elif Diameter > 14 and Diameter < 20:
return (Length*100)
else:
return None
Value
CulvertValue(!Diameter!,!Length!)
add a comment |
Here's the updated code in case anyone needs this in the future
Script code:
def CulvertValue(Diameter,Length):
if Diameter > 0 and Diameter < 14:
return (Length*50)
elif Diameter > 14 and Diameter < 20:
return (Length*100)
else:
return None
Value
CulvertValue(!Diameter!,!Length!)
add a comment |
Here's the updated code in case anyone needs this in the future
Script code:
def CulvertValue(Diameter,Length):
if Diameter > 0 and Diameter < 14:
return (Length*50)
elif Diameter > 14 and Diameter < 20:
return (Length*100)
else:
return None
Value
CulvertValue(!Diameter!,!Length!)
Here's the updated code in case anyone needs this in the future
Script code:
def CulvertValue(Diameter,Length):
if Diameter > 0 and Diameter < 14:
return (Length*50)
elif Diameter > 14 and Diameter < 20:
return (Length*100)
else:
return None
Value
CulvertValue(!Diameter!,!Length!)
answered Mar 13 '17 at 23:52
TomTom
284
284
add a comment |
add a comment |
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%2f231943%2fif-then-field-calculator-return-calculations%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
Welcome to GIS SE! As a new user be sure to take the Tour. Please do not say thank you in your questions or answers. The way to say thanks here is to upvote (or accept answers to your own questions).
– PolyGeo♦
Mar 13 '17 at 22:17