AnsweredAssumed Answered

Arcpy -- Edit Spatial Reference Object Properties

Question asked by trillevine on Nov 5, 2015
Latest reply on Mar 18, 2016 by trillevine

Hello All,

 

I'm trying to develop a python script  to edit the name property of several spatial reference objects found while iterating through a folder and its subdirectories.  The projection of the data is identical to ETRS_1989_UTM_Zone_32N, but is named something else -- I'm just trying to reset the name to ETRS_1989_UTM_Zone_32N.  According to the help, this property is both readable and writable in ArcGIS 10.2, which is what I'm running.  I'm just not sure how to go about writing in the new projection name via the script...anybody have any ideas?  Any feedback is greaty appreciated!

 

Here's my code so far:

 

import os
import arcpy

workspace = r"C:\Scripts\Reproject"
newProjection = "ETRS_1989_UTM_Zone_32N"

def recursiveProjections(workspace):
    """
    Function iterates through a workspace and its subfolders using arcpy.da.walk and returns
    a list of spatial reference objects of all geographic datasets (including those inside
    geodatabases).  Parameter: target workspace

    """
    projections = []
    for dirpath, dirnames, filenames in arcpy.da.Walk(workspace):
        for filename in filenames:
            desc = arcpy.Describe(os.path.join(dirpath, filename))
            srObject = desc.spatialReference
            projections.append(srObject)
    return projections

def editProjection(workspace):
    projections = recursiveProjections(workspace)
    for projection in projections:
        print projection.name

editProjection(workspace)

Outcomes