Skip to content

Instantly share code, notes, and snippets.

@danmaps
Last active July 16, 2020 19:30
Show Gist options
  • Save danmaps/76b27c1a86b3f81ed20edda1a3d5cbf6 to your computer and use it in GitHub Desktop.
Save danmaps/76b27c1a86b3f81ed20edda1a3d5cbf6 to your computer and use it in GitHub Desktop.
based on a discussion at the 2020 virtual UC
layer = 'grid' # if running this script outside of ArcGIS, this should be a full path to a feature class, not a layer name
fields = ['ID'] # this is field which matches the .tif filename
tif_folder = r'c:\my_tifs'
out_folder = r'c:\output'
with arcpy.da.SearchCursor(layer, fields) as cursor:
for r in cursor: # for each row in the layer:
print(r[0]) # print the ID
tif_file = os.path.join(tif_folder,r[0]+'.tif') # get the path to the matching .tif file (c:\my_tifs\01234.tif)
tif_destination = os.path.join(out_folder,r[0]+'.tif') # set up the path to copy it to (c:\c:\output\01234.tif)
arcpy.Copy_management(tif_file,tif_destination) # execute the copy tool
# this will repeat for each row in the input feature class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment