<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Getting XY from locator service in Python Script in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/getting-xy-from-locator-service-in-python-script/m-p/86099#M2971</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks like in order to specify multiple attributes using the format here, you just need your attributes to be in a comma-separated list, in DOUBLE quotes&lt;/P&gt;&lt;P&gt;So, full code being used to call a locator service and get the X,Y attributes returned - may vary depending on the configuration of the locator service you are hitting - but essentially the 'data' variable here is what gets put in the URL query to the locator so you can try submitting a request directly from the REST endpoint of the locator and see how that looks in the URL to determine what you want in the 'data' parameters.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy,os&lt;BR /&gt;import urllib&lt;BR /&gt;import json&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;address = '201 N Stone Av'&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;data = {'SingleLine': address,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; 'maxLocations': 1,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; 'outFields': "x,y",&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; 'f': 'pjson'}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;URL = 'https://gis.tucsonaz.gov/public/rest/services/Geocoders/CENTERLINE_LOCATOR_WEB/GeocodeServer/findAddressCandidates'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;result = urllib.urlopen(URL, urllib.urlencode(data)).read()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;print json.loads(result)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 Mar 2019 15:42:38 GMT</pubDate>
    <dc:creator>AllenScully</dc:creator>
    <dc:date>2019-03-21T15:42:38Z</dc:date>
    <item>
      <title>Getting XY from locator service in Python Script</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/getting-xy-from-locator-service-in-python-script/m-p/86097#M2969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Working on a GP tool that will be published&amp;nbsp;as a GP service for use in a GP Widget/WebApp.&amp;nbsp; User will need to enter an address OR click on a map to kick of the tool, then a bunch of other things happen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All is working fairly well - can hit the locator, and get results.&amp;nbsp; However, there a few steps I'm fuzzy on as far as working with the results that come back from the locator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 - how to specify that we only need 1 result from the locator (the first one) - typically we are getting at least 2 results.&lt;/P&gt;&lt;P&gt;2 - how to specify that really all I want is the X and Y back&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think once I'm just getting a single result back, and then only the X/Y values, I can go forward.&lt;/P&gt;&lt;P&gt;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:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import urllib&lt;BR /&gt;import json&lt;BR /&gt;import arcpy,os&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;address = '201 N Stone Av'&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data = {'SingleLine': address,&lt;BR /&gt; 'f': 'pjson'}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;URL = 'https://gis.tucsonaz.gov/public/rest/services/Geocoders/CENTERLINE_LOCATOR_WEB/GeocodeServer/findAddressCandidates'&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;result = urllib.urlopen(URL, urllib.urlencode(data)).read()&lt;BR /&gt;print json.loads(result)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks -&amp;nbsp;&lt;/P&gt;&lt;P&gt;Allen Scully&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2019 20:59:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/getting-xy-from-locator-service-in-python-script/m-p/86097#M2969</guid>
      <dc:creator>AllenScully</dc:creator>
      <dc:date>2019-03-20T20:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Getting XY from locator service in Python Script</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/getting-xy-from-locator-service-in-python-script/m-p/86098#M2970</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok - sometimes it takes putting it out to there to see what's right in front of you -&lt;/P&gt;&lt;P&gt;Got it to return a single record (maxLocations):&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;data = {'SingleLine': address,&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt; 'maxLocations': 1,&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt; 'f': 'pjson'}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I'm stuck on now is getting the 'outFields' portion to&amp;nbsp; be X and Y - simple formatting issue I think, as far as how to properly write out multiple fields to the 'outFields parameter - it works as below, returning the X attribute - now just need to add the Y attribute - have tried a bracketed lists: ('x','y'),&amp;nbsp; ['x','y'], {'x','y'},&amp;nbsp; - no luck, and&amp;nbsp;simply putting a comma between:&amp;nbsp; 'x','y', reads as invalid in the IDE&lt;/P&gt;&lt;P&gt;for example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data = {'SingleLine': address,&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;'maxLocations': 1,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;'outFields': 'x',&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;'f': 'pjson'}&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2019 22:15:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/getting-xy-from-locator-service-in-python-script/m-p/86098#M2970</guid>
      <dc:creator>AllenScully</dc:creator>
      <dc:date>2019-03-20T22:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Getting XY from locator service in Python Script</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/getting-xy-from-locator-service-in-python-script/m-p/86099#M2971</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks like in order to specify multiple attributes using the format here, you just need your attributes to be in a comma-separated list, in DOUBLE quotes&lt;/P&gt;&lt;P&gt;So, full code being used to call a locator service and get the X,Y attributes returned - may vary depending on the configuration of the locator service you are hitting - but essentially the 'data' variable here is what gets put in the URL query to the locator so you can try submitting a request directly from the REST endpoint of the locator and see how that looks in the URL to determine what you want in the 'data' parameters.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy,os&lt;BR /&gt;import urllib&lt;BR /&gt;import json&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;address = '201 N Stone Av'&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;data = {'SingleLine': address,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; 'maxLocations': 1,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; 'outFields': "x,y",&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; 'f': 'pjson'}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;URL = 'https://gis.tucsonaz.gov/public/rest/services/Geocoders/CENTERLINE_LOCATOR_WEB/GeocodeServer/findAddressCandidates'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;result = urllib.urlopen(URL, urllib.urlencode(data)).read()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;print json.loads(result)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2019 15:42:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/getting-xy-from-locator-service-in-python-script/m-p/86099#M2971</guid>
      <dc:creator>AllenScully</dc:creator>
      <dc:date>2019-03-21T15:42:38Z</dc:date>
    </item>
  </channel>
</rss>

