undefinedSr = arcpy.SpatialReference() #Note this DOES NOT make a 'Unknown' SR obj, see below mxd = r"C:\temp\my_mxd.mxd" for df in arcpy.mapping.ListDataFrames(mxd): df.spatialReference = undefinedSr mxd.save() del mxd
undefinedSr = arcpy.Describe(unknownSrFC).spatialReference mxd = r"C:\temp\my_mxd.mxd" for df in arcpy.mapping.ListDataFrames(mxd): df.spatialReference = undefinedSr mxd.save() del mxd
undefinedSr = arcpy.SpatialReference(None) undefinedSr = arcpy.SpatialReference(0) undefinedSr = arcpy.SpatialReference("Unknown") undefinedSr = arcpy.SpatialReference(Unknown)
Anyone know a better way to create an Unknown spatial reference object?
sr = arcpy.SpatialReference() sr = sr.loadFromString('{B286C06B-0879-11D2-AACA-00C04FA33C20}')
Nothing says Unknown coordinate system like '{B286C06B-0879-11D2-AACA-00C04FA33C20}'...
newSpatialReference = arcpy.SpatialReference() newSpatialReference = newSpatialReference.loadFromString('{B286C06B-0879-11D2-AACA-00C04FA33C20}') def clearSR(): # Copy FC's to the new database dsList = arcpy.ListDatasets() fcList = arcpy.ListFeatureClasses() projectList = dsList + fcList # Project the datasets and featureclasses and write to target db for p in projectList: arcpy.AddMessage('Defining Spatial Reference for {0}'.format(p)) arcpy.DefineProjection_management(p,newSpatialReference)
“
arcpy.DefineProjection_management(p,newSpatialReference) ”
This is error in arcgis 10.
ExecuteError: ERROR 000622: Failed to execute (Define Projection). Parameters are not valid.
ERROR 000628: Cannot set input into parameter coor_system.
Jon and Joe,
The reason your code doesn't work is your second line:
newSpatialReference = newSpatialReference.loadFromString('{B286C06B-0879-11D2-AACA-00C04FA33C20}')
This is setting newSpatialReference to the return value of the loadFromString function.
But loadFromString doesn't return anything, it sets the calling object value, so you have a None value
for the rest of your script, which Define projection doesn't like. To unset projection, just call loadFromString:
newSpatialReference = arcpy.SpatialReference() newSpatialReference.loadFromString('{B286C06B-0879-11D2-AACA-00C04FA33C20}')
That will create the object, then assign the value with loadFromString. I tested it and it works fine with DefineProjection.
Cheers,
Shaun
Test OK!
Thank you very much!