I have a python script that involves some geocoding. For the geocoding, I am using an existing locator service hosted on our AGS. When I go to publish the python script as a geoprocessing service, it wants to copy the locator to the server.
Is there a way to publish a geoprocessing script that uses an existing locator service without having to copy the locator to the server?
Unfortunately, I'm not sure if there's a workaround for that. If you are hosting the geocode service yourself, why not just reference the locators on disk instead of referencing the service?
Thanks Jonathan. I figured this out shortly after posting. Our need really was only to geocode a single address, then find intersecting project area. For this workflow I found that just calling the geocoding service and decoding the JSON response worked great. Turns out, it was also much faster than using arcpy.GeocodeAddresses_geocoding.
gcUrl = "https://mapviewer.lynchburgva.gov/arcgis/rest/services/Locators/Composite/GeocodeServer/findAddressC..."+ arcpy.GetParameterAsText(0) + "&outFields=&maxLocations=&outSR=&searchExtent=&f=pjson"
response = urllib.urlopen(gcUrl)
data = json.loads(response.read())
with open('gcAddress.json', 'w') as outfile:
gcPoint = arcpy.Point(data["candidates"]["location"]["x"], data["candidates"]["location"]["y"])
arcpy.SelectLayerByLocation_management(projectArea_Layer, "INTERSECT",arcpy.Geometry ("point", gcPoint, arcpy.Describe(projectArea).spatialReference),"","NEW_SELECTION")
I am trying to do the same thing. But I get a couple of errors. One being Key error: 'candidates' in PythonWin and the other is NameError: name 'urllib' is not defined when running tool in Arctoolbox. Any help is appreciated. I have been trying to perform this with request module and need to be able to input address each time.
You can try to print the response of the request prior to parsing it or even accessing the text file generated to make sure that it contains the response you expect. The urllib module is a default, standard library included with the installation of Python for Server and ArcMap. You need to make sure you import the module prior to using it.