ArcPy ArcGIS Pro – Changing Spatial Reference of Map Using ArcPy in ArcGIS Pro

aprxarcgis-proarcpycoordinate system

Steps:

  1. I am loading an aprx from a template, which is in WGS84 spatial
    reference.
  2. Then I do some processes.
  3. Finally, I want to change
    the MAP's spatial reference (WGS84)
    to another, which I get from another layer.

Is it possible to do it using arcpy and ArcGIS Pro?

The code is:

aprx = arcpy.mp.ArcGISProject(r"\\ptemplate\project.aprx)

ras= "my_layer.tif"

sr=arcpy.Describe(ras).spatialReference

aprxMap = aprx.listMaps()[0]

How do I change the Spatial Reference to _sr_?

aprx.saveACopy(r"\\my_projects\project_out.aprx)

Best Answer

You're pretty much there with your code. You just need to apply the SR on the map

ras= "my_layer.tif"
sr=arcpy.Describe(ras).spatialReference

p = arcpy.mp.ArcGISProject(r"\\ptemplate\project.aprx")
m = p.listMaps()[0]
m.spatialReference = sr
p.saveACopy(r"\\my_projects\project_out.aprx)