I am using python to try and iterate through a feature class to use the extent of each feature to update the extent in the Clip Raster tool. This is to get around the row/column limitation Esri places on its image servers. I have included the code below. It runs successfully but the raster values range from 0 to 0. I have tried it directly on the Image Server, and on my own image server layer made from the wider image layers, as shown below. The script works fine on a DTM layer downloaded and saved to my local drive. Additionally, running it as a standalone geoprocessing tool, with the image_server_layer as input, and one feature selected and set as the extent, provides the desired outcome!
raster = r'https://uk-gis.stantec.com/portal/sharing/servers/af25a795273440deb449b336543602be/services/WorldEle...'
with arcpy.da.SearchCursor(sites, fields) as cursor:
for row in cursor:
extent = row[1].extent
# Create the image server layer
image_server_layer = arcpy.management.MakeImageServerLayer(raster, 'ImageSL', extent)
# Define the output raster path
output_raster = out_loc + '\\' + row[0] + "_2025"
# Ensure the extent values are correctly formatted
rectangle = f"{extent.XMin} {extent.YMin} {extent.XMax} {extent.YMax}"
# Clip the raster based on the extent
arcpy.management.Clip(in_raster=image_server_layer, rectangle=rectangle,
out_raster=output_raster, in_template_dataset="",
nodata_value="255", clipping_geometry="NONE", maintain_clipping_extent="NO_MAINTAIN_EXTENT")
print(f"Exported and clipped raster part for feature {row[0]}")
It's a bit tricky to see what's going on without proper code formatting but it looks like you're rebuilding the IS layer every loop. Does the tool work correctly if you give each layer a new name every loop? Alternatively, can you hoist the layer out of the loop and build it without an extent? Or do you need to define a layer with a limited extent to ensure the clip works?
Make sure extent coordinates are correct,
print(f"Extent: {rectangle}")
Also maybe check the output_raster
output_raster_obj = arcpy.Raster(output_raster)
print(f"Output raster for feature {row[0]}: {output_raster_obj.meanCellHeight}, {output_raster_obj.meanCellWidth}, {output_raster_obj.extent}")