<?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 Accessing AGOL service with Python 3 for geoprocessing in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/accessing-agol-service-with-python-3-for/m-p/34444#M1214</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was curious about programmatically running Viewshed2 against the &lt;A href="https://www.arcgis.com/home/item.html?id=58a541efc59545e6b7137f961d7de883" rel="nofollow noopener noreferrer" target="_blank"&gt;ESRI Terrain service&lt;/A&gt;&amp;nbsp;so I started writing a jupyter notebook from the arcgispro-py3 environment. For input to the tool, I needed to&amp;nbsp;make an image layer from the url using MakeImageServerLayer which takes a url as an input. What&amp;nbsp;I came up with is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SignInToPortal("http://www.arcgis.com", username, password)
token = arcpy.GetSigninToken()['token']
token = token.rstrip(".")
terrain_url = "https://elevation.arcgis.com/arcgis/rest/services/WorldElevation/Terrain/ImageServer?token={}".format(token)
arcpy.MakeImageServerLayer_management(terrain_url, "terrain", layer_extent,"","","","","", 12)

&lt;/PRE&gt;&lt;P&gt;This works (at least as far as getting Viewshed2 to start; I've got some other issues with extent and memory, but those are beside the point) but is this the best way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For instance, you can see that I have to strip two trailing period characters off the end of the token string to make it work in the URL. Why would the token be returned with those characters if they are invalid in the url?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also never found a similar example in any question or documentation. The only code&amp;nbsp;in which I ever saw MakeImageServerLayer it was preceded by mapping.CreateGISServerConnectionFile which doesn't appear to exist in AGP Python3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;just recently discovered the viewshed task included in the ESRI Elevation Analysis services and that is a possibility, but the resolution of the World Elevation / Terrain service is a bit better in my area than the elevation data that those analysis services use (why is that?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suggestions? Comments?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 15:56:39 GMT</pubDate>
    <dc:creator>EvanThoms</dc:creator>
    <dc:date>2021-12-12T15:56:39Z</dc:date>
    <item>
      <title>Accessing AGOL service with Python 3 for geoprocessing</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/accessing-agol-service-with-python-3-for/m-p/34444#M1214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was curious about programmatically running Viewshed2 against the &lt;A href="https://www.arcgis.com/home/item.html?id=58a541efc59545e6b7137f961d7de883" rel="nofollow noopener noreferrer" target="_blank"&gt;ESRI Terrain service&lt;/A&gt;&amp;nbsp;so I started writing a jupyter notebook from the arcgispro-py3 environment. For input to the tool, I needed to&amp;nbsp;make an image layer from the url using MakeImageServerLayer which takes a url as an input. What&amp;nbsp;I came up with is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SignInToPortal("http://www.arcgis.com", username, password)
token = arcpy.GetSigninToken()['token']
token = token.rstrip(".")
terrain_url = "https://elevation.arcgis.com/arcgis/rest/services/WorldElevation/Terrain/ImageServer?token={}".format(token)
arcpy.MakeImageServerLayer_management(terrain_url, "terrain", layer_extent,"","","","","", 12)

&lt;/PRE&gt;&lt;P&gt;This works (at least as far as getting Viewshed2 to start; I've got some other issues with extent and memory, but those are beside the point) but is this the best way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For instance, you can see that I have to strip two trailing period characters off the end of the token string to make it work in the URL. Why would the token be returned with those characters if they are invalid in the url?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also never found a similar example in any question or documentation. The only code&amp;nbsp;in which I ever saw MakeImageServerLayer it was preceded by mapping.CreateGISServerConnectionFile which doesn't appear to exist in AGP Python3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;just recently discovered the viewshed task included in the ESRI Elevation Analysis services and that is a possibility, but the resolution of the World Elevation / Terrain service is a bit better in my area than the elevation data that those analysis services use (why is that?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suggestions? Comments?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 15:56:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/accessing-agol-service-with-python-3-for/m-p/34444#M1214</guid>
      <dc:creator>EvanThoms</dc:creator>
      <dc:date>2021-12-12T15:56:39Z</dc:date>
    </item>
  </channel>
</rss>

