AnsweredAssumed Answered

Get Extent object for features returned by SearchCursor

Question asked by johnmdye on Oct 23, 2014
Latest reply on Dec 2, 2014 by bixb0012

What is a good way to get an extent object for the features returned by a da.SearchCursor with a where_clause applied? Certainly, I could apply a selection to the FeatureLayer and then use the getSelectedExtent method on the Layer object but frankly, I find SelectLayerByAttribute_management to be an expensive transaction. Add to this that I would also need to go back and clear the selection too. I just want to zoom to the extent of the returned features of the SearchCursor. Ideas?

 

with arcpy.da.SearchCursor(FeatureLayer, "SHAPE@", searchQuery) as rows:
    rowCount = 0
    for row in rows:
        rowCount = rowCount + 1
    print str(rowCount)
    if rowCount == 0:
        pythonaddins.MessageBox("No features found which meet criteria.", 
                                "ERROR: INVALID SEARCH CRITERIA", 0)
        return
    elif rowCount == 1:
        if row[0].type == "point":
            extent = row[0].extent
            df.extent = extent
            df.scale = 5000
            arcpy.RefreshActiveView()
            del extent
            del rows
        else:
            print "Geometry is: " + str(row[0].type)
            return
    elif rowCount > 1:
        # so...now I have a bunch of features/rows returned..hmm
        # how to go about getting the full extent for these 
        # returned features without applying a selection

Outcomes