<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Analyze Map Extent for Visible Layers in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/analyze-map-extent-for-visible-layers/m-p/586094#M45996</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;is there a pythonic way of determing if a layer is visible within the dataframe extent in arcpy 10.1? Not unlike how the option in a legends property dialogue box--&amp;gt; Items tab--&amp;gt; Map Extent Options--&amp;gt; 'Only show classes that are visible in the current map extent' analyzes the map and toggles on and off legend items. I would like to analyze the current map extent and turn on and off layers.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 May 2014 18:06:13 GMT</pubDate>
    <dc:creator>MikeMacRae</dc:creator>
    <dc:date>2014-05-08T18:06:13Z</dc:date>
    <item>
      <title>Analyze Map Extent for Visible Layers</title>
      <link>https://community.esri.com/t5/python-questions/analyze-map-extent-for-visible-layers/m-p/586094#M45996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;is there a pythonic way of determing if a layer is visible within the dataframe extent in arcpy 10.1? Not unlike how the option in a legends property dialogue box--&amp;gt; Items tab--&amp;gt; Map Extent Options--&amp;gt; 'Only show classes that are visible in the current map extent' analyzes the map and toggles on and off legend items. I would like to analyze the current map extent and turn on and off layers.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 May 2014 18:06:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/analyze-map-extent-for-visible-layers/m-p/586094#M45996</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2014-05-08T18:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Analyze Map Extent for Visible Layers</title>
      <link>https://community.esri.com/t5/python-questions/analyze-map-extent-for-visible-layers/m-p/586095#M45997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For something like this, you can use the &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000072000000" rel="nofollow noopener noreferrer" target="_blank"&gt;arcpy.Extent&lt;/A&gt;&lt;SPAN&gt; object.&amp;nbsp; Specifically, the "contains" and "overlaps" methods it has.&amp;nbsp; These methods receive geometries though, no other extents.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The approach I would take, is to create a rectangular geometry that mimics your feature class's extent.&amp;nbsp; Whenever you want to test if that feature class is visible, check and see it it's extent geometry overlaps the dataframe extent. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Get your Feature Layer extent
layer = arcpy.mapping.Layer("Your Feature Layer")
extent = arcpy.Describe(layer).extent

# Create a Polygon object from that extent
extentArray = arcpy.Array(i for i in (extent.lowerLeft,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extent.lowerRight,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extent.upperRight,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extent.upperLeft,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extent.lowerLeft))

extentPolygon = arcpy.Polygon(extentArray, arcpy.SpatialReference(4326))
del extentArray

# Get reference to your dataframe
mxd = arcpy.mapping.MapDocument("CURRENT") 
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]

# Whenever appropriate, test if the layerframe overlaps the extent geometry of your feature layer
if df.extent.overlaps(extentPolygon) == False:
&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.visible = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.visible = True
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you have several layers you want to test with this, you can use &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.mapping.ListLayers(mxd)&lt;/PRE&gt;&lt;SPAN&gt; to get references to all the layers in your mxd and loop through them with this test.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:12:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/analyze-map-extent-for-visible-layers/m-p/586095#M45997</guid>
      <dc:creator>MattEiben</dc:creator>
      <dc:date>2021-12-12T01:12:38Z</dc:date>
    </item>
  </channel>
</rss>

