4

I'm trying to save filled raster object to geo database by my specified filename.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = r"C:\GIS Data\Cameron_Run\Topo_NED\Projected"
# Set local variables
surfaceRaster = "raw_10m_dem"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute FlowDirection
fillRaster = Fill(surfaceRaster)
arcpy.RasterToGeodatabase_conversion(fillRaster, r"C:\GIS Data\Cameron_Run\Topo_NED
\Projected\fillRasterGDB.gdb")

But this code is saving raster file by its own specified name, for this case Fill_raw_10m1 is the default name of saved raster file.

Is there any way so that I can specify the name of saved raster file?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked May 22, 2012 at 13:05
4
  • Have you considered renaming or copy with new name raster before executing RasterToGeodatabase ? Commented May 22, 2012 at 13:12
  • RasterToGeodatabase_conversion doesn't provide any option to save as your specified name. You can only specify the output geo database path Commented May 22, 2012 at 13:15
  • Yes, thats why I proposed to RENAME raster file (i.e. with os.rename()) before running RasterToGeodatabase_conversion. You can also use Rename tool from ArcToolbox. Commented May 22, 2012 at 13:19
  • 1
    your paths are not in the correct format, either use raw format r"C:\GIS Data\Cameron_Run\Topo_NED\Projected" or double backslashes or single foreslashes Commented May 22, 2012 at 13:20

2 Answers 2

11

It looks like you've looked at ESRI's example because your comment says "Execute FlowDirection" - which is the error in ESRI's docs, but I'll pull out the important part that your code is missing - the save() method for your fill object.

Generally, the Spatial Analyst tools work a little differently in scripting than some of the other toolbox tools since they generate a return value that is an object (rather than taking input and output locations). Once you have the Fill object living in memory, you can save it using the object's save method. So, in your code above:

# run Fill on surfaceRaster and put output object into fillRaster
fillRaster = Fill(surfaceRaster)
# note the specification of a dataset name in the gdb below
outname = r"C:\GIS Data\Cameron_Run\Topo_NED\Projected\fillRasterGDB.gdb\fillRaster"
# save the fillRaster object to the location specified in outname
fillRaster.save(outname)

So, just run save, and pass in a location in order to specify where it goes. My understanding is that the RasterToGeodatabase tool doesn't accept Spatial Analyst objects as inputs.

answered May 22, 2012 at 18:17
1

It is possible to use next options:

  1. If it is file-based raster then you can rename it with os.rename() function before using RasterToGeodatabase_conversion tool. But don't forget all supplementing files (i.e. tfw, ovr). I believe this is a faster method than second one.
  2. You can use tool Rename_management from ArcToolbox in any step.
answered May 22, 2012 at 13:25
4
  • 1
    First of all, ArcGIS is saving the file by its own specified name. I'm not sure what pattern it's following to give names. If I don't know the name of file for sure, how can I rename it? Commented May 22, 2012 at 13:29
  • If you are talking about Fill then it has return value "out_surface_raster" (as stated in the help). Which I believe you can use. Have you checked example "Fill example 2 (stand-alone script)" in Fill help ? They are saving results there... Commented May 22, 2012 at 13:39
  • Oh, this is another issue. ArcGIS is not saving data in grid format, though it's saving data in img and tif format. Commented May 22, 2012 at 16:29
  • You can then convert it to GRID with RasterToOtherFormat_conversion tool. Commented May 22, 2012 at 16:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.