Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

arcpy.mapping SelectLayerByLocation_management

$
0
0
Okay, where is the example to select feature by an extent?

The select with a point geometry was easily found, but come'on --- the select by rectangle tool is already a default tool! I'd think there'd be an example of how this tool selects features since it's such a common tool!

Any help?

I have this so far which doesn't select anything:

Code:


def onRectangle(self, rectangle_geometry):

        mxd = arcpy.mapping.MapDocument("CURRENT")

        ext = rectangle_geometry
        #Creates a polygon object
        a = arcpy.Array()
        a.add(ext.lowerLeft)
        a.add(ext.lowerRight)
        a.add(ext.upperRight)
        a.add(ext.upperLeft)
        a.add(ext.lowerLeft)
        thepoly = arcpy.Polygon(a)

        for lyr in arcpy.mapping.ListLayers(mxd):
            if lyr.name=="mylayer":
                dlyr = lyr
                arcpy.SelectLayerByLocation_management(dlyr, "INTERSECT", thePoly, "", "NEW_SELECTION")


        arcpy.RefreshActiveView()


Viewing all articles
Browse latest Browse all 2485

Trending Articles