2

I'm creating a model in the ArcGIS 10.3 ModelBuilder and have problems to get the select data tool to work. At first the complete model: IHS-Klassifizierung With the Select Data tool (Input Data Element: Raster, Child Data Element: %layerband%_1) I'm selecting Band_1 or Band_3 from a Rasterfile, for this I need to check with Calculate Value if the Bands are called "Layer_x" or "Band_x" (In my raster data are different names and I mustn't change them), with the following code:

def x(Rasterfile):
import arcpy            # I think this is not necessary, but I'm not sure   
desc = arcpy.Describe(Rasterfile)       # Get the necessary information
bandlayer = desc.children[0].name       # select the first band
ergebnis = str(bandlayer.split("_",1)[0])   # Remove the _ and the number from the Name
return ergebnis

as Expression I use x("%Rasterfile%") and Date type String.

When I run the model on my sample data (just one raster file) I get the following error:

Executing: IHS-Klassifizierung W:\arctest W:\arctest\output
Start Time: Tue Nov 03 16:39:06 2015
Executing (Iterate Rasters): IterateRasters W:\arctest # # NOT_RECURSIVE
Start Time: Tue Nov 03 16:39:06 2015
Succeeded at Tue Nov 03 16:39:07 2015 (Elapsed Time: 0,52 seconds)
Executing (Parse Path (2)): ParsePath W:\arctest\orthoclip.tif FILE
Start Time: Tue Nov 03 16:39:07 2015
Succeeded at Tue Nov 03 16:39:07 2015 (Elapsed Time: 0,00 seconds)
Executing (Calculate Value): CalculateValue x("orthoclip.tif") 
"def x(Rasterfile):\n   
import arcpy                
desc = arcpy.Describe(Rasterfile)       
bandlayer = desc.children[0].name       
ergebnis = str(bandlayer.split("_",1)[0])       
return ergebnis\n" 
String
Start Time: Tue Nov 03 16:39:07 2015
Value = Band
Succeeded at Tue Nov 03 16:39:07 2015 (Elapsed Time: 0,04 seconds)
Executing (Select Data): SelectData W:\arctest\orthoclip.tif Band_1
Start Time: Tue Nov 03 16:39:07 2015
**Failed to execute. Parameters are not valid.**
**ERROR 000800: The value is not a member of Band_1 | Band_2 | Band_3 | Band_4.**
Failed to execute (Select Data).
Failed to execute (IHS-Klassifizierung).

If I try it without the Calculate Value Tool and put in the Select Data- Child Data Element directly Band_1 or Band_3 it works.

Sometimes it happens (I can't figure out why and I don't connect it to changes witch I made) that the following error appears:

Executing: IHS-Klassifizierung W:\arctest W:\arctest\output
Start Time: Wed Nov 04 13:23:47 2015
Executing (Iterate Rasters): IterateRasters W:\arctest # # NOT_RECURSIVE
Start Time: Wed Nov 04 13:23:47 2015
Succeeded at Wed Nov 04 13:23:47 2015 (Elapsed Time: 0,35 seconds)
Executing (Parse Path (2)): ParsePath W:\arctest\orthoclip.tif FILE
Start Time: Wed Nov 04 13:23:47 2015
Succeeded at Wed Nov 04 13:23:47 2015 (Elapsed Time: 0,00 seconds)
Executing (Calculate Value): CalculateValue x("orthoclip.tif") "def x(Rasterfile):\n    
import arcpy\n  
desc = arcpy.Describe(Rasterfile)       \n  
bandlayer = desc.children[0].name       \n  
ergebnis = bandlayer.split("_",1)[0]        \n  
return ergebnis\n" 
String
Start Time: Wed Nov 04 13:23:47 2015
ERROR 000539: Error running expression: x("orthoclip.tif") 
Traceback (most recent call last):
  File "<expression>", line 1, in <module>
  File "<string>", line 3, in x
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\__init__.py", line 1246, in Describe
    return gp.describe(value)
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\geoprocessing\_base.py", line 374, in describe
    self._gp.Describe(*gp_fixargs(args, True)))
IOError: "orthoclip.tif" does not exist

Failed to execute (Calculate Value).
Failed at Wed Nov 04 13:23:48 2015 (Elapsed Time: 0,28 seconds)
Failed to execute (IHS-Klassifizierung).
Failed at Wed Nov 04 13:23:48 2015 (Elapsed Time: 0,93 seconds) 

migrated from stackoverflow.com Nov 19 '15 at 20:44

This question came from our site for professional and enthusiast programmers.

  • Can you show us the output from when you try it without the Calculate Value Tool and put in the Select Data- Child Data Element directly Band_1 or Band_3 and it works? Does the call to SelectData look any different than what you've shown us (SelectData W:\arctest\orthoclip.tif Band_1)? – Gary S. Nov 3 '15 at 21:34
  • 1
    That's what I tried before, it works without problems, Executing (Select Data): SelectData W:\arctest\orthoclip.tif Band_1 Succeeded at Wed Nov 04 13:16:25 2015 (Elapsed Time: 0,04 seconds) Executing (Select Data (2)): SelectData W:\arctest\orthoclip.tif Band_3 – leFörster Nov 4 '15 at 12:18
1

I found a solution: In this case it's stupid to use the "Select Data" tool, because you can use directly the calculate value tool for getting the complete paths to the Bands. Changed Model

The python code from calculate value tool (expression x(r"%Raster%"), DataType Raster Band):

def x(rasterimage):
    import arcpy
    desc = arcpy.Describe(rasterimage)
    bandlayer = desc.children[0].name
    ergebnis = bandlayer.split("_",1)[0]
    pfad = r"%Raster%\%s_1" % ergebnis
    return pfad

Works fine now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.