Select to view content in your preferred language

Saving output with predefined name

2273
3
Jump to solution
01-28-2016 11:50 AM
ShawnKasprick
New Contributor

I am trying to clip a raster and save the output with a predefined name to a file geodatabase which will be defined by the user as a parameter.  I have tried two different angles, and both give me errors.

Trial 1

# Import modules

import arcpy

from arcpy import env

from arcpy.sa import *

# Input Parameters

Boundary = arcpy.GetParameterAsText(0)

InRaster = arcpy.GetParameterAsText(1)

GDBLoc = arcpy.GetParameterAsText(2) # data type set as workspace

# Clip Raster

Raster = arcpy.Clip_management(InRaster, "", "in_memory", Boundary, "0", "ClippingGeometry", "NO_MAINTAIN_EXTENT")

RasName = ("GDBLoc" + "\\PredefinedName")

Raster.save(RasName)

Results in:

AttributeError: 'Result' object has no attribute 'save'

Trial 2

# Import modules

import arcpy

from arcpy import env

from arcpy.sa import *

# Input Parameters

Boundary = arcpy.GetParameterAsText(0)

InRaster = arcpy.GetParameterAsText(1)

GDBLoc = arcpy.GetParameterAsText(2) # data type set as workspace

# Clip Raster

Raster = arcpy.Clip_management(InRaster, "", "GDBLoc + \\PredefinedName", Boundary, "0", "ClippingGeometry", "NO_MAINTAIN_EXTENT")

Results in:

ExecuteError: ERROR 999999: Error executing function.

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Shawn,

In the second example, the issue is that you are placing quotes around the GDBLoc variable.  This will cause the variable to be read as a string.

Try the following:

# Import modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Input Parameters
Boundary = arcpy.GetParameterAsText(0)
InRaster = arcpy.GetParameterAsText(1)
GDBLoc = arcpy.GetParameterAsText(2) # data type set as workspace

arcpy.Clip_management(InRaster, "", GDBLoc + "\\PredefinedName", Boundary, "0", "ClippingGeometry", "NO_MAINTAIN_EXTENT")

View solution in original post

3 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Shawn,

In the second example, the issue is that you are placing quotes around the GDBLoc variable.  This will cause the variable to be read as a string.

Try the following:

# Import modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Input Parameters
Boundary = arcpy.GetParameterAsText(0)
InRaster = arcpy.GetParameterAsText(1)
GDBLoc = arcpy.GetParameterAsText(2) # data type set as workspace

arcpy.Clip_management(InRaster, "", GDBLoc + "\\PredefinedName", Boundary, "0", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
ShawnKasprick
New Contributor

That worked exactly as I was hoping!!  Thanks!

0 Kudos
AdrianWelsh
MVP Honored Contributor

I'm not really sure but have you verified that the user enter variables are coming out the way they should be? What I do while testing is to do a few prints just to make sure that the output locations and things like that are looking how they are supposed to look.

Can you see if the geodatabase is locked (like, can you perform this clipping without Python to make sure it works)?

Also, for saving, doesn't the Clip_management command save to a variable in its options (as opposed to having to save the raster later on)?

This article shows that the third parameter in Clip_management is the output raster:

Clip—Help | ArcGIS for Desktop

0 Kudos