It does not seem to recognize my for in loop of the RasterImage - any ideas? The print statment after the loop shows that it is recognizing the file (in python) but that the spatial analyses used in arcpy are not.

I thought it might have to do something with the workspace used so I thought that adding

RasterImage = InputFolder + '\\' + RasterImage

might help locate the full path of the raster datasets but to no avail! Im lost for ideas and the only help files that utilize spatial analyses on the ArcGIS resource page do not utilize loops in their scripts. ¨

UPDATE

Issue has been resolved by implementing the following:

The original question displaying the error 'RasterImage' does not exist was cause in part due to the '' marks and the spaces around the NbrRectangle. I have implemented part of my new code using the suggestions by nmpeterson whereby the geoprocessing is called through the function

While methodologies in which several temporary files rely on one another (i.e. a geoprocess within another geoprocess) i've used the .save function into a temporary directory as shown by om_henners before deleting all those contents afterwards.

2 Answers
2

In the line Temp4 = FocalStatistics('RasterImage', NbrRectangle (9, 9, 'CELL'), "RANGE", "DATA"), you need to remove the single-quotes around RasterImage -- it is being treated as a string literal and looking for a file called RasterImage.

Edit: Thinking about this some more, I'm wondering if the script is failing because you initialize Temp4 as a string but then redefine it as whatever the return type of FocalStatistics is -- I'm not sure if it's handled as a string or not.

The only case on that page using quotes (that I can see) is the elevation example, where "elevation" is the actual filename of the raster in the workspace. Have you also tried removing the space between NbrRectangle and the following (?
–
nmpetersonNov 29 '11 at 17:39

I edited my original answer with a new suggestion: creating a new function to avoid having to define Temp4 outside of the for-loop.
–
nmpetersonNov 29 '11 at 17:53

Alright I will try that again tomorrow... thanks for your response once more!
–
BJEBNNov 29 '11 at 18:00

As @nmpeterson says above, the first issue comes down to the quotes around the RasterImage variable name.

However the big thing is that you are overwriting the variable Temp4 with the contents of the raster. Instead, according to the FocalStatistics documentation from ESRI, the raster object returned has a save(path) method.

I'm assuming you don't want to overwrite your output each time, so one quick way of getting a temporary name is in Python using tempfile.NamedTemporaryFile(dir="working_dir").name - however this won't store a reference to the original Raster, which I'll assume you want, so we can do it slightly differently as follows (assuming you're using Info rasters - if you're using a .tif, .png etc you'll have to strip the file extension before creating the new file):

Of course I can't really speak for @BJEBN, but I don't think this is necessary in this case. Since the file is clearly a temp file (as evidenced by the name "temp4"), there is no reason to ever save the file -- whether temporary or not. Rather, the input raster for the next process (which was left out of the example here) can simply be specified by the FocalStatistics() function (or the focalStats() function I wrote above), since the processing has to occur within the for-loop anyway.
–
nmpetersonNov 29 '11 at 23:27

Ideally I would like to utilize those as temp files rather than saving the file...however i've found that when one has several temp files that rely on one another - this cannot be done without saving the file first. i.e. def rc(raster): Temp3 = Raster(FocalStats(raster)) / 2 return Temp 3 where FocalStats refers to that suggested by nmpeterson above. As for the original question - it was a combination of the '' around the rasterimage and the space around NbrRectangle
–
BJEBNNov 30 '11 at 11:08

Well, one possibility would be to add the saved raster datasets to a list, and then after processing loop through them and delete them with arcpy.Delete_management(dataset)
–
om_hennersNov 30 '11 at 12:27