AnsweredAssumed Answered

Change a data frame's coordinate system based on a shapefile attribute

Question asked by NDierksQSI on Feb 12, 2018
Latest reply on Feb 12, 2018 by NDierksQSI

I'm trying to write a script tool that, among other things, sets the coordinate system of the map to a given UTM zone based on the attribute data of a shapefile (generated by a spatial join earlier in the script). The relevant bit is as follows:

 

NZone = arcpy.da.SearchCursor(ShpShp, ["UTM_Zone"])
#UTMRef = r"Coordinate Systems\Projected Coordinate Systems\UTM\NAD 1983\NAD 1983 UTM Zone 12N.prj"
UTMRef = r"Coordinate Systems\Projected Coordinate Systems\UTM\NAD 1983\NAD 1983 UTM Zone " + str(NZone) + "N.prj"
MXD = arcpy.mapping.MapDocument("CURRENT")
DF = arcpy.mapping.ListDataFrames(MXD)[0]
sr = arcpy.SpatialReference(UTMRef)
DF.spatialReference = sr

 

(ShpShp is a variable for the shapefile in question, including ".shp")

Note that the commented-out line works if I use that instead. This also works if I change the first line to "NZone = 12". Since I want this to work for any potential UTM zone 1 through 20 (all North), I wanted to use the UTM_Zone field that was the result of the spatial join.


The field is type string, and the values are written exactly as the projection files display (ie no leading zeroes or anything).

 

Am I using SearchCursor wrong? Everything else seems to work fine; I adapted the rest of the above code from this earlier discussion.

 

Any tips?

Outcomes