Select to view content in your preferred language

Using Landscape Image Services in a Python Script

1889
1
11-07-2013 07:10 AM
RichNauman
Deactivated User
Is it possible to use a Landscape Image Service as a geoprocessing input for a stand alone Python script?
Tags (2)
0 Kudos
1 Reply
CharlieFrye
Esri Contributor
Yes it is, though it is important to access the image service via a connection file that you create in the python code.  Here is the essential snippet of code to use:


    arcpy.mapping.CreateGISServerConnectionFile("USE_GIS_SERVICES", arcpy.env.scratchFolder,
                                                servername + ".ags", "http://" + servername + ".arcgis.com/arcgis/services",
                                                "ARCGIS_SERVER", '', '', userName, passWord, "SAVE_USERNAME")

    # set up image layer from the landscape server connection, and get its spatial reference
    imageService = os.path.join(arcpy.env.scratchFolder, servername, imageservicename + ".ImageServer")
    inputImageLayer = arcpy.MakeImageServerLayer_management(imageService,"imageLayer")


Once you have that inputImageLayer, you can use it to get properties via the arcpy.describe function:

rastSpatRef = arcpy.Describe(inputImageLayer).spatialReference
arcpy.env.cellSize = arcpy.Describe(inputImageLayer).meanCellWidth
theCellSize = arcpy.Describe(inputImageLayer).meanCellWidth


From there you can make a rasterLayer:

arcpy.MakeRasterLayer_management(inputImageLayer, "temp_raster")


And that can be used in many Geoprocessing functions:

arcpy.sa.Con("junk2g","temp_raster")