Select to view content in your preferred language

ArcGIS Pro Spatial Reference

4213
5
Jump to solution
02-09-2016 06:04 PM
RogerLoweth
Emerging Contributor

I can't figure out how to get the equivalent of this arcpy.mapping code into arcpy.mp

# Set the CRS values based on the current data frame CRS

    # get the map document

    mxd = arcpy.mapping.MapDocument("CURRENT")

    # get the data frame

    df = arcpy.mapping.ListDataFrames(mxd)[0]

    sr = df.spatialReference

Can anyone help please?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

from the help topic

get the current document

get the first dataframe called "yosemite national park"

get a list of the layers

do stuff with the layer IF it supports showlabels

p = arcpy.mp.ArcGISProject("CURRENT")

m = p.listMaps("Yosemite National Park")[0]   

for lyr in m.listLayers():

    if lyr.supports("SHOWLABELS"):

        lblClasses = lyr.listLabelClasses()

yours

get the current project

get the first dataframe called Map

try to get its spatial reference which... it works... will just return a spatial reference object and not its name

so even if that works you might want m.spatialReference.name (check spelling is it S or small s in spatialReference)

So see

Introduction to arcpy.mp—ArcPy | ArcGIS for Desktop  and

Map—ArcPy | ArcGIS for Desktop

but here is the only place you are going to get the SR

SpatialReference—ArcPy Classes | ArcGIS for Desktop  since the map and map frame apparently don't have any concept of SR that I can find...however, I haven't fully explored all, and all hasn't been ported yet

View solution in original post

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

Roger... have you seen the migration documentation ? ... Migrating from arcpy.mapping to ArcGIS Pro—ArcPy | ArcGIS for Desktop

0 Kudos
RogerLoweth
Emerging Contributor

Dan - yes, I'm looking at it now. I can see how to do it by referencing a layer, but what if I don't have any layers when I invoke my tool?

0 Kudos
RogerLoweth
Emerging Contributor

I tried doing this, but it doesn't work:

    # get the map document

    p = arcpy.mp.ArcGISProject("CURRENT")

    # get the data frame

    m = p.listMaps("Map")[0]

    sr = m.spatialReference

0 Kudos
DanPatterson_Retired
MVP Emeritus

from the help topic

get the current document

get the first dataframe called "yosemite national park"

get a list of the layers

do stuff with the layer IF it supports showlabels

p = arcpy.mp.ArcGISProject("CURRENT")

m = p.listMaps("Yosemite National Park")[0]   

for lyr in m.listLayers():

    if lyr.supports("SHOWLABELS"):

        lblClasses = lyr.listLabelClasses()

yours

get the current project

get the first dataframe called Map

try to get its spatial reference which... it works... will just return a spatial reference object and not its name

so even if that works you might want m.spatialReference.name (check spelling is it S or small s in spatialReference)

So see

Introduction to arcpy.mp—ArcPy | ArcGIS for Desktop  and

Map—ArcPy | ArcGIS for Desktop

but here is the only place you are going to get the SR

SpatialReference—ArcPy Classes | ArcGIS for Desktop  since the map and map frame apparently don't have any concept of SR that I can find...however, I haven't fully explored all, and all hasn't been ported yet

0 Kudos
RogerLoweth
Emerging Contributor

Thanks Dan - that's what I thought; map and map frame don't seem to have any concept of spatial reference, even though from the help:

"A Map in ArcGIS Pro represents a collection of  tabular and symbolized geographic layers and also persists information like coordinate system, default views of the data, and various other metadata."

So clearly the map works with the CRS - it just doesn't allow the poor old user access to it!

Maybe in the next version...

Cheers, Roger

0 Kudos