babakkasraie

Select by Rectangle codes problem

Discussion created by babakkasraie on Feb 1, 2013
Hi experts

I tried to create a function for my Tkinter button 1 by which to be able to Select Features from a layer of my current map. Something is missing in my codes. They don't work. What do I need to add to these codes to work as an interactive selection tool. I need to click on the map then drag and then release and then a rectangle to be created and finally the features to be selected. Please have a look on my codes and help me. Best regards. Babak


 def button1Click(self, selection):
        
            
        mxd=arcpy.mapping.MapDocument("CURRENT")

        # This is an empty polygon shape file.
        extent = "extent_shapefile"
        # Set the workspace
            #
        env.workspace = mxd

        # these codes are for selecting a layer from listbox
        index = self.listbox.curselection()               
        label = self.listbox.get(index) 

        # Local variables: a layer from listbox. It is fine
        layer = label

        # Data ferame is the current map

        df = arcpy.mapping.ListDataFrames(mxd)[0]
        # Create a search cursor from layer
            #
            
        # Create an Array object.
                #The DataFrame extent object is converted into a polygon feature so it can be used with the SelectLayerByLocation function.
        dfAsFeature = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft, df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]),df.spatialReference)
        arcpy.SelectLayerByLocation_management(layer, "INTERSECT", dfAsFeature, "", "NEW_SELECTION")

Outcomes