I have a simple example python script below that accepts an address and is trying to return the XY.
My plan is to take this python script and create a tool and publish this to ArcGIS Server as a service
I can then call the service and pass it the address parameter. THe code will run and set a variable to the XY location of the geocoded address. Great everything works....
How do I get that XY back to the user that is passing the address parameter?
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># Geting user input for address</SPAN>
searchAddress <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># SEARCH PARAMETERS FROM SERVICE</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"passed search address: "</SPAN> <SPAN class="operator token">+</SPAN> searchAddress
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">""</SPAN>
<SPAN class="comment token"># GEOCODERS</SPAN>
geoCodeUrl <SPAN class="operator token">=</SPAN> <SPAN class="string token">"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates"</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">singleAdressGeocode</SPAN><SPAN class="punctuation token">(</SPAN>address<SPAN class="punctuation token">,</SPAN> geoCodeUrl<SPAN class="punctuation token">,</SPAN> outSR <SPAN class="operator token">=</SPAN> <SPAN class="string token">"26917"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token">##clean up the address for url encoding</SPAN>
address <SPAN class="operator token">=</SPAN> address<SPAN class="punctuation token">.</SPAN>replace<SPAN class="punctuation token">(</SPAN><SPAN class="string token">" "</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"+"</SPAN><SPAN class="punctuation token">)</SPAN>
address <SPAN class="operator token">=</SPAN> address<SPAN class="punctuation token">.</SPAN>replace<SPAN class="punctuation token">(</SPAN><SPAN class="string token">","</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"%3B"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#send address to geocode service</SPAN>
lookup <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>geoCodeUrl <SPAN class="operator token">+</SPAN> <SPAN class="string token">"?SingleLine="</SPAN> <SPAN class="operator token">+</SPAN> address <SPAN class="operator token">+</SPAN> <SPAN class="string token">"&outSR="</SPAN> <SPAN class="operator token">+</SPAN> outSR <SPAN class="operator token">+</SPAN> <SPAN class="string token">"&maxLocations=1&f=pjson"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#get results to variable</SPAN>
data <SPAN class="operator token">=</SPAN> lookup<SPAN class="punctuation token">.</SPAN>json<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> data<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"candidates"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">return</SPAN> data
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token">##no results</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="string token">"Address not geocoded: "</SPAN> <SPAN class="operator token">+</SPAN> address
<SPAN class="comment token"># CALL GEOCODER</SPAN>
geocodeResult <SPAN class="operator token">=</SPAN> singleAdressGeocode<SPAN class="punctuation token">(</SPAN>searchAddress<SPAN class="punctuation token">,</SPAN> geoCodeUrl<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># GET RESULTS</SPAN>
addressResult <SPAN class="operator token">=</SPAN> geocodeResult<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"candidates"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"address"</SPAN><SPAN class="punctuation token">]</SPAN>
coordinateX <SPAN class="operator token">=</SPAN> geocodeResult<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"candidates"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"location"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"x"</SPAN><SPAN class="punctuation token">]</SPAN>
coordinateY <SPAN class="operator token">=</SPAN> geocodeResult<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"candidates"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"location"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"y"</SPAN><SPAN class="punctuation token">]</SPAN>
strcoordinateX <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>coordinateX<SPAN class="punctuation token">)</SPAN>
strcoordinateY <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>coordinateY<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># SHOW RESULTS</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"gecode result: "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>geocodeResult<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"-------------------"</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"geocoded address: "</SPAN> <SPAN class="operator token">+</SPAN> addressResult
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"-------------------"</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"X coordinate: "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>coordinateX<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"-------------------"</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Y coordinate: "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>coordinateY<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"-------------------"</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>