HOW TO

List the spatial reference of layers on a map in ArcGIS Pro via ArcPy

Last Published: June 27, 2022

Summary

Identifying the spatial reference of layers on a map in an ArcGIS Pro project is helpful in ensuring the layers are accurately projected. In ArcGIS Pro, it is possible to create a spatial reference list of the layers available on the map via ArcPy.

Procedure

Depending on the project's file format, the workflows described below are applicable.

Specify the Python script to run a project file (.aprx) in the Python window

The following steps demonstrate how to specify the Python script to run a project file (.aprx) in the ArcGIS Pro Python window.

  1. Import the ArcPy module.
Import arcpy
  1. Set the current opened project in ArcGIS Pro.
aprx = arcpy.mp.ArcGISProject("CURRENT")
  1. Specify the map name in the project.
m = aprx.listMaps("<Map_Name>")[0]
  1. Iterate through the map for existing layers to check the spatial reference using the Describe() function.
for lyr in m.listLayers():
    spatial_ref = arcpy.Describe(lyr).spatialReference
    print(lyr.name, spatial_ref.name)

The code below shows the full working script.

import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("Map_Sample")[0]
for lyr in m.listLayers():
   spatial_ref = arcpy.Describe(lyr).spatialReference
   print(lyr.name, spatial_ref.name)
Note:
The “AttributeError: DescribeData: Method spatialReference does not exist” error message can be ignored as the Describe() function does not consider basemaps as layers in the operation.

Specify the Python script to run a file geodatabase (FGDB) in the Python window

In ArcGIS Pro, specify the Python script to run a file geodatabase (FGDB) in the ArcGIS Pro Python window. Refer to ArcGIS Pro: Code sample for instructions.

Note:
The Describe() function can be run using a stand-alone Python script by creating a Python file.

Article ID: 000027742

Software:
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 7 x
  • ArcGIS Pro 2 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options