EDIT: OK, added two lines to the code below including a projectAs().
When I start my mxd and run this code it selects a polygon. However, if I then pan to a new location - still within the bounds of the target FC - it doesn't work. Is there some update command I need to run after panning? It's as though the dataframe extent is lost after panning.
I'm trying to selectByLocation using a pointGeometry. The code below creates a pointGeometry from the center of the current dataframe extent. It works if the dataframe and the target feature class (polygon features) are in the same coordinate system but not when they're in different systems.
My usage model is that the target will usually be in a continental projected system or geographic coordinates while the dataframe will be in NAD 1983 UTM 10N to 20N.
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd) arcpy.env.outputCoordinateSystem = df.spatialReference **sr = arcpy.Describe('targetFC').spatialReference** myPt = arcpy.Point((df.extent.XMax + df.extent.XMin)/2.0, (df.extent.YMax + df.extent.YMin)/2.0) myPtGeometry = arcpy.PointGeometry(myPt, df.spatialReference) **myPtGeometry.projectAs(sr)** arcpy.SelectLayerByLocation_management('targetFC', 'INTERSECT', myPtGeometry) del df, mxd
Thank you, Scott