I am looking to see if anyone has a more efficient method of setting bit depth for my output rasters than what I am currently doing. I am using ArcPy in ArcGIS Pro's notebook to create rasters from features and then computing path distance on them. My primary issue is that some of my input datasets are gigantic and can't handle the automatic 32 bit that is being assigned. I am trying to find a way to reduce my storage during the process and thought that maybe changing the bit depth would help. The only method I can figure out to accomplish this is using the 'copy raster' function which is working. The main issue is that it is taking forever because it has to create double the rasters essentially.
Do you have any tidbits on both reducing the storage during processing (particularly during the path distance function as this is where my code runs out of storage) or how to set bit depth?
Here is my current code:
# Convert Features to Rasters
# Temporarily set workspace to the feature dataset to list its feature classes
arcpy.env.workspace = feature_dataset
feature_classes = arcpy.ListFeatureClasses()
arcpy.env.workspace = working_gdb # Reset workspace to working_gdb
arcpy.env.overwriteOutput = True
# Step 3: Convert feature classes to raster datasets
for input_fc in feature_classes:
if 'AOI' in input_fc:
continue
input_fc_path = os.path.join(feature_dataset, input_fc)
# Construct the output raster name by appending '_R' to the feature class name
temp_raster = os.path.join(working_gdb, f"temp_{input_fc}_R")
output_raster = os.path.join(working_gdb, f"{input_fc}_R")
# Set the processing extent
arcpy.env.extent = reference_fc
arcpy.env.nodata = 65535
# Convert feature class to raster
arcpy.conversion.FeatureToRaster(
in_features=input_fc_path,
field="OBJECTID",
out_raster=temp_raster,
cell_size=cell_size
)
# Convert the temporary raster to a compressed format with a consistent bit depth
arcpy.management.CopyRaster(
in_raster=temp_raster,
out_rasterdataset=output_raster,
pixel_type="16_BIT_UNSIGNED",
format="TIFF",
nodata_value="65535"
)
# Delete the temporary raster to free up space
arcpy.management.Delete(temp_raster)
print("Step 3 completed successfully.")
# Path Distance
# Dictionary to store maximum distance values
max_distance_dict = {
"C1_Wet_pnt": 47.854,
"C1_HydroEdge": 47.854,
"C1_Wet_Area": 45.72,
"C2_1_Wet_pnt": 22.86,
"C2_1_HydroEdge": 22.86,
"C2_1_Wet_Area": 22.86,
"C2_2_Wet_pnt": 31.09,
"C2_2_HydroEdge": 31.09,
"C2_2_Wet_Area": 30.48
}
# List all raster datasets in the working geodatabase
arcpy.env.workspace = working_gdb
raster_datasets = arcpy.ListRasters("*_R")
# Step 4: Compute Path Distance
for input_raster in raster_datasets:
# Set the processing extent
arcpy.env.extent = reference_fc
output_path_distance = os.path.join(working_gdb, f"{input_raster}_PD")
# Determine the max distance based on the raster name
max_distance = None
for key, distance in max_distance_dict.items():
if key in input_raster:
max_distance = distance
break
if max_distance is None:
continue
try:
# Compute Path Distance
path_distance_result = arcpy.sa.PathDistance(
in_source_data=input_raster,
in_surface_raster=dtm_layer,
maximum_distance=max_distance
)
path_distance_result.save(output_path_distance)
# Delete the input raster to save storage space
arcpy.management.Delete(input_raster)
except arcpy.ExecuteError:
print(f"Failed to compute Path Distance for {input_raster}. {arcpy.GetMessages()}")
print("Step 4 completed successfully.")