I have been loading existing raster data into a geodatabase to be included in a new Mosaic Dataset–a very cool and useful addition to ArcGIS 10. The most time-consuming part of the process for the human (at least this human) has been getting the names of the rasters right.
Our existing data is organized by tiles with the directory name representing the tile name and then the data within each tile directory having the same name.
This makes batch loading the data less efficient because I end up having to rename the data or else end up with a series of feature classes named parcels, parcels_2, parcels_n.
So I hacked out a quick script that takes an input raster and figures out the final name I want it to have based of the directory name.
First, I used the Copy Raster (In ArcToolbox: Data Management-Raster-Raster Dataset-Copy Raster) and copied on sample to my geodatabase.
Then, I went to the Results Tab (Select Geoprocessing from the Menubar, Geoprocessing-Results) and right-clicked on the Copy Raster result and selected “Copy as Python Snippet”.
I then created a new python script and pasted the one line.
I added some imports, accepted a parameter, some string manipulation, and some result outputs and I had a quick & easy script. In added the script in ArcToolbox and now I can right-click on it and run it in Batch mode. I do a quick search in Windows Explorer to get all the rasters I want to run it on and select & drag them to my ArcToolbox Batch Dialog.
Actual code can be downloaded HERE and you don’t need to worry about WordPress messing up the spacing.
import arcpy import os, sys inRaster = sys.argv basedir = os.path.basename(os.path.dirname(inRaster)).lower() outRaster = "Database Connections/mgs_lidar.lidar.sde/mgs_lidar.lidar."+basedir def printit(inMessage): print inMessage arcpy.AddMessage(inMessage) if not (arcpy.Exists(outRaster)): printit ("Importing: "+basedir) arcpy.CopyRaster_management(inRaster,outRaster,"#","#","#","NONE","NONE","#") else: printit ("Skipping: "+basedir+" because it already exists!")