Create a Address Locator

1211
7
11-28-2018 11:29 AM
NickXu
by
New Contributor

I'm trying to create a Gazetteer style address locator by python script as:

import arcpy
arcpy.CreateAddressLocator_geocoding(
 in_address_locator_style="General Gazetteer",
 in_reference_data="(folder)\address2.gdb\ADDRESS_LOCATOR 'Primary Table'",
 in_field_map="'Feature ID' OBJECTID VISIBLE NONE;'*Place Name' ADDRESS VISIBLE NONE;Category <None> VISIBLE NONE;Type <None> VISIBLE NONE;Tags <None> VISIBLE NONE;Description <None> VISIBLE NONE;'3-Digit Language Code' <None> VISIBLE NONE;'2-Digit Language Code' <None> VISIBLE NONE;Rank <None> VISIBLE NONE;Neighborhood <None> VISIBLE NONE;City <None> VISIBLE NONE;County <None> VISIBLE NONE;State <None> VISIBLE NONE;'State Abbreviation' <None> VISIBLE NONE;Country <None> VISIBLE NONE;'Country Abbreviation' <None> VISIBLE NONE;'Street Address' <None> VISIBLE NONE;'Full Address' <None> VISIBLE NONE;'Primary Phone' <None> VISIBLE NONE;'Primary URL' <None> VISIBLE NONE;'Display X' <None> VISIBLE NONE;'Display Y' <None> VISIBLE NONE;'Min X value for extent' <None> VISIBLE NONE;'Max X value for extent' <None> VISIBLE NONE;'Min Y value for extent' <None> VISIBLE NONE;'Max Y value for extent' <None> VISIBLE NONE;'Additional Field' USER_DATA VISIBLE NONE",
 out_address_locator="(out_put_folder)\test.GeocodeServer",
 config_keyword="",
 enable_suggestions="ENABLED"
 )

but got error as: 

Traceback (most recent call last):
File "<module1>", line 12, in <module>
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\geocoding.py", line 160, in CreateAddressLocator
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000046: Too many reference data tables for this style.
Failed to execute (CreateAddressLocator).

I did try create locator from arcMap and Pro using the same data and successful.

Any thing wrong with my python script?

thank you for any help.

Tags (2)
0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus

line 12, which we can't find contains the key.

/blogs/dan_patterson/2016/08/14/script-formatting 

will give you line numbers.

It if worked in arcmap, why not copy the code snippet and use it in your code

0 Kudos
JoeBorgione
MVP Emeritus

Line 4 is suspect to me: typically commas separate arguments:  You have a feature class named and then it's role and they are space separated...

That should just about do it....
0 Kudos
DanPatterson_Retired
MVP Emeritus

So what are the folders? (folder) and (out_put_folder) or are you just anonymizing them? or are they parameters?

But I suspect it lies in the quoting within the parameter string if you didn't copy it directly... 

Create Address Locator—Help | ArcGIS Desktop 

0 Kudos
NickXu
by
New Contributor

Hi all,

I find the reason. We use UNC drive, for example, \\foldername\f, if I change it to forword slash as code sniper did //foldername/ then the py script runs without error. I don't know this is a bug of the address locator py api

thanks all!

0 Kudos
DanPatterson_Retired
MVP Emeritus

Checking for the existence of data—ArcPy Get Started | ArcGIS Desktop 

Is a good idea to check for inputs to functions.

forward slashes are definitely good because backslashes have special meaning in python and a single backslash is an escape character

0 Kudos
JoeBorgione
MVP Emeritus

I'm a huge fan of the raw string literal functionality that python provides.  As I get older, what memory I have left needs to go to things like where did I park today rather escaping back slashes or changing to fore slashes....

import arcpy
arcpy.env.workspace = r'\\RE-GOLD-16S\GISData$\ParcelCheck2015\ParcelPostSketch.gdb'
arcpy.env.workspace
u'\\\\RE-GOLD-16S\\GISData$\\ParcelCheck2015\\ParcelPostSketch.gdb'

Notice how all my slashes are escaped for me; this also plays to my laziness:  I can copy and past paths from windows explorer or ArcCatalog. In line 2 all I did was copy and past the unc path...

That should just about do it....
JoshAndreas
New Contributor III

I ran into this error today. Posting my solution here in case someone else makes the same mistake I did, because the error message has little to do with the actual problem in both my case and Nick's original case.

For me, it had nothing to do with path name and everything to do with my first parameter. I used "General-Gazetteer", which is how it is spelled in the parameter syntax table at Create Address Locator—Help | ArcGIS Desktop. Shame on me for following documentation. Evidently, it needs to have spaces on either side of the dash: "General - Gazetteer". To be fair, I do see that their sample code has the spaces, but I always refer to the table for the list of valid parameter values and just look at the sample code when I need help formatting these values (i.e. with the 2nd and 3rd parameters).

(And for the record, when I format my first parameter like the code in the original question, "General Gazetteer" with no dash at all, I also get the same error)