Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to select a polygon then it must automatically change (calculate) the status to "C". The tool seems to work in the background but nothing actually happens (the status is not updated). I have used the code from this post but nothing actually gets selected. If I have a feature in the layer selected already it does deselect it though.

Below is the code that i am using. Is there something that I have gotten wrong? Thanks for any help.

import arcpy
import pythonaddins

def getSearchDistanceInches(scale, selection_tolerance=3):
    """Returns the map distance in inches that corresponds to the input selection
    tolerance in pixels (default 3) at the specified map scale."""
    return scale * selection_tolerance / 96.0 # DPI used by ArcMap when reporting scale

class tlStatToC(object):
    """Implementation for PythonAddin_addin.tlMapCoods (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
    def onMouseDownMap(self, x, y, button, shift):
        mxd = arcpy.mapping.MapDocument("CURRENT")
        pointGeom = arcpy.PointGeometry(arcpy.Point(x, y), mxd.activeDataFrame.spatialReference)
        searchdistance = getSearchDistanceInches(mxd.activeDataFrame.scale)
        lyr = arcpy.mapping.ListLayers(mxd)[0] # assumes you want to select features from 1st layer in TOC
        arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", pointGeom)
        arcpy.RefreshActiveView()
        arcpy.CalculateField_management(lyr,"STATUS","C")
share|improve this question
add comment

1 Answer

You left off the search distance argument to SelectLayerByLocation. This is important -- for some reason, without it, a PointGeometry object will never intersect anything, at least in my limited testing.

Change:

arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", pointGeom)

To:

arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", pointGeom, "%d INCHES" % searchdistance)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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