timtee

Split and convert raster files

Discussion created by timtee on May 2, 2013
Latest reply on May 11, 2014 by hillaryhall
Hey guys,
i am pretty new to scripting with python in general and with ArcGIS in special.
I want to automate a process to split Rasters and afterwards convert them in .txt files.
So far so good. I wrote a script which works fine at my laptop. Sadly it doesnt work on my desktop. I reall dont get it why? Perhaps i did an obvious mistake, which you can identify. I could identify that the part "Splitting the raster " doesnt work like expected. In addition i dont get any error messages. Can you help me?
Here is my code:

"""
TOOL NAME: hydroshedtotxt
VERSION: ArcGIS 10.1
AUTHOR: Tim Tee
TOOL DESCRIPTION:   The tool splits hydroshed raster dataset (folders with .adf files), which are in the same directory like this script, in 10 x 10
                    tiles and convert the created .tif raster files into .txt files.
                    Attention: There are no other folders allowed in the same directory to run this script.
Date Created: 28/04/2013
                 
Usage: RasterToASCII, SplitRaster 

*********************************************************************************************************************"""



import os,arcpy,glob

#determine actual path as workspace
workspace = os.getcwd()

#Splitting the 5 degree raster (adf format) in 10 x 10 Tiles     
try:
    hydroshedlist = glob.glob(workspace + '/*/')
    for raster in hydroshedlist:
        print str(raster) + ' getting processed...'
        #set environment settings
        arcpy.env.workspace = '.'
        
        ##Split large Tiff in 10 x 10 parts
        arcpy.SplitRaster_management(raster, '.', raster[(len(workspace)+1):-1], "NUMBER_OF_TILES",\
                                 "TIFF", "BILINEAR", "10 10", "#", "0", "PIXELS",\
                                 "#", "#")

except:
    print "Split Raster failed."
  

#delete generated .xml, .ovr and .tfw files
xmlList = glob.glob(workspace + '\\*.xml')
for xml in xmlList:
    os.remove(xml)

ovrList = glob.glob(workspace + '\\*.ovr')
for ovr in ovrList:
    os.remove(ovr)

tfwList = glob.glob(workspace + '\\*.tfw')
for tfw in tfwList:
    os.remove(tfw)

# Converting tif to txt
try:
    #creating list of all .tif files and convert them into .txt
    tifList = glob.glob(workspace + '\\*.tif')
    for tif in tifList:
        # set environment settings
        arcpy.env.workspace = '.'

        #set local variables
        inRaster = tif
        outASCII = tif[:-4]+'.txt'

        # Execute RasterToASCII
        arcpy.RasterToASCII_conversion(inRaster, outASCII)

        #removing the created .tif , .xml and .prj
        os.remove(tif)
        os.remove(tif[:-4]+'.xml')
        os.remove(tif[:-4]+'.prj')
except:
    print "\ *** Error *** \n"


Please post all ideas which could be the causing problem and to my python style in general.
Thanks so far and excuse my english. I am not a native speaker ;-)

Tim

Outcomes