Publish python script as geoprocessing service using a locator service

1149
5
03-06-2017 11:14 AM
ShaunConway
Occasional Contributor II

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?

AGS 10.2.2

Reply
0 Kudos
5 Replies
JonathanQuinn
Esri Frequent Contributor

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?

Reply
0 Kudos
ShaunConway
Occasional Contributor II

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:
        json.dump(data, outfile)

gcPoint = arcpy.Point(data["candidates"][0]["location"]["x"], data["candidates"][0]["location"]["y"])
arcpy.MakeFeatureLayer_management(projectArea,projectArea_Layer)
arcpy.SelectLayerByLocation_management(projectArea_Layer, "INTERSECT",arcpy.Geometry ("point", gcPoint, arcpy.Describe(projectArea).spatialReference),"","NEW_SELECTION")

JonathanQuinn
Esri Frequent Contributor

Pretty spiffy!  Nicely done.

Reply
0 Kudos
MaryThomas
New Contributor

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.

Reply
0 Kudos
JonathanQuinn
Esri Frequent Contributor

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.

Reply
0 Kudos