Select to view content in your preferred language

Feeding Variable into arcpy.CreateAddressLocator_geocoding

2397
2
05-09-2013 10:54 AM
MarcCusumano
Occasional Contributor
I have had a lot of success feeding variables into data paths for all other geoprocessing tools (this needs to be in the design so the script can be passed around different systems without modifying the code). But for this one it just will not take it.

Here is what I have:

Path = os.getcwd() + "\\"
FileGDBName = "PSEG_Land_New"
FileGDBPath = Path + FileGDBName + ".gdb"
OldFileGDBName = "PSEG_Land"
OldFileGDBPath = Path + OldFileGDBName + ".gdb"
Locator = OldFileGDBPath + "\Dashboard_Locator"
refLocator = OldFileGDBPath + "\DM_AdjustedStreet_LN_Geocoding"

primTbl = "Primary Table"

arcpy.CreateAddressLocator_geocoding("US Address - Dual Ranges", '"' + "'" + refLocator + "' " + "'" + primTbl + "'" + '"', "'Feature ID' OBJECTID VISIBLE NONE;'*From Left' L_F_F_ADD VISIBLE NONE;'*To Left' L_T_F_ADD VISIBLE NONE;'*From Right' R_F_F_ADD VISIBLE NONE;'*To Right' R_T_F_ADD VISIBLE NONE;'Prefix Direction' PREFIX VISIBLE NONE;'Prefix Type' NAMEPREFIX VISIBLE NONE;'*Street Name' NAME VISIBLE NONE;'Suffix Type' TYPE VISIBLE NONE;'Suffix Direction' SUFFIX VISIBLE NONE;'Left City or Place' L_APNAME VISIBLE NONE;'Right City or Place' R_APNAME VISIBLE NONE;'Left ZIP Code' POSTAL_L VISIBLE NONE;'Right ZIP Code' POSTAL_R VISIBLE NONE;'Left State' <None> VISIBLE NONE;'Right State' <None> VISIBLE NONE;'Left Street ID' <None> VISIBLE NONE;'Right Street ID' <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;'Left Additional Field' <None> VISIBLE NONE;'Right Additional Field' <None> VISIBLE NONE;'Altname JoinID' <None> VISIBLE NONE", Locator, "")




This gives me:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000039: Not enough reference data tables for this style.
Failed to execute (CreateAddressLocator).

The problem is from the part where you provide the input data for the locator to be built off of. I have the syntax down perfect, if I add

print '"' + "'" + refLocator + "' " + "'" + primTbl + "'" + '"'


I get "'C:\Working Folders\GIS\Dashboard_Updates\PSEG_Land.gdb\DM_AdjustedStreet_LN_Geocoding' 'Primary Table'".

If I input this path into the piece where it takes the input, the tool will run. Completely baffled by this.
Tags (2)
0 Kudos
2 Replies
MarcCusumano
Occasional Contributor
Bump...anybody?
0 Kudos
gregmohler
New Contributor II
If you are still baffled, there is a difference in inputs and how print statements work:
print '"' + "'" + refLocator + "' " + "'" + primTbl + "'" + '"'
"'C:\Working Folders\GIS\Dashboard_UpdatesPSEG_Land.gdb\DM_AdjustedStreet_LN_Geocoding' 'Primary Table'"
x = '"' + "'" + refLocator + "' " + "'" + primTbl + "'" + '"'
x
'"\'C:\\Working Folders\\GIS\\Dashboard_UpdatesPSEG_Land.gdb\\DM_AdjustedStreet_LN_Geocoding\' \'Primary Table\'"'

Another quick example:
xyz = "x\ny\nz"
xyz
'x\ny\nz'
print xyz
x
y
z

try this, minding the variable names:
import os
old_gdb_name  = "PSEG_Land.gdb"
old_path = os.path.join(Path, old_gdb_name)
old_path
'C:\\Working Folders\\GIS\\Dashboard_Updates\\PSEG_Land.gdb'


and you can put this in as:
old_path + " " + primTbl
'C:\\Working Folders\\GIS\\Dashboard_Updates\\PSEG_Land Primary Table'

which should work according to the esri docs.  They also have [[path, role], ...] listed, but I think if you are only using the single reference data as a primary table you won't need the list.
0 Kudos