DistanceAccumulation returns raster with default name - how to set specific name?

662
5
12-10-2023 12:26 PM
ChristaRohrbach
New Contributor II

I run distance accumulation in a standalone Python script and save the resulting raster as follows:

 

dist_acc_raster = arcpy.sa.DistanceAccumulation(dest_features, "", "",
                                                cost_raster, "", "", "", "",
                                                back_dir_raster, "", "", "", "",
                                                "", "", "GEODESIC")
dist_acc_raster.setProperty("name", "some_specific_name")
dist_acc_raster.save(r"C:\some.gdb\some_specific_name")

# EDIT: replaced path variable with path to make it clearer

 

The raster name is always set to the default "Distanc_{suffix}" name which annoys me when adding the data to a map later. This does not happen when I run the tool manually in ArcGIS Pro. How can I set the name property? "setProperty" does not appear to work, and is probably not what I need (from the ArcPy Raster page: "Add a customized property to the raster dataset").

EDIT: added screenshot from FileGDB raster datasets.

0 Kudos
5 Replies
DanPatterson
MVP Esteemed Contributor

According to the help, you specify it using save

Distance Accumulation (Spatial Analyst)—ArcGIS Pro | Documentation

outDistAcc = DistanceAccumulation("insources.shp", "barriers.tif")
outDistAcc.save("c:/sapyexamples/output/distacc.tif")


... sort of retired...
0 Kudos
DavidPike
MVP Frequent Contributor

path_dist_acc_raster has the output path and name and this is not working?

0 Kudos
ChristaRohrbach
New Contributor II

Thanks for the quick answer. Yes, the raster is saved with the correct name in the FileGDB, but when added to a map, shown with name "Distanc_{suffix}".

0 Kudos
DanPatterson
MVP Esteemed Contributor

As a test, try saving it as a *.tif in a folder instead.

If it behaves as expected, perhaps the gdb uses an alias or just ignores anything after.

You could also examine the script to see if anything looks like it might be useful to solving this issue

C:\... your install folder ... \Resources\ArcToolBox\Scripts\distanceaccumulation.py


... sort of retired...
0 Kudos
ChristaRohrbach
New Contributor II

I just tested saving the accumulated distance rasters as TIF files and this works fine. In the FileGDB they are also saved with their correct name, as displayed in the Catalog pane, but in the Contents pane the default name is displayed. This is why I thought I might have to explicitely set some property.

On a side note, the back direction rasters are displayed correctly in the Contents pane. The difference to the accumulated distance raster is that there is a parameter to set the name.

I will check if I find something useful in distanceaccumulation.py tomorrow (its already late here), thank you for the hint.

0 Kudos