Hello all,
I currently have over 4000 .tif raster data that have to be loaded into a SDE Raster Catalog in ArcGIS 9.3.1. I had been manually uploading 1800 in batches using the Raster to Geodatabase (multiple) tools. I want to look into python script for the automation of the process.
Details of the data: All the .tifs are in 1 folder, 18mbs each, 8bits and JPEG compression (the purpose is for visual purpose so dont have to perform and image analysis)
I am very new to python script so if anyone of you can point me to the right direction.
I have found this old Batch Raster to GDB python script and modified to my specifics...
## Script Name: raster2gdb.py
## Description: Imports a raster into a geodatabase.
#-------------------------------------------------------------------------------
# function usage
#-------------------------------------------------------------------------------
def usage():
print " USAGE: raster2gdb.py <raster> <geodatabase>"
sys.exit(1)
#-------------------------------------------------------------------------------
# function bailout
#-------------------------------------------------------------------------------
def bailout(errMsg):
print " ERROR: "+errMsg
sys.exit(0)
#===============================================================================
# main routine
#===============================================================================
import sys, string, os, arcgisscripting
gp = arcgisscripting.create()
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")
# first argument is the input raster
try:
InRaster = "G:\\Teranet2013\\Simcoe_2012_tiles\\final\\ORTH175820495802012FBS.tif"
except:
usage()
# second argument is the geodatabase to import the raster into
try:
OutGDB = "Database Connections\\Connection to PSGISTEST01-Raster.sde\\Raster.PSGIS.SimcoeRegion"
except:
usage()
# does raster exist?
if not gp.exists(InRaster):
bailout("Raster "+InRaster+" does not exist")
# does geodatabase exist?
if not gp.exists(OutGDB):
bailout("Geodatabase "+OutGDB+" does not exist")
gp.pyramid = "PYRAMIDS -1 BILINEAR"
#gp.pyramid = "PYRAMIDS -1 CUBIC"
gp.rasterStatistics = "NONE"
gp.compression = "LZ77"
gp.tilesize = "128 128"
# start reporting
import time
me=os.path.splitext(os.path.basename(sys.argv[0]))[0]
print me,"started at: " + str(time.asctime())
timestamp=time.clock()
try:
# Process: RasterToGeodatabase_conversion
print "Loading " + InRaster + " to " + OutGDB
gp.RasterToGeodatabase_conversion(InRaster,OutGDB,"#")
print "Finished loading " + InRaster
except:
# If an error occurred print the message to the screen
print gp.GetMessages()
# report time
delta=time.clock()-timestamp
timestamp=time.clock()
print me,"successfully finished: ",str(time.asctime())
print "Total time: ",str(delta / 60)," minutes\n"
this script runs good but only process 1 specific file at a time. I was wondering if anyone can give me some help in making a loop to process the 4000+ files in the one folder.
I have look into loop and this is what I try to in corporate in my script to run all the .tifs files in that one folder.
# For loop iterates through every file in input folder
for found_file in os.listdir(G:\Teranet2013\Simcoe_2012_tiles\final):
# Searches for .tif files
if found_file.endswith(".tif"):
print "Converting: "+foundfile
InRaster = os.path.join(input_folder, found_file)
So if anyone can give me some guidance in automating batch raster to geodatabase that would be much appreciated!
Thanks,
Tony
I currently have over 4000 .tif raster data that have to be loaded into a SDE Raster Catalog in ArcGIS 9.3.1. I had been manually uploading 1800 in batches using the Raster to Geodatabase (multiple) tools. I want to look into python script for the automation of the process.
Details of the data: All the .tifs are in 1 folder, 18mbs each, 8bits and JPEG compression (the purpose is for visual purpose so dont have to perform and image analysis)
I am very new to python script so if anyone of you can point me to the right direction.
I have found this old Batch Raster to GDB python script and modified to my specifics...
## Script Name: raster2gdb.py
## Description: Imports a raster into a geodatabase.
#-------------------------------------------------------------------------------
# function usage
#-------------------------------------------------------------------------------
def usage():
print " USAGE: raster2gdb.py <raster> <geodatabase>"
sys.exit(1)
#-------------------------------------------------------------------------------
# function bailout
#-------------------------------------------------------------------------------
def bailout(errMsg):
print " ERROR: "+errMsg
sys.exit(0)
#===============================================================================
# main routine
#===============================================================================
import sys, string, os, arcgisscripting
gp = arcgisscripting.create()
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")
# first argument is the input raster
try:
InRaster = "G:\\Teranet2013\\Simcoe_2012_tiles\\final\\ORTH175820495802012FBS.tif"
except:
usage()
# second argument is the geodatabase to import the raster into
try:
OutGDB = "Database Connections\\Connection to PSGISTEST01-Raster.sde\\Raster.PSGIS.SimcoeRegion"
except:
usage()
# does raster exist?
if not gp.exists(InRaster):
bailout("Raster "+InRaster+" does not exist")
# does geodatabase exist?
if not gp.exists(OutGDB):
bailout("Geodatabase "+OutGDB+" does not exist")
gp.pyramid = "PYRAMIDS -1 BILINEAR"
#gp.pyramid = "PYRAMIDS -1 CUBIC"
gp.rasterStatistics = "NONE"
gp.compression = "LZ77"
gp.tilesize = "128 128"
# start reporting
import time
me=os.path.splitext(os.path.basename(sys.argv[0]))[0]
print me,"started at: " + str(time.asctime())
timestamp=time.clock()
try:
# Process: RasterToGeodatabase_conversion
print "Loading " + InRaster + " to " + OutGDB
gp.RasterToGeodatabase_conversion(InRaster,OutGDB,"#")
print "Finished loading " + InRaster
except:
# If an error occurred print the message to the screen
print gp.GetMessages()
# report time
delta=time.clock()-timestamp
timestamp=time.clock()
print me,"successfully finished: ",str(time.asctime())
print "Total time: ",str(delta / 60)," minutes\n"
this script runs good but only process 1 specific file at a time. I was wondering if anyone can give me some help in making a loop to process the 4000+ files in the one folder.
I have look into loop and this is what I try to in corporate in my script to run all the .tifs files in that one folder.
# For loop iterates through every file in input folder
for found_file in os.listdir(G:\Teranet2013\Simcoe_2012_tiles\final):
# Searches for .tif files
if found_file.endswith(".tif"):
print "Converting: "+foundfile
InRaster = os.path.join(input_folder, found_file)
So if anyone can give me some guidance in automating batch raster to geodatabase that would be much appreciated!
Thanks,
Tony