I am trying to join a point layer of students to a polygon layer that shows the school they should attend. However, several polygons have two attendance numbers. Kindergarten thru 2nd graders should attend one school (starting with 262), and 3-5 graders attend another (starting with 395). Is there a way to set up a spatial join to join based on a rule with the grade attribute?
I'm sure there's a more sophisticated way to do this, but the quickest way that comes to mind is to do a normal spatial join, then populate a field with the field calculator.
I'm not sure what your data looks like, but assuming the layers have the following fields:
Polygon layer
Points layer
The spatial join should create a feature class with all four of those fields. The "student_school" field could then be populated using conditional statements in the field calculator.
Using the Python parser:
Pre-Logic Script Code:
def returnSchool(st_grade,sch_K_2,sch_3_5):
if (st_grade == 'K' or st_grade == '1' or st_grade =='2'):
return sch_K_2
elif (st_grade == '3' or st_grade == '4' or st_grade == '5'):
return sch_3_5
else:
return "Invalid"
student_school =
returnSchool(!student_grade!,!schoolNum_K_2!,!schoolNum_3_5!)