Thanks for the assistance @Anonymous User, I was able to get this working. I have a follow up question that I'm hoping you may have some insight into.
My modified code is below. The extent string is computed beforehand, but seems to work as expected, based on the polyline geometry being read via a SearchCursor.
def save_raster(name, output_directory, ext_string):
""""""
url = r"https://elevation.nationalmap.gov/arcgis/rest/services/3DEPElevation/ImageServer/exportImage?"
params = {"f": "image",
"bbox": ext_string,
"bboxSR": 102005,
"imageSR": 102005,
"format": "tiff",
"pixelType": "F32",
"size": "600,600",
"noDataInterpretation": "esriNoDataMatchAny",
"interpolation": "RSP_BilinearInterpolation"}
response = requests.get(url=url, params=params, allow_redirects=True)
name = "".join([char if char in ascii_letters else "" for char in name])
fullpath = pathlib.Path(output_directory, f"{name}.tif")
with open(fullpath, mode="wb") as image_file:
image_file.write(response.content)
arcpy.management.CalculateStatistics(str(fullpath))
The question I have is about specifying pixel size, which oddly enough does not seem to be an option based on the documentation here:
https://developers.arcgis.com/rest/services-reference/enterprise/export-image.htm
Below my pixels are roughly 10x10 (meters) because I've specified a size of 600,600.
Here my pixels are much, much larger because the size I've specified is 30x30, width/height.
Using the dimensions of the polyline extent (extent.XMax - extent.XMin) and the intended pixel resulution (30 meters, for example), some math can be performed to get the "size=<width>,<height>" that yields approximately the intended pixel resolution, but it's pretty cumbersome compared to just passing the resolution as a parameter.
It's very odd to me that the call takes a pixel count (when is this property relevant?) instead of the actual pixel resolution, which is one of the more important properties of a raster dataset...