Access existing address locator properties with arcpy

653
5
01-26-2018 12:22 PM
Lake_Worth_BeachAdmin
Regular Contributor

my question is similar to this one: https://community.esri.com/message/459758?commentID=459758#comment-459758?q=accessing%20address%20lo... 

I am using Desktop 10.5.1

I am automating the process of creating an address locator with arcpy. Everything works fine however I need to adjust the properties of the locator after its created under the "geocode options" menu I need to change the values for the "match without house number" and "match with no zones" both need to be set to value "Yes"

How can I access this via arcpy?

this is  across post on stack exchange as well: geocoding - arcmap 10.5.1 address locator properties via arcpy - Geographic Information Systems Stac... 

Tags (2)
0 Kudos
5 Replies
BruceHarold
Esri Regular Contributor

Hi

There isn't any direct property access via ArcPy but you can do what you want by editing (in code) the .loc file component of the locator (or each .loc file in a composite locator, being careful that the locator supports house numbers and zones in the first place).

Edit or insert lines so that you have the below lines in the .loc file(s):

supportsEmptyHouseNumber = true
supportsOptionalZone = true

Lake_Worth_BeachAdmin
Regular Contributor

thanks for the Info Bruce, there is an issue though. the .loc file does not contain these fields originally. You have to manually enable them within arcmap/catalog then the .loc file will append those values. I tried using the code below directly after creating the locator (no errors) but it cannot replace the false with true values because they are not inside the .loc file after being created. if you create a locator open the .loc file you wil see none of the extended properties are present. if you set them inside catalog then open the .loc file you will see they are present.

with open(r"Y:\path\to\locator.loc", 'r') as file :
  filedata = file.read()

# Replace the target string
filedata1 = filedata.replace("supportsEmptyHouseNumber = false", "supportsEmptyHouseNumber = true")

filedata2 = filedata.replace("supportsOptionalZone = false", "supportsOptionalZone = true")

# Write the file out again
with open(r"Y:\path\to\locator.loc", 'w') as file:
  file.write(filedata1)
  file.write(filedata2)

0 Kudos
Lake_Worth_BeachAdmin
Regular Contributor

I should also mention I tried the append() method to just add those lines to the .loc file but this breaks the locator.

0 Kudos
Lake_Worth_BeachAdmin
Regular Contributor

another update... the append methods worked I just needed to add a extra line before adding the string values the code below did this correctly

with open(locatorLW, 'r') as file :
  filedata = file.read()


filedata1 = "supportsEmptyHouseNumber = true \n"

filedata2 = "supportsOptionalZone = true"

# Write the file out again
with open(locatorLW, 'a') as file:
  file.write('\n')
  file.write(filedata1)
  file.write(filedata2)
  file.close()

0 Kudos
BruceHarold
Esri Regular Contributor

Great, that should work then.  The locator isn't changed when you edit properties in the .loc file, it is quite safe to do it like you are and it will set the target properties.  If a locator is already loaded into memory though you will need to restart your session.