Thanks, tim. However you are still requiring an input shapefile, but I will go back and see if I can rework things prior to my new approach. I was hoping to avoid this and simply convert the geometry to a different spatial reference (WGS1984). Doesn't look like this is possible, so I came up with an "in_memory" implementation that seems to do what I need. The first click event takes about 3 seconds to build the in_memory FeatureClass but subsequent clicks the Lat/Lon values are reported immediately.Solution:
def onMouseDownMap(self, x, y, button, shift):
print "x: " + str(x) + " y: " + str(y)
## 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, spref)
ptFC = "in_memory\lpoint"
if arcpy.Exists(ptFC):
arcpy.Delete_management(ptFC)
arcpy.CreateFeatureclass_management("in_memory", "lpoint", "POINT", '', "DISABLED", "DISABLED", spref, '')
cursor = arcpy.da.InsertCursor(ptFC, "SHAPE@XY")
cursor.insertRow((lpoint,))
del cursor
to_sr = r'GEOGCS["GCS_WGS_1984",' + \
'DATUM["D_WGS_1984",' + \
'SPHEROID["WGS_1984",6378137,298.257223563]],' + \
'PRIMEM["Greenwich",0],' + \
'UNIT["Degree",0.017453292519943295]]'
flds = ["SHAPE@X", "SHAPE@Y"]
scursor = arcpy.da.SearchCursor(ptFC, flds, '', to_sr)
prjx = 0.00
prjy = 0.00
for row in scursor:
#print "X: " + str(row[0]) + " Y: " + str(row[1])
prjx = row[0]
prjy = row[1]
del scursor
msg = "Latitude: " + str(prjx) + "\n" + "Longitude: " + str(prjy)
pythonaddins.MessageBox(msg, 'Report Latitude/Longitude Values', 0)
this appears to be a good solution, but if anyone can spot any issue with the above, I'd appreciate it.