Select to view content in your preferred language

arcpy.da.Walk - Raster Dataset returns xls files as well

410
0
09-12-2013 11:09 PM
DaveBarrett
Deactivated User
Has anyone found any issues when using the da.Walk function in 10.1?

As part of a wider bulk raster data loading tool I have written a function that checks if a folder contains MrSID format rasters and returns True or False. This is used to determine whether to load the data into managed raster catalogs stored in SQL Server database.

## function to check if MrSID files are present in the file path.
def formatCheck(workspace):
    """This fuinction determines if the workspace contains MrSID format. The
    function returns True\False.
        
    This wil be used to determine whether to load the data. If the workspace
    is RemoteDatabase then the MrSIDs will not be loaded into a raster catalog.
    """
    ## search the input dataset for raster datasets
    for root, dirs, files in arcpy.da.Walk(workspace, datatype="RasterDataset"):
        for f in files:
            ## this test has been added due to xls files being returned as raster datasets with incorrect path
            ## by the da.Walk function. The fault does not appear to occur when using xlsx files in the directory
            if not f[-3:].lower() == "xls": 
                desc = arcpy.Describe(os.path.join(root,f))
                if desc.format == "MrSID":
                    return True
                else:
                    return False


The issue I have found is that the datatype="RasterDataset" filter in the Walk function returns excel 97-2003 files as a raster with a path of the form c:\Data\Raster\Charts.xls\sheet1.xls
This is then throwing an error as the path doesn't exist. This issue is not repeated with the new Excel format xlsx files.

If you describe the actual path to the excel table it retuns a data type of DETable so it is my understanding that this should not be returned as a raster dataset. The work around was to place this test in the code:

if not f[-3:].lower() == "xls"


I'd be interested to see if anyone has had this issue.

Thanks

Dave
Tags (2)
0 Kudos
0 Replies