Working on a GP tool that will be published as a GP service for use in a GP Widget/WebApp. User will need to enter an address OR click on a map to kick of the tool, then a bunch of other things happen.
Basically, I want the input parameters for the tool to be X/Y - so I'm calling one of our locator services to handle the scenario where user inputs an address.
All is working fairly well - can hit the locator, and get results. However, there a few steps I'm fuzzy on as far as working with the results that come back from the locator.
1 - how to specify that we only need 1 result from the locator (the first one) - typically we are getting at least 2 results.
2 - how to specify that really all I want is the X and Y back
I think once I'm just getting a single result back, and then only the X/Y values, I can go forward.
Code is below, for just the call and return to/from the Locator service(locator should be publicly accessible) - the 'address' variable will be converted to a GetParameterAsText variable to allow user input, just hard-coded currently for development:
import urllib
import json
import arcpy,os
arcpy.env.overwriteOutput = True
address = '201 N Stone Av'
data = {'SingleLine': address,
'f': 'pjson'}
URL = 'https://gis.tucsonaz.gov/public/rest/services/Geocoders/CENTERLINE_LOCATOR_WEB/GeocodeServer/findAddressCandidates'
result = urllib.urlopen(URL, urllib.urlencode(data)).read()
print json.loads(result)
Thanks -
Allen Scully