# import the needed modules import arcpy, os arcpy.env.overwriteOutput = True ########################################## ## VARIABLE SECTION - MODIFY THIS SECTION ONLY # here's where you need to define some variables # The following variable is for setting the workspace to a directory of rasters: arcpy.env.workspace = r'F:\12109\2011 aerials' # ...variable for the polygon shapefile or feature class for the raster outline (grid) output pathname, for example: GridName = r'C:\temp\test.shp' # ...variable, a numeric value, specifying the text field length needed to hold the pathname... # If it is a long pathname, then a longer field length will be required: IMAGEfldLen = 200 ## END VARIABLE SECTION - DO NOT MODIFY BELOW THIS LINE ######################################### outPath, outName = GridName.rsplit(os.sep, 1) arcpy.CreateFeatureclass_management(outPath, outName, 'POLYGON') fields = ['IMAGE', 'XMIN', 'XMAX', 'YMIN', 'YMAX'] arcpy.AddField_management(GridName, fields[0], 'TEXT', '', '', IMAGEfldLen) for i in range(1, 5): arcpy.AddField_management(GridName, fields, 'DOUBLE', 18, 17) rasters = arcpy.ListRasters() 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 = os.path.join(arcpy.env.workspace, 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 outRows
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.