0
def Assign(csdname, cdname, ccsname, zone):
if csdname == "Oshawa" or csdname == "Whitby":
    return "70"
elif csdname == "Toronto":
    return "71a"
elif csdname == "Mississauga" or csdname == "Brampton":
    return "71b"
elif csdname == "Hamilton" and cdname == "Hamilton":
    return "72"
elif csdname == "Ottawa" or csdname == "Vanier" or csdname == "Rockcliffe Park":
    return "73a"
elif csdname == "Kanata" or csdname == "Nepean" or csdname == "Cumberland" or csdname == "Gloucester":
    return "73b"
elif csdname == "Windsor" or csdname == "Tecumseh" or csdname == "St. Clair Beach" or csdname == "Sandwhich West":
    return "74a"
elif csdname == "London":
    return "74b"
elif csdname == "Niagara Falls":
    return "75a"
elif csdname == "St. Catharines":
    return "75b"
elif csdname == "Burlington" or csdname == "Oakville":
    return "76a"
elif csdname == "Kitchener" or csdname == "Cambridge" or csdname == "Waterloo":
    return "76b"
elif csdname == "Sudbury":
    return "77a"
elif csdname == "Sault Ste. Marie":
    return "77b"
elif zone == "78a":
    #78 Northern Ontario A
    return "78a"
elif csdname == "Sudbury" or csdname == "Timiskaming":
    #78 Northern Ontario B
    return "78b"
elif cdname == "Algoma" or cdname == "Cochrane" or cdname == "Kenora":
    #78 Northern Ontario C
    return "78c"
elif csdname == "Thunder Bay":
    return "79b"
elif zone == "West 85th Meridian":
    return "79a"
else:
    return "70"

Assign(!CSDNAME!, !CDNAME!, !CCSNAME!, !ZONE!)

Trying to simplify the Python script above but not sure how to best do it. Ideally, I'd also like to figure out how to print which of the if conditions are not met for manual review later.

5

If you want to stick to python you can use a dictionary

mydict= {
    'Oshawa': '70',
    'Toronto': '71a',
    'Mississauga': '85',
    'Kitchener': '77',
    'Sudbury': '65'
}
if !CSDNAME! in mydict.keys():
    !ZONE! = (mydict[!CSDNAME!])
else:
  #do something to flag

Or you could create a table and districts and names and do a join. A left outer join (keep all) is very easy in arcpy and after that just look for nulls in the zone. https://pro.arcgis.com/EN/PRO-APP/TOOL-REFERENCE/DATA-MANAGEMENT/add-join.htm field.

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.