Split and convert raster files

1335
2
05-02-2013 09:37 AM
TimTrautmann
New Contributor
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
Tags (2)
0 Kudos
2 Replies
TimTrautmann
New Contributor
I just tried this on my desktop and he didn't create new tiles and didn't threw any error messages.
import arcpy
arcpy.env.workspace = '.'
        ##Split large Tiff in 10 x 10 parts
arcpy.SplitRaster_management("n10e000_dem", ".", ".", "NUMBER_OF_TILES",\
                             "TIFF", "BILINEAR", "10 10", "#", "0", "PIXELS",\
                             "#", "#")


Perhaps there is a problem with the tool i dont get it.
0 Kudos
HILLARYHALL
New Contributor II
I want to set the tiff merging and splitting as example to explain raster image files splitting and merging. Tiff is a multi-page document, and sometimes, we need a certain page of them, thus, we need a image splitting tool. And on the contray, if we need to add two or more tiff pages into a new one, we need to use page merging and combining application. I can share the tiff image splitting methods here, which programmed with vb codes, and if you need more raster image converting controls, check out the online guides.

Private Sub SplitDocument(source As Stream, index As Integer, destns As List(Of Stream)) Implements TIFFDocument.SplitDocument
End Sub
Private Sub SplitDocument(index As Integer, source As [String], destns As List(Of Stream)) Implements TIFFDocument.SplitDocument
End Sub
0 Kudos