Updating Spatial Reference of Map using arcpy

1755
3
06-22-2022 10:45 AM
CullenWilliams-Freier1
Emerging Contributor

Hello!

I'm currently working on automating a workflow that involves creating various maps, nationwide, that all use different state plane coordinate systems. Does arcpy support updating the spatial reference information of the map itself? I understand how to update this information for individual layers, but I'm looking for a way to update the spatial reference information that I would normally update under the map's Properties page.

Any advice welcome, thanks!

0 Kudos
3 Replies
EvanThoms
Frequent Contributor

Get a handle on the map object and there is a spatialReference property you can read and write to

Map—ArcGIS Pro | Documentation

I was able to determine this was available at least as late as v2.6, but older than that, I don't know

0 Kudos
CullenWilliams-Freier1
Emerging Contributor

Thanks! I did notice that, and I've been trying to work with that and cannot figure it out (novice Python user, to be sure). Would it look something like this?

#Get current spatial reference information for a map called "subjectLocationMap".
subjectLocationSR = subjectLocationMap.spatialReference
#Test to see what comes back - in this case, it's "WGS_1984_Web_Mercator_Auxiliary_Sphere"
subjectLocationSR.name
#Picking randomly, let's pretend I want to update the map's spatial reference to NAD 1983 StatePlane Arizona Central (FIPS 0202). Do I think create a string with the desired spatial reference system, then use subjectLocationSR.loadFromString()?

 

 

0 Kudos
EvanThoms
Frequent Contributor

Probably the easiest way to create a spatialReference object is to pull it from another item, such as a map or layer, as you have done in your example, but you can also create one from a .prj file, the name, or factory code and you don't need to use loadFromString. From the documentation:

sr = arcpy.SpatialReference("Hawaii Albers Equal Area Conic")

 

You would only need loadFromString if you only had the WKT string.

0 Kudos