Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

looping through rasters in an mxd

$
0
0
Hi all, newbie question here. I'd like to use the Python window to write a piece of code which loops through all the rasters in an mxd, and creates a polygon of the outline of each raster.

The Raster Domain tool in the 3D analyst extension works well for this task. However, when I try and use the code snippet in the Python window, I encounter the following problem. When I go to type in the In Raster ("dtm_grd") in the example below, I get a drop down list of all the rasters in my mxd. If I choose one from this list, I then get an error message that the raster "does not exist or is not supported". However, if I change the environment to the folder where the raster is currently located, and copy the source of the raster from the Properties box, the tool executes successfully.

Is there a way of looping through these layers, without having to manually change the address for each one? I know (very roughly) how to loop through a list of layers in python, but there doesn't seem much point trying if I can't get the Python snippet to work on even one layer.

nb not using the Raster to Polygon tool as most of the rasters are floating point and would need to be converted to integer before this tool would work.

Code:

arcpy.CheckOutExtension("3D")
env.workspace = "C:/data"
arcpy.RasterDomain_3d("dtm_grd", "raster_domain.shp", "POLYGON")


Viewing all articles
Browse latest Browse all 2485

Trending Articles