0

How do i get my layer EPSG with Python in ArcMap 10.1?

It needs to return a integer.

something like this:

layerEPSG = arcpy.getActiveLayerEpsg()

Here is some context:

    insrs = arcpy.SpatialReference(layerEPSG)
    outsrs = arcpy.SpatialReference(4326)
    newcoord = arcpy.PointGeometry(arcpy.Point(x,y),insrs).projectAs(outsrs).lastPoint

Actually i needed the dataframe factorycode which is this:

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
projectEPSG = df.spatialReference.factoryCode
  • 1
    A "layer" doesn't have a coordinate system, per se, since it's the map canvas that defines the common spatial reference. Each layer has a source reference, and many sources have a defined SpatialReference, but custom SRs might not have an equivalent EPSG factory code. An older build of ArcGIS certainly wouldn't reflect newer EPSG values. – Vince Nov 27 '17 at 11:27
  • Show us how you create the layer object – BERA Nov 29 '17 at 9:31
  • You commented that you received an error - what was it? – PolyGeo Nov 29 '17 at 9:36
  • You appear to have done a Describe on a basemap layer name, not a data source. You'd likely get the info you need from a layer, but you'd need to access it correctly. See the documentation. – Vince Nov 29 '17 at 11:17
  • i think you are right. i tested another layer and it worked. Is there a way to get the spatialreference from a basemap layer? or map sr or project sr... – José Gabriel Nov 29 '17 at 11:30
3

Use arcpy.Describe

insrs = arcpy.Describe(<the layer>).spatialReference.factoryCode
  • Runtime error Traceback (most recent call last): File "<string>", line 2, in <module> AttributeError: DescribeData: Method spatialReference does not exist – José Gabriel Nov 27 '17 at 11:56
  • hmm, should be avail in 10.1 afaik. try to break it up like: desc = arcpy.Describe(<feature class>) srid_name = desc.spatialReference.name – haakon_d Nov 27 '17 at 12:59
  • same error as before – José Gabriel Nov 29 '17 at 9:20
  • @JoséGabriel Please edit your question to show a code snippet that starts with import arcpy and shows how you tested this answer, and any error message that you received. – PolyGeo Nov 29 '17 at 9:35
  • >>> import arcpy ... desc = arcpy.Describe("World Imagery") ... srid_name = desc.spatialReference.name ... print "name: {}".format(srid_name) ... Runtime error Traceback (most recent call last): File "<string>", line 3, in <module> AttributeError: DescribeData: Method spatialReference does not exist – José Gabriel Nov 29 '17 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.