Select to view content in your preferred language

how to use calculate value an "exists" in Modelbuilder to check if raster file exists

2621
1
08-28-2012 03:39 AM
JonathanWinn
Deactivated User
How can "exists" be used in Modelbuilder to check if a raster dataset exists?

I have checked through all help files, regarding the If / Then and branching. They give a good example to check for a feature class, but i cant get this to work for a raster dataset.

I have created the initial part of a simple model to try to get the calculate value to return a treu / fals eif a raster dataset exists. This modle works when the check is with a feature class and the model contains the feature class as a variable.

However when i use the same logic, but with a raster dataset it does not work, it returns false even though the raster dataset is present in the gdb.

The raster datset and the feature class are both present in the .gdb, and both are present as variables in the model.

i dont understand why this does not work for the raster datset.

any help would be appreciated.

in this example "test1" is a raster dataset and "selection_5" is a feature class

cheers, 
[ATTACH=CONFIG]17282[/ATTACH][ATTACH=CONFIG]17283[/ATTACH][ATTACH=CONFIG]17284[/ATTACH]Jonathan

the code that works for the feature class is

expression
x("%selection_5%","%Workspace%")

code block

def x(selection_5, Workspace):
    import arcpy
    arcpy.env.workspace = Workspace
    if arcpy.Exists(selection_5):
        return "true"
    else:
        return "false"

the code that does not work for the raster dataset (gives false when should be true)

expression

x("%test1%","%Workspace%")

code block

def x(test1, Workspace):
    import arcpy
    arcpy.env.workspace = Workspace
    if arcpy.Exists(test1):
        return "true"
    else:
        return "false
0 Kudos
1 Reply
curtvprice
MVP Esteemed Contributor
How can "exists" be used in Modelbuilder to check if a raster dataset exists?


Please use code blocks in your posts. It helps more than you think!

Normally the way this is done is to simply use a raster element as a precondition to a tool. If the dataset does not exist, it will prevent the tool from running.
0 Kudos