2

I have an address locator that is updated weekly and I need to overwrite the existing geocode service and share the updated address locator as a new geocode service. Is there a pythonic way to automate the overwriting and re-publishing step, like in the screenshot below?

Overwrite an existing service

  • 1
    All you have to do is update the .loc/.lox files on the server – Maksim Jun 22 '18 at 19:06
  • @Maksim Sounds like the geocode service is "fetching" data from the locator data source in the organizational server instead of actually publishing the whole locator along with all of its data to the web. So as long as changes are made locally on the .loc/.lox, the web service will be able to "fetch" the new data without overwriting or republishing the service. Am I right about this? – PacmanKX Jun 26 '18 at 21:25
  • That is correct – Maksim Jun 27 '18 at 12:56
  • @Maksim Do I need to stop the service before rebuilding and restart it after rebuilding? – PacmanKX Jun 27 '18 at 14:40
  • To prevent any possible issues, that would be a good idea – Maksim Jun 27 '18 at 14:46
2

I have done this before by rebuilding a separate instance of the address locator in python and using arcpy.Copy_management to overwrite the published locator. After this you do not have to republish the locator, it will be updated automatically.

http://pro.arcgis.com/en/pro-app/tool-reference/data-management/copy.htm

You cannot rebuild the locator using python, you have to copy over it with a new one in my experience.

If you are using ArcGIS pro release of arcpy you can use this tool to rebuild it more easily: http://pro.arcgis.com/en/pro-app/tool-reference/geocoding/rebuild-address-locator.htm

  • I'm using ArcGIS Pro and I'm able to use the one you mentioned to rebuild the locator. So what you're saying is that as long as the .loc and .lox stored in our organizational server is rebuilt by this RebuildAddressLocator_geocoding() function, outside users will immediately experience the changes, right? Before and after rebuilding do I have to stop/start the geocode service? – PacmanKX Jun 26 '18 at 21:19
  • 1
    I was using arcgis 10x so it may be different for you, but no, we did not have to restart the service after overwriting the published address locator using python. You should verify this of course before implementation in production. – atxgis Jun 27 '18 at 14:14
-1

Yes but it is not as straightforward as it should be, or at least I never found a way to simply overwrite an existing service and keep all it's settings. Instead I create a new SDDraft, edit the drafts properties to match the one it is replacing and then publish this modified SDDraft. The code below is what I reuse to automate the republishing of a cached map service. The tags it edits won't exist in geocoding service but you get the idea.

def republishBasemap():
    wrkspc = r'C:\Temp''\\'
    wrkspc = r'D:\mxds'
    mapDoc = arcpy.mapping.MapDocument(os.path.join(wrkspc, r'Basemap.mxd'))
    con = r"D:\BatchJobs\Update\arcgis on localhost_6080 (admin).ags" 
    service = 'Basemap'
    sddraft = os.path.join(wrkspc,service + '.sddraft')
    sd = os.path.join(wrkspc, service + '.sd')
    summary = 'County Basemap'
    tags = 'County,Basemap'
    newSDdraft = os.path.join(wrkspc, "updatedDraft.sddraft")
    arcpy.env.overwriteOutput = True
    try:
        #create a new SDDraft
        analysis = arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER', con, False, None, summary, tags)
        print ""
        print "   "
        if analysis['errors'] == {}:
                #Draft is an xml file that can be edited as needed
                doc = DOM.parse(sddraft)
                tagsType = doc.getElementsByTagName('Type')
                for tagType in tagsType:
                        if tagType.parentNode.tagName == 'SVCManifest':
                                if tagType.hasChildNodes():
                                        tagType.firstChild.data = "esriServiceDefinitionType_Replacement"
                tagsState = doc.getElementsByTagName('State')
                for tagState in tagsState:
                    if tagState.parentNode.tagName == 'SVCManifest':
                        if tagState.hasChildNodes():
                            tagState.firstChild.data = "esriSDState_Published"
                tagsKeepCache = doc.getElementsByTagName('KeepExistingMapCache')
                for tagCache in tagsKeepCache:
                    if tagCache.parentNode.tagName == 'SVCManifest':
                        if tagCache.hasChildNodes():
                            tagCache.firstChild.data = "true"
                configProps = doc.getElementsByTagName('ConfigurationProperties')[0]
                propArray = configProps.firstChild
                propSets = propArray.childNodes
                for propSet in propSets:
                    keyValues = propSet.childNodes
                    for keyValue in keyValues:
                        if keyValue.tagName == 'Key':
                            if keyValue.firstChild.data == "isCached":
                                keyValue.nextSibling.firstChild.data = "true"
                    for keyValue in keyValues:
                        if keyValue.tagName == 'Key':
                            if keyValue.firstChild.data == "maxScale":
                                keyValue.nextSibling.firstChild.data = "1128.497176"

                # Write the new draft to disk
                f = open(newSDdraft, 'w')
                doc.writexml( f )
                f.close()
                #Stage and publish
                arcpy.StageService_server(newSDdraft, sd)
                arcpy.UploadServiceDefinition_server(sd, con,"","","EXISTING","Public","STARTED")
                print "Success"
        else:
                print analysis['errors']
    except Exception as exe :
        _errFail (True)
        _errmsg( "***** ERROR: Can't republish basemap " + "\n")
        logfile.write("***** ERROR: Can't republish basemap \n"  + exe + "\n")
        logfile.write("\n\n")
        print exe
  • Be aware if you copy/paste this code sample, its for MAPS, not geocoding services. – KHibma Jun 22 '18 at 16:23
  • @KHibma Good point. I'll edit my answer to reflect this. – Dowlers Jun 22 '18 at 16:26

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.