Original User: JSkinn3To find the percentage, you will just need to add a couple more lines of code:import arcpy
from arcpy import env
env.overwriteOutput = 1
env.workspace = r"C:\temp\test.gdb"
serviceAreas = "ServiceAreas"
counties = "Counties"
arcpy.AddField_management(serviceAreas, "COUNT", "LONG")
arcpy.AddField_management(serviceAreas, "PERCENTAGE", "DOUBLE")
result = arcpy.GetCount_management(counties)
countyCount = int(result.getOutput(0))
with arcpy.da.UpdateCursor(serviceAreas, ["OBJECTID", "COUNT", "PERCENTAGE"]) as cursor:
for row in cursor:
OID = row[0]
arcpy.MakeFeatureLayer_management(serviceAreas, "SA_lyr", "OBJECTID = " + str(OID))
arcpy.MakeFeatureLayer_management(counties, "County_lyr")
arcpy.SelectLayerByLocation_management("County_lyr", "INTERSECT", "SA_lyr", "#", "NEW_SELECTION")
result = arcpy.GetCount_management("County_lyr")
count = int(result.getOutput(0))
row[1] = count
row[2] = count / float(countyCount) * 100
cursor.updateRow(row)
On the buffering, I wanted to also compare 20km buffer, 3okm buffer etc for the same counties
Do you want to buffer the counties or the hospitals? One way to do this is to buffer the county/hospital and then join this to your service area feature class. You could then create a third field and calculate the difference by dividing the area of the service area by the buffered county/hospital.