Layer references a C:\Users\jdoe\AppData\Local\Temp\***.afr file

1355
2
02-11-2011 09:30 AM
MannyGimond
New Contributor III
This is a follow-up to my last post.

The following code does a proper job in creating both raster and layer files in a user defined directory (c:/tmp/ in this example), however, the layer file points to a temporary(?) .afr file under C:\Users\jdoe\AppData\Local\Temp\***.afr instead of pointing to the raster layer. ArcMap does not seem to have a problem displaying the layer when loaded in a layout, however, when trying to perform a map algebra operation on that layer, ArcMap returns an error stating that the raster cannot be found (i.e. it is looking for the .afr file).

Any idea what may be going on? I'm using version 10 SP1.

...
YMAP = arcpy.NumPyArrayToRaster(YmapArray,lowerLeft,pixSi ze,pixSize)
YMAP.save(YmapFile)
...
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.MakeRasterLayer_management(YmapFile,"Y Map")
ymapLyr = arcpy.mapping.Layer(r"c:/tmp/YMAP.lyr")
Tags (2)
0 Kudos
2 Replies
JosephBarraud
New Contributor II
I had the same problem. The raster layer is created with an "Identity Function" that points to the raster file.
I suggest you add the following lines to your code. This will correct the path to the right location.

ymapLyr.replaceDataSource(new_workspace_path,"NONE",raster_filename)
ymapLyr.save()


Joseph
0 Kudos
MannyGimond
New Contributor III
Thanks Joseph. The function replaceDataSource resolved the issue I had with the LYR files pointing to a temporary .afr location.

Now the remaining issue I have occurs when the script is run within an open map document. After the layer is created and added to the TOC, the Raster Calculator still seems to think that the LYR file is pointing to the temporary raster directory. Interestingly, other spatial analyst functions such as Times and Hillshade are properly reading the layer's source path. Now if the LYR file is loaded in a new map document, the Raster Calculator will correctly read the LYR's source location.

Having a raster layer added to an existing TOC is beginning to make up the bulk of my code! Hopefully ESRI will come up with a simpler function to complete this task.
0 Kudos