Created
March 1, 2018 16:28
-
-
Save mu88/8a1c7590b2a548f9aac8e18f7c8860e8 to your computer and use it in GitHub Desktop.
ArcPy - List all Rasters within File Geodatabase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arcpy, codecs, csv, os, shutil | |
os.system("cls") | |
origFgdbLocation = r"\\Server\Share" | |
origFgdbNames = ["MyFileGeodatabase1", "MyFileGeodatabase2", "MyFileGeodatabase3"] | |
csvFilePath = r"C:\temp\members.csv" | |
elements = [] | |
for fgdbName in origFgdbNames: | |
print "Start FGDB '" + fgdbName + "'" | |
origFgdbPath = origFgdbLocation + os.path.sep + fgdbName + ".gdb" | |
arcpy.env.workspace = origFgdbPath | |
for fds in arcpy.ListDatasets(): | |
print "Start feature dataset '" + fds + "'" | |
arcpy.env.workspace = os.path.join(origFgdbPath, fds) | |
rasters = arcpy.ListRasters() | |
for raster in rasters: | |
currentElement = [fgdbName, fds, raster, "raster"] | |
elements.append(currentElement) | |
arcpy.env.workspace = origFgdbPath | |
print "Finish feature dataset '" + fds + "'" | |
print "Start root rasters" | |
arcpy.env.workspace = origFgdbPath | |
rasters = arcpy.ListRasters() | |
for raster in rasters: | |
currentElement = [fgdbName, "", raster, "raster"] | |
elements.append(currentElement) | |
print "Finish root rasters" | |
print "Finish FGDB '" + fgdbName + "'" | |
print "Finish all" | |
f = codecs.open(csvFilePath, "w", encoding="utf-8") | |
f.write("FGDB; Dataset; Element; Type\n") | |
for element in elements: | |
f.write(element[0] + "; " + element[1] + "; " + element[2] + "; " + element[3] + "\n") | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment