arcpy.CheckOutExtension("3D") env.workspace = "C:/data" arcpy.RasterDomain_3d("dtm_grd", "raster_domain.shp", "POLYGON")
Solved! Go to Solution.
#Script to loop through rasters in an mxd, and print a shape file of their extent.
# Based on script at the following forum link: http://forums.arcgis.com/threads/74002-Create-index-outline-of-rasters?p=258761#post258761
mxd = arcpy.mapping.MapDocument("CURRENT")
GridName = "boundaries"
IMAGEfldLen = 50
arcpy.CreateFeatureclass_management("<file path for directory which will contain shapefile>", "<insert name of shapefile>", "POLYGON")
fields = ['IMAGE', 'XMIN', 'XMAX', 'YMIN', 'YMAX']
arcpy.AddField_management("<insert name of shapefile>", fields[0], "TEXT", '', '', IMAGEfldLen)
for i in range(1,5):
arcpy.AddField_management(GridName, fields, "DOUBLE", 18, 17)
print "added field: " + fields
rasters = arcpy.mapping.ListLayers(mxd)
arrayObj = arcpy.CreateObject('Array')
outRows = arcpy.InsertCursor(GridName)
for raster in rasters:
extent = arcpy.Describe(raster).extent
arrayObj.add(extent.lowerleft)
arrayObj.add(extent.lowerright)
arrayObj.add(extent.upperright)
arrayObj.add(extent.upperleft)
arrayObj.add(extent.lowerleft)
feat = outRows.newRow()
feat.Shape = arrayObj
image = '.\\' + str(raster)
feat.setValue('IMAGE', image)
feat.setValue('XMIN', extent.xmin)
feat.setValue('YMIN', extent.ymin)
feat.setValue('XMAX', extent.xmax)
feat.setValue('YMAX', extent.ymax)
outRows.insertRow(feat)
arrayObj.removeAll()
del outRowsgp.AddField_management(GridName, fields[0], 'TEXT', '', '', IMAGEfldLen)
>>> fields = ['IMAGE', 'XMIN', 'XMAX', 'YMIN', 'YMAX'] >>> for i in range(0, 5): # or for i in range(5): print fields IMAGE XMIN XMAX YMIN YMAX
>>> for field in fields: print field IMAGE XMIN XMAX YMIN YMAX
#Script to loop through rasters in an mxd, and print a shape file of their extent (exact boundary, not just polygon).
import arcpy
from arcpy import env
arcpy.CheckOutExtension("3D")
mxd = arcpy.mapping.MapDocument(r"J:\gisprojects\Project\330\80000_89999\3308480_SS_GIS\0051_LiDAR_Index\mxd\ras_to_polygon_test.mxd")
env.workspace = r"J:\gisprojects\Project\330\80000_89999\3308480_SS_GIS\0051_LiDAR_Index\data\shpfile_ras_boundaries"
rasters = arcpy.mapping.ListLayers(mxd)
for raster in rasters:
#Generate a unique name for each polygon
outPoly = "domain_" + str(raster) + ".shp"
#Execute Raster Domain Tool
arcpy.RasterDomain_3d(raster, outPoly, "POLYGON")
print "finished"