Hi all, so basically there are some cases where in the If statement shown below, the script is returning nothing where it should be returning an error message, and its because the input field value is null.
E.G., if "Ramp_Width" was "<Null>" in the table, and "Lvl_Width" was 40, the script returns nothing, when it should be returning "LL Width too small". How can I alter my code so that it ignores the <Null> value in the "Ramp_Width" field?
RampQA(!rampcond!, !ramp_type!, !ramp_width!, !lvl_width!, !ramp_rslope!, !ramp_cslope!, !lvl_length!, !lvl_slope!, !lvl_cslope!, !left_twidth!, !left_tslope!, !left_txslope!, !right_twidth!, !right_tslope!, !right_txslope!, !flareleft_slope!, !flareright_slope!, !cleararea_slope!, !cleararea_xslope!, !cleararea_travellane!, !cleararea_crosswalk!)
- copy everything below into second dialogue box called "Code Block":
def RampQA(rampcond, ramp_type, ramp_width, lvl_width, ramp_rslope, ramp_cslope, lvl_length, lvl_slope, lvl_cslope, left_twidth, left_tslope, left_txslope, right_twidth, right_tslope, right_txslope, flareleft_slope, flareright_slope, cleararea_slope, cleararea_xslope, cleararea_travellane, cleararea_crosswalk):
if rampcond == "Poor":
return "Ramp Condition Poor"
elif (ramp_width < 48):
return "Ramp width too small"
elif (lvl_width < 48):
return "LL width too small"
elif (ramp_type == "Perpendicular" and ramp_rslope > 8.3 or ramp_type == "Continuous" and ramp_rslope > 8.3):
return "Ramp slope too big"
elif (ramp_type == "Perpendicular" and ramp_cslope > 2.1 or ramp_type == "Continuous" and ramp_cslope > 2.1):
return "Ramp X-slope too big"
elif (lvl_length < 48):
return "LL length too small"
elif (lvl_slope > 2.1):
return "LL Slope too big"
elif (lvl_cslope > 2.1):
return "LL X-slope too big"
elif (ramp_type == "Parallel" and left_twidth < 48 or ramp_type == "Blended" and left_twidth < 48):
return "Left T-width too small"
elif (ramp_type == "Parallel" and left_tslope > 8.3 or ramp_type == "Blended" and left_tslope > 8.3):
return "Left T-slope too big"
elif (ramp_type == "Parallel" and left_txslope > 2.1 or ramp_type == "Blended" and left_txslope > 2.1):
return "Left T-X slope too big"
elif (ramp_type == "Parallel" and right_twidth < 48 or ramp_type == "Blended" and right_twidth < 48):
return "Right T-Width too small"
elif (ramp_type == "Parallel" and right_tslope > 8.3 or ramp_type == "Blended" and right_tslope > 8.3):
return "Right T-Slope Error too big"
elif (ramp_type == "Parallel" and right_txslope > 2.1 or ramp_type == "Blended" and right_txslope > 2.1):
return "Right T-X Slope too big"
elif (ramp_type == "Perpendicular" and flareleft_slope > 10):
return "Left Flare Slope Error too big"
elif (ramp_type == "Perpendicular" and flareright_slope > 10):
return "Right Flare Slope Error too big"
elif (cleararea_slope > 5):
return "Clear Area Slope too big"
elif (cleararea_xslope > 2.1):
return "Clear Area X Slope too big"
elif (cleararea_travellane is None or cleararea_travellane is "No"):
return "Clear Area Travel Lane Error"
elif (cleararea_crosswalk is None or cleararea_crosswalk is "No"):
return "Clear Area Crosswalk Error"
One issue I see, that likely isn't the same issue you are asking about, are the following lines:
elif (cleararea_travellane is None or cleararea_travellane is "No"):
return "Clear Area Travel Lane Error"
elif (cleararea_crosswalk is None or cleararea_crosswalk is "No"):
return "Clear Area Crosswalk Error"
The code won't generate an error, but it will generate a SyntaxWarning because checking variable values should be done with the equality operator (==) and not the identity operator (is). When checking for None, the identity operator is used because None is a singleton representing nothing.
There are several places where TypeError can occur. For example,
elif (lvl_width < 48):
return "LL width too small"
will generate an error if lvl_width is None because None can't be used in an ordering operation like less-than or greater-than.
thanks i didnt notice that about my last few lines of the script!