1

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)[0]

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

  • 2
    Could you specify what it is that you are actually asking about?! To get an answer, you need to ask a question.. :) – Martin Jul 11 '13 at 13:35
  • I'm asking how to get the code to work when my target feature class and dataframe are in different coordinate systems. It only works when they match, but I need it to work when they are different. – ScottO Jul 11 '13 at 17:51
1

The PointGeometry object supports a method projectAs, so reproject your point into the coordinate system of your dataset before you use it.

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.