2

I'm attempting a research project in which I am seeking to categorize a municipality's Property Use Codes as Generalized Land Uses. For example, "AGRII - Developed Farmland" and "INDGR - Grain Elevator" are both "Agricultural" land uses. I have created a new field "Land Use Category" and used the following code:

PLY_AssessmentParcels_LandUseCategory = MyFunction(!Assessment_Parcels_CSV_csv_Property_Use_Code!) _

def MyFunction(s):
   if ("AGRII" or "INDGR") in s:
      return "Agricultural"
   elif ("VRES2" or "VRES1" or "VINDU" or "VCOMM" or "VAPRK" or "VAGRI" or "CNVAC") in s:
      return "Vacant"
   elif ("STATR" or "SKYWK" or "RAILR" or "ARPRT" or "CMPST" or "CMPSP") in s:
      return "Transportation"
   elif ("RESTR" or "RESSU" or "RESSS" or "RESSD" or "RESRM" or "RESRH" or "RESOT" or "RESMU" or "RESMH" or "RESMC" or "RESMB" or "RESGC" or "RESAP" or "RESDU" or "RESAM" or "CNAPT" or "CNCMP" or "CNDRH" or "CNRES") in s:
      return "Residential"
   elif ("CMCMU" or "CMFBK" or "CMHBH" or "CMHHO" or "CMHMO" or "CMMRH" or "CMOFF" or "CMOGV" or "CMOMC" or "CMRCS" or "CMRCV" or "CMRNS" or "CMRRE" or "CMRRS" or "CMRSM" or "SMRST" or "CMRWC" or "CMVCD" or "CMVSR") in s:
      return "Commercial"
   elif ("CNCOM" or "REFRL" or "CMSTP") in s:
      return "Other"
   elif ("PIRST" or "PIRRT" or "PIRRI" or "PIRPO" or "PIRPK" or "PIRMU" or "PIRGC" or "PIRCC" or "PIRBA" or "PIRAR" or "PIEBM" or "PIECS" or "PIETC") in s:
      return "Recreational"
   elif ("CNIND" or "HYDSS" or "INMHM" or "INMLM" or "INMMI" or "INMMU" or "INWSC" or "INWWH" or "MTSSS" or "TRAPI") in s:
      return "Industrial"
   elif ("PIEMA" or "PIICH" or "PIIDC" or "PIIGC" or "PIIHO" or "PIIMB" or "PIINH" or "PIIPF" or "PIIRE" or "PIISC" or "PIIUC" or "PIMCE" or "PIMFH" or "PIMLI") in s:
      return "Institutional"
   else:
      return

When I run the above code, I often received an error stating "Cannot acquire lock". After restarting ArcGIS Pro, I can usually get one good run out in which the process completes successfully in about 40 seconds. The problem is that nothing has changed in my attribute table. Please note, I'm dealing with about 212,000 records. The file is stored in a .gdb and I have re-created the feature class in the .gdb with the same issues. System specs are very reasonable (i7 7800k, 32gb ram, GTX 1080i, etc.)

Any ideas?

Screenshot of attribute table

6
  • 1
    Can you try on a few records? I was having a similar problem last week. I verified with a small case, a few records and one statement, then added the rest. Maybe try selecting a few rows of "AGRII" and run with if ("AGRII") in s: return "Agricultural". See if that gives you some success.
    – timlohnes
    Commented Dec 7, 2018 at 23:44
  • 1
    Can be as simple as setting environment extent.
    – FelixIP
    Commented Dec 7, 2018 at 23:54
  • 1
    Are you sure the field name is !Assessment_Parcels_CSV_csv_Property_Use_Code!, and not the field alias? You should return something at the last else, like "ERROR" and see if fields are filled with this. Otherwise the function will return a None, which might not work if field is not nullable.
    – Bera
    Commented Dec 8, 2018 at 7:47
  • Thanks for the feedback everyone. @BERA thanks for the suggestion - it is filling everything in as 'Error'. Definitely something wrong with my code. Commented Dec 8, 2018 at 18:14
  • 1
    Well then it is doing something which is better than nothing. Could you add a screenshot showing the attribute table? Try adding s = s.strip() before the if lines. It will strip whitespaces. You know that python is case sensitive right? So AAA is not the same as aaa
    – Bera
    Commented Dec 8, 2018 at 19:16

1 Answer 1

1

I figured it out. I switched to the following any() command:

def MyFunction(s):
    if any(x in s for x in ["AGRII", "INDGR"]):
        return "Agricultural"

...

else:
    return "Error"

My hunch is that I am trying to check if a whole Tuple (such as "('AGRII' or 'INDGR')" is contained within a string (which will always return false). Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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