Select to view content in your preferred language

How to find the extent of layer that was created with MakeFeatureLayer

717
2
04-28-2021 10:05 PM
mody_buchbinder
Frequent Contributor

I work in arcpy for ArcMap and do MakeFeatureLayer with some expression.

Then I need to find the extent of this layer.

Describe on the layer name gives the original extent (without  the query)

I know I can do a search cursor and union the extent of all features but I would like to avoid it.

I can also do a CopyFeatures but this will create extra layer.

Any other ideas?

Thanks

0 Kudos
2 Replies
Tim_McGinnes
Frequent Contributor

For ArcMap, arcpy.mapping.Layer has a method called GetSelectedExtent.

ArcPy - Mapping module - Classes - Layer 

 

For Pro users, unfortunately it does not have this method, but there is a solution here (yes, uses search cursor but does not union so should be fairly quick):

ArcPy.mp Get Selected Features Extent 

mody_buchbinder
Frequent Contributor

The problem is to get the Layer.

After more testing, this looks like it works

arcpy.MakeFeatureLayer_management(r"C:\temp\data.gdb\City","bb","objectid < 10")
lyr = arcpy.mapping.Layer("bb")

lyr.getExtent()

0 Kudos