1

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?

  • 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
3

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

2

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
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.