Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

projectAs help

$
0
0
I'm attempting to implement some of the functionality found here:

http://support.esri.com/en/knowledge...s/detail/40730

I need to acquire the x/y values where mouse click occurs, convert the values into Latitude/Longitude and then report these values.

The plan is to require a layer to be loaded in the map TOC, so there will be a defined spatial reference to go from. No problem getting these projected x/y values so far but I am not able to project these to WGS1984. Is this even possible? Or will I have to use in_memory in some capacity here?

Code:


    def onMouseDownMap(self, x, y, button, shift):
        print "x: " + str(x) + " y: " + str(y) ## this reports as expected!
               
        ## get a layer loaded in the TOC to determine the spatial reference       
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        testCount = len(arcpy.mapping.ListLayers(mxd, "", df))
        if testCount==0:
            msg = "There are no features selected to report"
            pythonaddins.MessageBox(msg, 'Report Latitude/Longitude Values', 0)
        else:   
          for lyr in arcpy.mapping.ListLayers(mxd):
            dsc = arcpy.Describe(lyr)
            spref = dsc.spatialReference

            lpoint = arcpy.Point()
            lpoint.X = x
            lpoint.Y = y
            ptGeometry = arcpy.PointGeometry(lpoint)
            #ptGeom = arcpy.PointGeometery(arcpy.point(x,y),spref, False, False)

            to_sr = arcpy.SpatialReference('WGS 1984')
                   
            projectedPoint = ptGeometry.projectAs(to_sr, r'NAD_1983_HARN_To_WGS_1984')
            prjX = projectedPoint.X
            prjY = projectedPoint.Y
            print "X:" + str(prjX) + " Y:" + str(prjY)

The code above fails on the line:
projectedPoint = ptGeometry.projectAs(to_sr, r'NAD_1983_HARN_To_WGS_1984')


Error msg:
"projectedPoint = ptGeometry.projectAs(to_sr, r'NAD_1983_HARN_To_WGS_1984')
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 761, in projectAs
return convertArcObjectToPythonObject(self._arc_object.ProjectAs(*gp_fixargs((spatial_reference, transformation_name))))
ValueError: NAD_1983_HARN_To_WGS_1984"

Viewing all articles
Browse latest Browse all 2485

Trending Articles