If/then Field Calculations

3083
6
Jump to solution
01-11-2021 06:39 AM
Labels (2)
JamesWenyon
Occasional Contributor

Good Morning Everyone,

I have some experience with Pro but I am unfamiliar with writing Python and Arcade expressions.

I have a group of parcels and I am attempting to make a field calculation to exclude certain parcels like lakes right of ways, etc. The result of the field calculations will be a field that says exclude for the parcels I wish to exclude. Does anyone have any tips or resources for doing an if, then statement for a filed calculation?

0 Kudos
2 Solutions

Accepted Solutions
DavidPike
MVP Frequent Contributor

What does the data table look like, and what would be the intended result of the field calculation for each type?

Slightly more advanced or verbose field calculations are done by creating a function in the 'code block' then passing in field arguments to execute it.

An if, else statement might look something like this in the function:

def categorize_stuff(my_field):
    if my_field in ('Lake', 'Right of Way', 'Shark_Infested_Custard'):
        return None
    else:
        return my_field

View solution in original post

DavidPike
MVP Frequent Contributor

Sure, if you're planning on just doing the calculation once (e.g. for data that's not changing every week) you may be better off doing Joe's method:

Select by Attribute, where field = "Lake" OR field = 'Right of Way' ...

then running a simple calculate field to set all selected records to 'exclude'.

or if you plan to run it regularly you may want to use a field calculation from the outset:

 

def categorize_stuff(my_field):
    if my_field in ('Lake', 'Right of Way', 'Shark_Infested_Custard'):
        return 'exclude'
    else:
        return None

 

You would probably throw in some logic to exclude already calculated records (for when you next run it) and also some spell checking (remove case sensitivity etc.) 

View solution in original post

6 Replies
DavidPike
MVP Frequent Contributor

What does the data table look like, and what would be the intended result of the field calculation for each type?

Slightly more advanced or verbose field calculations are done by creating a function in the 'code block' then passing in field arguments to execute it.

An if, else statement might look something like this in the function:

def categorize_stuff(my_field):
    if my_field in ('Lake', 'Right of Way', 'Shark_Infested_Custard'):
        return None
    else:
        return my_field
JamesWenyon
Occasional Contributor

thanks for your reply David!

I attached a picture of what my attribute table looks like. The intended result of the calculation will be a filed that will specify what parcels would be excluded from development. For example If i Filed calculated an if then statement for if the landusedesc is lake then return a text that says exclude. Then when someone else is analyzing the file as a spreadsheet they can see the exclude field and know not to handle the lake parcel that was excluded.

0 Kudos
DavidPike
MVP Frequent Contributor

Sure, if you're planning on just doing the calculation once (e.g. for data that's not changing every week) you may be better off doing Joe's method:

Select by Attribute, where field = "Lake" OR field = 'Right of Way' ...

then running a simple calculate field to set all selected records to 'exclude'.

or if you plan to run it regularly you may want to use a field calculation from the outset:

 

def categorize_stuff(my_field):
    if my_field in ('Lake', 'Right of Way', 'Shark_Infested_Custard'):
        return 'exclude'
    else:
        return None

 

You would probably throw in some logic to exclude already calculated records (for when you next run it) and also some spell checking (remove case sensitivity etc.) 

DanPatterson
MVP Esteemed Contributor

You can save and reload calculator expressions... it is useful in many ways whether you are doing field calculations once or many... even I have a catalog of them 😉


... sort of retired...
JoeBorgione
MVP Emeritus

You can apply your calculation to a selected set of records; what if you first select your parcels where

ParcelType does not contain  the text Lakes 

or

ParcelType does not contain the text ROW

etc...

 

That should just about do it....