Last active
October 25, 2020 15:11
-
-
Save knu2xs/d8d0119709fc75cc9a71 to your computer and use it in GitHub Desktop.
Select and zoom to features in ArcMap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # import modules | |
| import arcpy | |
| def select_zoom(layer, sql): | |
| """ | |
| Select from the current map document, a feature in a layer and zoom to the specified feature. | |
| """ | |
| # select by attributes enforcing new selection method to clear any previous selections | |
| SelectLayerByAttribute_management(in_layer_or_view=layer, | |
| selection_type='NEW_SELECTION', | |
| where_clause=sql) | |
| # identify the current map document | |
| mxd = arcpy.mapping.MapDocument('CURRENT') | |
| # identify the data frame | |
| df = arcpy.mapping.ListDataFrames(mxd)[0] | |
| # use the zoom to selected features method of the data frame to update the extent | |
| df.zoomToSelectedFeatures () | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment