Skip to content

Instantly share code, notes, and snippets.

@jeaneric
Created November 28, 2012 15:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeaneric/4162013 to your computer and use it in GitHub Desktop.
Save jeaneric/4162013 to your computer and use it in GitHub Desktop.
ArcGIS create footprint for raster folder
#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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment