AnsweredAssumed Answered

Arcpy and Geoprocessing Tool Warnings

Question asked by trillevine on Nov 11, 2015
Latest reply on Nov 12, 2015 by trillevine

Hello All,


I have a script which I'm trying to implement to re-define the projections of all datasets in a directory and its subdirectories.  I'm using the define projection tool from data management to do this.  Unfortunately, when I run the script, I'm getting an error:



If I try to define the projection in one of these datasets directly through ArcToolbox, I get the following warning:



My guess is that I need to write some error handling into the script in order to dismiss this warning, but I can't find anything anywhere that explains clearly how I might implement this.  Anyone have any ideas?  Feedback is greatly appreciated!


My code so far:


import os
import arcpy
from arcpy import env

arcpy.env.overwriteOutput = True
workspace = r"C:\Scripts\Redefine Projection"
newProjection = arcpy.SpatialReference(25832) # wkid for 'ETRS_1989_UTM_Zone_32N'

def recursiveProjections(workspace):
    """ Function iterates through a workspace and its subfolders using arcpy.da.walk and returns
        a tuple containing two lists: 1) list of spatial reference objects of all geographic datasets (including those inside
        geodatabases) and 2) a list of filepaths for the geographic datasets.  Parameter: target workspace
    describeDatasets = []
    filesList = []
    for dirpath, path, filenames in arcpy.da.Walk(workspace):
        for filename in filenames:
            desc = arcpy.Describe(os.path.join(dirpath, filename))
    for path, path_names, data_names in arcpy.da.Walk(workspace):
        for data_name in data_names:
            filesList.append(os.path.join(path, data_name))
    return describeDatasets, filesList

def defineProjection(workspace):
    """ Function redefines the existing projection for datasets in a workspace.  A log file is created listing
        the paths of all redefined datasets.  Parameter: workspace
    # unpack tuple returned by def recursiveProjections into two lists
    descriptions, filenames = recursiveProjections(workspace)
    # iterate through features and redefine their projections correctly
    for feature in descriptions:
       arcpy.DefineProjection_management(feature, newProjection)

def main():

if __name__ == '__main__':