2

I have a set of rasters of different extent and I have written a script to combine them all into one raster using CellStatistics:

import arcpy
from arcpy.sa import *

arcpy.env.workspace = r'C:\ESRI\ArcGIS_Pro_Projects\DATA\Optimity_Alf\Work.gdb'

#Path where rasters are located
path = r'C:/ESRI/ArcGIS_Pro_Projects/Optimity_Alf/DATA/Work.gdb'

#List of raster names from workspace
rasters = arcpy.ListRasters('*', 'All')

#Building list of raster complete paths
paths = []
for raster in rasters:
    if raster[0] != '_':
        complete_path = path + "/" + raster
        paths.append(complete_path)

#Combining rasters into one unique raster
path_combined_raster = r'C:\ESRI\ArcGIS_Pro_Projects\Optimity_Alf\DATA\Work.gdb\Combined_Raster'
combined_raster = CellStatistics (paths, 'MINIMUM', 'DATA')
combined_raster.save(path_combined_raster)

However, when I run this script it throws the following error:

    Traceback (most recent call last):
  File "C:\ESRI\ArcGIS_Pro_Projects\Optimity_Alf\Arcpy_Scripts\Combining_Viewsheds.py", line 21, in <module>
    combined_raster = CellStatistics (paths, 'MINIMUM', 'DATA')
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Functions.py", line 3173, in CellStatistics
    ignore_nodata)
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Utils.py", line 53, in swapper
    result = wrapper(*args, **kwargs)
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Functions.py", line 3169, in Wrapper
    [function] + Utils.flattenLists(in_rasters_or_constants))
RuntimeError:  ERROR 999998: Unexpected Error.
 Failed to execute (CombinedViewsheds).

I have no idea what all that error message means. However, I tried to do the same operation in ArcGIS Pro and got an error regarding the extent of the rasters. Therefore I went to Environments and set the extent to 'Union of Inputs'. That change made the thing work fine. My question is, how can I set the extent in arcpy? The instruction "CellStatistics (paths, 'MINIMUM', 'DATA')" does not accept more parameters.

1 Answer 1

2

You can set the extent using the env module, prior to running Cell Statistics:

arcpy.env.extent = "MAXOF"

See here for the scripting syntax of the extent variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.