-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-layer-extent.py
29 lines (22 loc) · 1.08 KB
/
get-layer-extent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Use this script to get the rectangular extent bounding box of a layer in your map.
# This can be a feature layer or an image layer. Any layer as far as I can tell.
# The x/y values returned are in the layer's native spatial reference, not the spatial reference of the map.
# Of course if you need to convert those values, the WKID returned below is what you can use.
# not needed if running in a Pro notebook
import arcpy
# assuming you're running this on your current Pro project's notebook
aprx = arcpy.mp.ArcGISProject("CURRENT")
# obviously you need to edit these parameters
m = aprx.listMaps("name_of_your_map")[0]
lyr = m.listLayers("name_of_the_layer")[0]
# layer has a dataSource, which can be Describe'd, then from that Description, read the extent and spatialReference
src = lyr.dataSource
desc = arcpy.Describe(src)
ext = desc.extent #bounding box
srfc = desc.spatialReference.factoryCode #the WKID
# tell 'em what they won, Johnny
print('minX: ' + str(ext.XMin))
print('minY: ' + str(ext.YMin))
print('maxX: ' + str(ext.XMax))
print('maxY: ' + str(ext.YMax))
print('WKID: ' + str(srfc))