2

I've been using ArcGIS Pro over ArcMap recently because ArcMap is giving me some incorrect summary statistics that I use to populate a data field in a number of feature classes. The problem is that I'm not very familiar with Python and I haven't been able to translate my VB Script expressions into Python.

The expression considers two data fields from the summary statistics table for each unique Site ID and either gives the study panel number [LAST_panel], or the evaluation status [LAST_Eval_Status] if the status is either "Dormant" or "Reject" and enters a value into a "Panel_Status" field in a point feature class.

Pre-Logic Script Code:

dim PS

if [PARK_GRTS_EVAL_Statistics.LAST_Eval_Status]="Dormant" then
  PS="Dormant"
elseif [PARK_GRTS_EVAL_Statistics.LAST_Eval_Status]="Reject" then
  PS="Reject"
else PS= [PARK_GRTS_EVAL_Statistics.LAST_panel]
end if

PARK_PCM_GRTS.Panel_Status =

PS

In the expression above, PARK is a stand-in for a location code, since there are multiple locations and datasets I'm working with. The workaround I've been using is to create the summary statistics in ArcGIS Pro and then doing the field calculator in ArcMap 10.5 but it would be more efficient if I could do it all in ArcGIS Pro. Plus it would benefit me to learn a bit of Python.

How do I translate this into Python 3?

3

If I understand your question to simply be how to migrate the VB code into Python, see below. It's all basically the same, just minor differences in the syntax. The biggest syntax difference is the!fieldname!. This is how, using Python in the Calc Field tool you pass fields within the dataset into the code block.

Using Calc Field, you'll want to set Panel_Status == ifelse(!Eval_Status!, !Last_Panel!)

Code block:

def ifelse(evalstat, lastpanel):
    if evalstat == "Dormant":
        return "Dormant"
    elif evalstat == "Reject":
        return "Reject"
    else:
        return lastpanel

Results:

enter image description here

  • Thanks, this is what I was looking for. Those little differences in syntax are hard to find in most tutorials without doing a full lesson. Particularly when it comes to working specifically with data in ArcGIS. I'll eventually get around to becoming fluent in Python once my workload eases up a bit. – Carlos_S Jul 6 '18 at 14:29

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.