Thursday 29 November 2018

arcgis desktop - If/Then Field Calculator Return Calculations



enter image description here


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?



Answer



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!)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...