I am trying to use the ESRI Living Atlas “Terrain” raster layer as an input for the copy raster tool. I am able to perform this operation manually so have copied the “Copy Raster” portion of the code. I am also able to access the Terrain layer alone so that portion appears to be correct. When I combine the two, I am getting an error code. This is my script thus far:
import arcpy
from arcgis.gis import GIS
# Set up ArcGIS Online connection
username = "my_username"
password = "my_password"
gis = GIS("https://www.arcgis.com", username, password)
try:
# Search for terrain layer
terrain_layer = gis.content.search("Terrain")[4]
# Fetch the actual raster layer from the item
except Exception as e:
print("Error accessing terrain layer:", e)
# Set the workspace to the geodatabase location
arcpy.env.workspace = r"C:Modeling_PythonTools.gdb"
# Define the input feature class
input_feature_class = "Point_feature_class_layer"
# Define the output folder
output_folder = r"C:Outputs"
try:
with arcpy.EnvManager(outputCoordinateSystem='PROJCS["WGS_1984_Web_Mercator_Auxiliary_Sphere",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Mercator_Auxiliary_Sphere"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],PARAMETER["Standard_Parallel_1",0.0],PARAMETER["Auxiliary_Sphere_Type",0.0],UNIT["Meter",1.0]]', snapRaster="Terrain", extent='-95.2058694319287 29.6965465890539 -95.1541935076243 29.7416535152976 GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]', cellSize="Terrain", cellAlignment="ALIGN_WITH_INPUT"):
arcpy.management.CopyRaster(
in_raster=terrain_layer,
out_rasterdataset=r"C:copy_raster",
config_keyword="",
background_value=None,
nodata_value="",
onebit_to_eightbit="NONE",
colormap_to_RGB="NONE",
pixel_type="32_BIT_FLOAT",
scale_pixel_value="NONE",
RGB_to_Colormap="NONE",
format="GRID",
transform="NONE",
process_as_multidimensional="CURRENT_SLICE",
build_multidimensional_transpose="NO_TRANSPOSE"
)
except arcpy.ExecuteError:
# Get any messages from the last operation
msgs = arcpy.GetMessages(2)
print("ArcPy error:", msgs)
except Exception as e:
print("Python error:", e)
The error code I am receiving is:
Python error: Object: Error in executing tool
I am wondering if I am treating this as a raster layer but should be treating it different when inputting it into the Copy Raster tool. Not entirely sure why this error is showing up.