Adding MapService raster layer using ArcPy from ArcGIS REST Services directory to a ArcMap MXD
I have map services published in to a specific folder on to an ArcGIS Server site. Each map service publishes raster layers.
Tipically the url of the rest directory of a raster layer is:
https://<my host>/server/rest/services/<folder>/<service name>/MapServer/<id>
Unsing ArcPy I would like to add the raster layer to a MXD using its rest directory url.
I have tried the following code embedded in the "execute" section of a python arctoolbox:
import arcpy.mapping
IMXD = arcpy.mapping.MapDocument("CURRENT")
DF_layer = arcpy.mapping.ListDataFrames(IMXD, "Layers")[0]
url_ras_layer = r"https://<my host>/server/rest/services/<folder>/<service name>/MapServer/<id>"
arcpy.mapping.AddLayer(DF, arcpy.mapping.Layer(url_ras_layer))but I got the error message:
ValueError: Object: CreateObject Layer invalid data source
Furthermore I guess that an account must provided in order to establish the right access to the datastore.
Hoping that is possible to perform the add operation via ArcPy, how can I do it ?