HOW TO

Resample image services of an area of interest using the Arcpy module

Last Published: April 25, 2020

Summary

Image services stored on an end user's ArcGIS Enterprise stack can be resampled by specifying the area of interest (AOI) from a feature class. The process can be tedious when it involves large imagery services, so using the Arcpy module with the Resample_management() function is helpful.

Procedure

The following steps describe how to use the ArcPy module to resample image services of an area of interest with the Resample_management() function.

  1. Import the necessary modules.
import arcpy, ArcGIS
from arcgis.gis import GIS
  1. Specify the parameters of the AOI, Portal for ArcGIS credentials, and the output location of the images.
input_fishnet = r"<Location to AOI>"
gis = GIS(url ="<Portal URL>", username="<Portal_Username>",password="<Portal_Password>", verify_cert=False)
resample_output=r"<Location of the output images>"
  1. Create a loop to retrieve all image services available according to the AOI specified.
for row in arcpy.da.SearchCursor(input_fishnet, ["SHAPE@", "OID"]):
    extent = row[0].extent
    name= row[1]
    update_name=str(name)
    update_extent=str(extent).replace(" ",",")
    
    imagery = arcgis.raster.ImageryLayer("*REST endpoint of the imagery service*",gis=gis)

    AOI=imagery.export_image(bbox=update_extent,export_format="tiff",bbox_sr=2913,f="image",save_folder=r"*Location of the Output Folder*", save_file=update_name+".tif")
  1. Run the Resample_management() function in the same loop.
arcpy.Resample_management(AOI,resample_output+update_name+"_resampled.tif",4,"BILINEAR")

The following shows the full script:

import arcpy, arcgis

from arcgis.gis import GIS

input_fishnet = r"C:\Temp"
gis = GIS(url ="https://test.esri.com/portal", username="username",password="password", verify_cert=False)
resample_output=r"C:\Temp"
for row in arcpy.da.SearchCursor(input_fishnet, ["SHAPE@", "OID"]):
    extent = row[0].extent
    name= row[1]
    update_name=str(name)
    update_extent=str(extent).replace(" ",",")
    
    imagery =arcgis.raster.ImageryLayer("https://test.esri.com/portal/rest/services/Test",gis=gis)

    AOI=imagery.export_image(bbox=update_extent,export_format="tiff",bbox_sr=2913,f="image",save_folder=r"C:\Temp",save_file=update_name+".tif")
   
    arcpy.Resample_management(AOI,resample_output+update_name+"_resampled.tif",4,"BILINEAR")

Article ID:000020154

Software:
  • ArcMap
  • Portal for ArcGIS

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic