arcpy.Geocode won't work inside script

6242
6
08-14-2014 01:25 PM
RobertChappe1
New Contributor II

Hello All,

  • Using ArcGIS 10.2.1 for Desktop on Windows 8.1

 

I have searched through the forums and couldn't find a resolution to this, though people have experienced similar problems:

 

I have a fairly simple script that will:

  1. take a user string input (an address)
  2. create a temp table to store the address
  3. geocode address
  4. more processing planned

 

I have tried:

  • running Geocode Addresses from the toolbox with the same inputs and it works
  • running the following piece of code from the python command line in arcmap work
  • arcpy.GeocodeAddresses_geocoding("C:/Users/v-robcha/Documents/ArcGIS/Default.gdb/GeocodeTemp","GIS Servers/geocoderfromESRI/World.GeocodeServer","SingleLine Address VISIBLE NONE","C:/Users/v-robcha/Documents/ArcGIS/Default.gdb/GeocodeTEMP_GeocodeAddresses_1","STATIC")

 

But when I try to use that EXACT line (hard coded file paths and all) in a script tool the geocoded results are empty. No matched or unmatched, just zero features. Furthermore, when I try to use variables for the file paths it returns the same result (nothing).

 

Below is the full script, I am quite frustrated at this point.

# Import arcpy module import arcpy import csv import os arcpy.env.workspace = r"C:/Users/v-robcha/Documents/ArcGIS/Default.gdb" ws = arcpy.env.workspace #address to be geocoded  address = arcpy.GetParameterAsText(0) #geocode service geocoder = r"GIS Servers\geocoderfromESRI\World.GeocodeServer" # dbf template for geocoding dbftemplate = "TemplateGeocode" # geocode output fn GeocodeAddressOut = "GeocodeAddresses_please" # user parameter for facilities (hotels, avis, etc) ## set up list of choices ## FacilitiesLocations = "AvisLocations_All1" # create table to store user input address arcpy.CreateTable_management(ws,"GeocodeTemp",dbftemplate,"#") ifields = ["OBJECTID", "Address"] irow = ["0", address] icur = arcpy.da.InsertCursor("GeocodeTemp", ifields) icur.insertRow(irow) # Process: Geocode Addresses arcpy.GeocodeAddresses_geocoding("GeocodeTemp", geocoder, "SingleLine Address VISIBLE NONE", GeocodeAddressOut, "STATIC") 
6 Replies
DanPatterson_Retired
MVP Emeritus

Haven't looked in detail, however, you don't mix raw format with forward slashes in

arcpy.env.workspace = r"C:/Users/v-robcha/Documents/ArcGIS/Default.gdb" 

get rid of the "r" in the path

RobertChappe1
New Contributor II

Good catch. However, that bad syntax on my part has never caused me issues.

But it also didn't solve this issue.

0 Kudos
RobertChappe1
New Contributor II

Bump.

Still struggling. Any help would be appreciated.

0 Kudos
KevinBrown2
New Contributor II

We're having the exact same problem.  Single Field Locator fails to match any addresses when run in python, but works fine when run in ArcMap.  Other Locators, like US Dual Range, work fine.  Went back to a machine with ArcGIS 10.1 installed and ran the script pointing to the same datasources and it works just fine.  Everything points to problems with the Single Field Locator being run as a python script outside ArcMap on a 10.2.1 client.

0 Kudos
KevinBrown2
New Contributor II

A coworker of mine, Darris Friend‌, found the problem.  We're using address points with the "General - Single Field" geocoder.  At 10.1 and earlier, the syntax for the python script was:

arcpy.GeocodeAddresses_geocoding({TableOfAddresses}, {GeocoderName}, "SingleKey {AddressFieldName} VISIBLE NONE", etc...)

At 10.2 it's now:

arcpy.GeocodeAddresses_geocoding({TableOfAddresses}, {GeocoderName}, "'Single Line Input' {AddressFieldName} VISIBLE NONE", etc...)

So SingleKey changed to 'Single Line Input'.  Make sure you include the single quotes.

by Anonymous User
Not applicable

After trying a lot of different 'solutions' to the generic Error 000010 that the geocoder throws when following the examples in the documentation, this one provided by @brownkj worked:

arcpy.GeocodeAddresses_geocoding(permittable, geocoder, "'Single Line Input' ADDRESS VISIBLE NONE", outFC)

With over 5177 Views at the time of writing this (~862 a year, 2.3 times a day since the original posting), I'm resurrecting this solution to tag Error 000010 so hopefully it helps others find a solution a lot faster than I did.

0 Kudos