The problem is, I would like to get a python script that can run the service area tool and calculate three diffrent sets of service areas around the hospitals and after that, compare the coverages of the three diffrent service area rings in terms of the number of counties covered.
Hi Frank,How do you want this returned? For example, do you want the service area feature class to have a field that shows a count of how many counties it covers?
import arcpy from arcpy import env env.workspace = r"C:\temp\test.gdb" env.overwriteOutput = 1 serviceAreas = "ServiceAreas" counties = "Counties" arcpy.AddField_management(serviceAreas, "COUNT", "LONG") with arcpy.da.UpdateCursor(serviceAreas, ["OBJECTID", "COUNT"]) 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 cursor.updateRow(row)
Here is an example on how to get the number of counties each service area intersects:I'm not sure what you mean by 'calculate percentage of the number of fields covered' or 'get a buffreing ring to compare to the service areas in the same manner'. Could you elaborate?
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.
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.