1

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?

3

I see two issues here:

buffering = "c:\Scripts\Lab 6 Data\buffers"
output = "output.shp" 
# Process: Buffer
arcpy.Buffer_analysis(output, buffers, "3 Miles", "", "", "NONE", "", "")
  1. you need to either escape your slashes "c:\\Scripts\\Lab 6 Data\\buffers" or (my preferred method) mark them as a raw string r"c:\Scripts\Lab 6 Data\buffers"
  2. You have a variable buffering but your arcpy.Buffer_analysis() line references a variable buffers which I do not see in your script at all. You may need to change the Buffer tool to reference buffering instead.
1

try

buffering = r'c:\Scripts\Lab6Data\buffers'

the use of r before the path string makes python to take the path string as is, while otherwise you may have to use \ in other to override the escape sequence. Another tip is to try to avoid spaces in your file names. Sometimes this lead to confusion, and the code does not work properly.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

-2

buffering = "c:\Scripts\Lab 6 Data\buffers"

It looks like the \b in your path is getting interpolated into a regex search pattern. Try changing to single quotes:

buffering = 'c:\Scripts\Lab 6 Data\buffers'

  • Didnt work. Same error. – A_Worthy Feb 1 '17 at 19:59
  • Ugh, I confused perl and python, I deserve the negative votes. – Mintx Feb 1 '17 at 21:40
  • @Mintx an edit may attract some upvotes – Midavalo Feb 2 '17 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.