Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver_sandbox.py", line 21, in File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver_sandbox.py", line 12, in countHospitals File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\analysis.py", line 692, in Buffer raise e arcgisscripting.ExecuteError: ERROR 000210: Cannot create output c:\Scripts\Lab 6 Datauffers.shp Failed to execute (Buffer).
The code should perform the following tasks:
- Create 3 mile buffer around the schools in the input shapefile
- Count number of hospitals in each school's buffered area using Spatial Join tool
- Print the name of each school with zero (0) hospitals based on the "Join_Count" field from the resulting feature class from "Spatial Join" using search cursor
My code:
import arcpy
work = arcpy.env.workspace = raw_input("Enter the full workspace path: ")
sType = ("HIGH SCHOOL")
result = "buffer_shp"
def countHospitals(work, sType, result):
buffering = "c:\Scripts\Lab 6 Data\buffers"
output = "output.shp"
# Process: Buffer
arcpy.Buffer_analysis(output, buffers, "3 Miles", "", "", "NONE", "", "")
# Process: Spatial Join
arcpy.SpatialJoin_analysis(buffers, Hospitals, sJoin_shp, "JOIN_ONE_TO_ONE", "KEEP_ALL", "OBJECTID_1 \"OBJECTID_1\" true true false 10 Long 0 10 ,First,#,C:\\Scripts\\Lab 6 Data\\buffer.shp,OBJECTID_1,-1,-1;OBJECTID_2 \"OBJECTID_2\" true true false 10 Long 0 10 ,First,#,C:\\Scripts\\Lab 6 Data\\buffer.shp,OBJECTID_2,-1,-1;OBJECTID \"OBJECTID\" true true false 9 Long 0 9 ,First,#,C:\\Scripts\\Lab 6 Data\\buffer.shp,OBJECTID,-1,-1;NAME \"NAME\" true true false 27 Text 0 0 ,First,#,C:\\Scripts\\Lab 6 Data\\buffer.shp,NAME,-1,-1;ADDRESS \"ADDRESS\" true true false 28 Text 0 0 ,First,#,C:\\Scripts\\Lab 6 Data\\buffer.shp,ADDRESS,-1,-1;FACILITY \"FACILITY\" true true false 17 Text 0 0 ,First,#,C:\\Scripts\\Lab 6 Data\\buffer.shp,FACILITY,-1,-1;DISTRICT \"DISTRICT\" true true false 16 Text 0 0 ,First,#,C:\\Scripts\\Lab 6 Data\\buffer.shp,DISTRICT,-1,-1;VERIFIED \"VERIFIED\" true true false 2 Text 0 0 ,First,#,C:\\Scripts\\Lab 6 Data\\buffer.shp,VERIFIED,-1,-1;BUFF_DIST \"BUFF_DIST\" true true false 19 Double 0 0 ,First,#,C:\\Scripts\\Lab 6 Data\\buffer.shp,BUFF_DIST,-1,-1;ORIG_FID \"ORIG_FID\" true true false 10 Long 0 10 ,First,#,C:\\Scripts\\Lab 6 Data\\buffer.shp,ORIG_FID,-1,-1;NAME_1 \"NAME_1\" true true false 33 Text 0 0 ,First,#,Hospitals,NAME,-1,-1;ADDRESS_1 \"ADDRESS_1\" true true false 28 Text 0 0 ,First,#,Hospitals,ADDRESS,-1,-1;CITY \"CITY\" true true false 7 Text 0 0 ,First,#,Hospitals,CITY,-1,-1;STATE \"STATE\" true true false 7 Text 0 0 ,First,#,Hospitals,STATE,-1,-1;ZIPCODE \"ZIPCODE\" true true false 11 Text 0 0 ,First,#,Hospitals,ZIPCODE,-1,-1;PHONE_NUMB \"PHONE_NUMB\" true true false 17 Text 0 0 ,First,#,Hospitals,PHONE_NUMB,-1,-1;AV_ADD \"AV_ADD\" true true false 28 Text 0 0 ,First,#,Hospitals,AV_ADD,-1,-1;AV_STATUS \"AV_STATUS\" true true false 1 Text 0 0 ,First,#,Hospitals,AV_STATUS,-1,-1;AV_SCORE \"AV_SCORE\" true true false 6 Long 0 6 ,First,#,Hospitals,AV_SCORE,-1,-1;AV_SIDE \"AV_SIDE\" true true false 1 Text 0 0 ,First,#,Hospitals,AV_SIDE,-1,-1;FullAddr \"FullAddr\" true true false 254 Text 0 0 ,First,#,Hospitals,FullAddr,-1,-1", "CONTAINS", "", "")
with arcpy.da.UpdateCursor(sJoin_shp, ['JOIN_COUNT', 'NAME']) as uCursor:
for row in uCursor:
if row[0] == 0:
print ("The following schools have zero hospitals within a 3-mi radius "), row[1]
countHospitals(work, sType, result)
My code wont accept where I want to store my buffer output. I think. Any ideas as to the problem?