0

I have a script I am attempting to debug so I can automate this task I have to do a weekly basis every monday morning which is tedious. I am very new to python and coding in general.

This is a very simple script, I am given a excel sheet with data (addresses) and I have to geocode them. I then must clip out the points to only a specific area (polygon) and then I select a specific 'series' which is a field type for its attribute and have that become its own layer so I can manipulate its symbology uniquely. Below is my script.

All the paths are correct however the "Y" drive is a network drive shared between the entire organization. When I first came across this error my table was located there so I moved it locally on my desktop and the error persists.

The table is not open or being used by any other program by myself or anyone else so there should not be a file lock on it.

Anyone have any suggestions?

My code is below.

# Import arcpy module
import arcpy
import os

#Change user "jhead" to your local group username (amiller), this creates a temp folder on your desktop
#because the path for geocoding will not save outputbecause of spaces in path
newpath = r'C:\Users\jhead\Desktop\Temp'
if not os.path.exists(newpath):
    os.makedirs(newpath)

# Local variables:
Sheet1_ = "Sheet1$"
LakeWorth_Addressing_Parcels = "Y:\\Department for Community Sustainability\\GIS Division\\Internal Division Files\\GIS Addressing Tools\\LakeWorth_Addressing_Parcels"
table1_xlsx = "C:\Users\jhead\Desktop\table1.xlsx"
Geocode1_shp = "Y:\\Department for Community Sustainability\\GIS Division\\Internal Division Files\\Division Work Folders\\ABT\\New_project\\TempData\\Geocode1.shp"
LakeWorth_DBO_Municipal_Boundary_Poly_2016 = "LakeWorth.DBO.Municipal_Boundary_Poly_2016"
clip1_shp = "Y:\\Department for Community Sustainability\\GIS Division\\Internal Division Files\\Division Work Folders\\ABT\\New_project\\TempData\\clip1.shp"
liquor_select_shp = "Y:\\Department for Community Sustainability\\GIS Division\\Internal Division Files\\Division Work Folders\\ABT\\New_project\\TempData\\liquor_select.shp"

# Process: Geocode Addresses
arcpy.GeocodeAddresses_geocoding(Sheet1_, LakeWorth_Addressing_Parcels, "Street ADDRESS_LINE1 VISIBLE NONE;City City VISIBLE NONE;ZIP ZIP VISIBLE NONE", Geocode1_shp, "STATIC")

# Process: Clip
arcpy.Clip_analysis(Geocode1_shp, LakeWorth_DBO_Municipal_Boundary_Poly_2016, clip1_shp, "")

# Process: Select
arcpy.Select_analysis(clip1_shp, liquor_select_shp, "\"SERIES\" = '3PS'")

The error I am recieving is: **

  • Runtime error Traceback (most recent call last): File "", line 29, in File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\geocoding.py", line 212, in GeocodeAddresses raise e ExecuteError: ERROR 000006: Could not open the address table. Failed to execute (GeocodeAddresses).

** I would like to add that when I perform this tool manually (toolbox and select the tool and add the inputs manually) everything works perfectly. it grabs the tables and geocodes all the addresses no issues. So not sure why this is happening.

I think maybe its due to this geocode tool having multiple inputs, sheet, the table and the addressing locator, but in the script its missing the table inut and the model shows a dotted line connected rather solid line. model

  • 1
    Im not sure if this has anything to do with it but I don't see your path for table1_xlsx escaped out like your other paths table1_xlsx = "C:\Users\jhead\Desktop\table1.xlsx" – kttii Dec 16 '16 at 15:12
  • What do you mean escaped out? I did just noticed that the variable had "_xlsx" added to the end of "table1" which the actual file is not called that I just renamed the variable to "table1" however same error after I ran it again. – NULL.Dude Dec 16 '16 at 15:14
  • it just weird how it works fine when I drag the tool into the model and run it perfectly. export the code snippet and now its an error saying it cant find it? :/ – NULL.Dude Dec 16 '16 at 15:16
  • 1
    look at the variable path for Geocode1_shp... it contains a double "\\" rather than a single "\" in the path... change table1_xlsx to table1_xlsx = "C:\\Users\\jhead\\Desktop\\table1.xlsx" – kttii Dec 16 '16 at 15:17
  • 1
    or I beleive you can escape your path like newpath is and change table1_xlsx to table1_xlsx = r'C:\Users\jhead\Desktop\table1.xlsx' – kttii Dec 16 '16 at 15:26
1

I figured out what was causing the issue and as I suspected it was the 3 inputs I had for the geocode addresses. Instead I had to convert the excel file into a .dbf files and use that as an input. the below code worked for me as expected.

# Import arcpy module
import arcpy
import os

#Change user "jhead" to your local group username (amiller), this creates a temp folder on your desktop
#because the path for geocoding will not save outputbecause of spaces in path
newpath = r'C:\Users\jhead\Desktop\Temp'
if not os.path.exists(newpath):
    os.makedirs(newpath)

# Local variables:
table2_dbf = "Y:\\Department for Community Sustainability\\GIS Division\\Internal Division Files\\Division Work Folders\\ABT\\New_project\\Tables\\table3.dbf"
LakeWorth_Addressing_Parcels = "Y:\\Department for Community Sustainability\\GIS Division\\Internal Division Files\\GIS Addressing Tools\\LakeWorth_Addressing_Parcels"
geocode1_shp = "Y:\\Department for Community Sustainability\\GIS Division\\Internal Division Files\\Division Work Folders\\ABT\\New_project\\TempData\\geocode1.shp"
LakeWorth_DBO_Municipal_Boundary_Poly_2016 = "LakeWorth.DBO.Municipal_Boundary_Poly_2016"
clip1_shp = "Y:\\Department for Community Sustainability\\GIS Division\\Internal Division Files\\Division Work Folders\\ABT\\New_project\\TempData\\clip1.shp"
liquor_Stores_shp = "Y:\\Department for Community Sustainability\\GIS Division\\Internal Division Files\\Division Work Folders\\ABT\\New_project\\TempData\\liquor_Stores.shp"

# Process: Geocode Addresses
arcpy.GeocodeAddresses_geocoding(table2_dbf, LakeWorth_Addressing_Parcels, "Street ADDRESS_LI VISIBLE NONE;City City VISIBLE NONE;ZIP ZIP VISIBLE NONE", geocode1_shp, "STATIC")

# Process: Clip
arcpy.Clip_analysis(geocode1_shp, LakeWorth_DBO_Municipal_Boundary_Poly_2016, clip1_shp, "")

# Process: Select
arcpy.Select_analysis(clip1_shp, liquor_Stores_shp, "\"SERIES\" = '3PS'")

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.