public
Last active

ArcGIS create footprint for raster folder

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#Inspired by the code present in this answer:
#http://gis.stackexchange.com/a/26944/2043
 
import arcpy,os
 
def main():
InFolder = arcpy.GetParameterAsText(0)
Dest=arcpy.GetParameterAsText(1)
arcpy.env.workspace=InFolder
#The raster datasets in the input workspace
in_raster_datasets = arcpy.ListRasters()
arcpy.CreateFeatureclass_management(os.path.dirname(Dest),
os.path.basename(Dest),
"POLYGON")
arcpy.AddField_management(Dest,"RasterName", "String","","",250)
arcpy.AddField_management(Dest,"RasterPath", "String","","",250)
cursor = arcpy.InsertCursor(Dest)
point = arcpy.Point()
array = arcpy.Array()
corners = ["lowerLeft", "lowerRight", "upperRight", "upperLeft"]
for Ras in in_raster_datasets:
feat = cursor.newRow()
r = arcpy.Raster(Ras)
for corner in corners:
point.X = getattr(r.extent, "%s" % corner).X
point.Y = getattr(r.extent, "%s" % corner).Y
array.add(point)
array.add(array.getObject(0))
polygon = arcpy.Polygon(array)
feat.shape = polygon
feat.setValue("RasterName", Ras)
feat.setValue("RasterPath", InFolder + "\\" + Ras)
cursor.insertRow(feat)
array.removeAll()
del feat
del cursor
if __name__ == '__main__':
try:
main()
except Exception, e:
import traceback
map(arcpy.AddError, traceback.format_exc().split("\n"))
arcpy.AddError(str(e))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.