Accessing AGOL service with Python 3 for geoprocessing

382
0
05-02-2019 11:15 AM
EvanThoms
Occasional Contributor II

I was curious about programmatically running Viewshed2 against the ESRI Terrain service so I started writing a jupyter notebook from the arcgispro-py3 environment. For input to the tool, I needed to make an image layer from the url using MakeImageServerLayer which takes a url as an input. What I came up with is:

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)

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?

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?

I also never found a similar example in any question or documentation. The only code in which I ever saw MakeImageServerLayer it was preceded by mapping.CreateGISServerConnectionFile which doesn't appear to exist in AGP Python3.

I 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?)

Suggestions? Comments?

0 Kudos
0 Replies