Select to view content in your preferred language

Use arc.py to zoom to layer

817
2
Jump to solution
01-15-2024 10:47 AM
edward33
Regular Contributor

I am using notebooks and arc py to do a definition query, after the def query is done I want to zoom to the layer. I cannot seem to find documentation on how to do this, I have figured out the definition query and it works well as seen below- 

import arcpy
# Set the project path to "CURRENT" to use the currently open project
project_path = "CURRENT"
# Set the name of the map and the layer you want to apply the definition query to
map_name = 'main'
layer_name = 'prop'

# Set the field and value for the definition query
field_name = 'id'
query_value = input('Enter the ID') 

# Create a reference to the ArcGIS Pro project
aprx = arcpy.mp.ArcGISProject(project_path)
# Access the map and the layer
map_obj = aprx.listMaps(map_name)[0]
layer_obj = map_obj.listLayers(layer_name)[0]
# Set a simple definition query
definition_query = f"{field_name} = '{query_value}'"
layer_obj.definitionQuery = definition_query

1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

You might want to look around the camera properties to see if it is possible

Camera—ArcGIS Pro | Documentation


... sort of retired...

View solution in original post

2 Replies
DanPatterson
MVP Esteemed Contributor

You might want to look around the camera properties to see if it is possible

Camera—ArcGIS Pro | Documentation


... sort of retired...
edward33
Regular Contributor

This worked thanks!

0 Kudos