0

I have been given the task to extract PASER scores from a comprehensive table of of PASER_byYear. I would like to take the time to create a view and query layers using SQL, but do to time constraints, I simply used the the SQL clause GUI in ArcGIS Pro to output this:

last_edited_date >= timestamp '2020-01-01 00:00:00' And last_edited_date < timestamp '2020-12-29 
00:00:00' OR last_edited_date >= timestamp '2016-01-01' AND last_edited_date < timestamp '2016-12-29'

The goal from here is to use Python subtract 2016 PASER scores from 2020 PASER scores for for identical road segments (Road_Segment_ID) and if the out put is -n multiply by -1 and if the output is +n multiply by -1.

Thus a simple analysis of road condition over time can be related an overlayed feature for scheduled paving in 2020.

I posted a question last week as ArcGIS Pro Python Field Calculating, and the admins and commenters helped immensely. Although I have been able to pick up on some things, I have a lot of learning about the languages/syntax necessary to make my job easier / be a better GIS professional.

The tricky thing with the current task is calling out only the year, then writing an expression that subtracts integers from the PASER_Score field based on the Last_Edited_Date field.

Expression:

PASER_2016(PASER_Score, last_edited_date)

Code Block:

def PASER_2016(PASER_Score, last_edited_date, x):
result = x
if !last_edited_date!.rsplit("/")[0] == '2016':
    result = !PASER_SCORE!
    return result

enter image description here

enter image description here

PASER_2016(PASER_Score, last_edited_date) 

def PASER_2016(PASER_Score, last_edited_date):
result = PASER_Score
if last_edited_date.year == 2016:
    return result

The expression checks out, but I am prompted an error message of "NameError": name 'PASER_Score' is not defined.

enter image description here

Expression:

PASER_2016(!PASER_Score!, !last_edited_date!)

Code Block:

def PASER_2016(PASER_Score, last_edited_date):
result = PASER_Score
if last_edited_date.year == 2016:
    return result

enter image description here

3
  • Date datatype. the whole timestamp functionality in SQL and Python has kind of thrown me off, have been scouring 3W schools to read up on how to navigate them in a simple fashion.
    – cheff_
    Jun 23, 2020 at 13:30
  • Expression checks out, but returns are Null. I am guessing that has to do with how I am defining the result?
    – cheff_
    Jun 23, 2020 at 14:08
  • 1
    I left out the .year for if last_edited_date.year == 2016
    – cheff_
    Jun 23, 2020 at 14:11

1 Answer 1

1
PASER_2016(!PASER_Score!, !last_edited_date!)

def PASER_2016(PASER_Score, last_edited_date):
result = PASER_Score
if last_edited_date.year == 2016:
    return result

enter image description here

To replace Null values

replaceNull(!PASER_2016!)

def replaceNull(x):
    if x is None:
       return 0
    else:
       return x

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.