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
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.
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
1 Answer 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
To replace Null values
replaceNull(!PASER_2016!)
def replaceNull(x):
if x is None:
return 0
else:
return x
Explore related questions
See similar questions with these tags.
.year
forif last_edited_date.year == 2016