<?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 Re: feature class list and display results in dataframe in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686589#M53125</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm new to programming, you Might help me&lt;/P&gt;&lt;P&gt;I try to follow your advice&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#import modules&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#create MXD project to know where to send the &lt;STRONG&gt;Feature&lt;/STRONG&gt; classs &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument ("CURRENT")&lt;/P&gt;&lt;P&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#Route information &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = r'C:\Users\Infomacion.gdb'&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#feature class list&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;datasets = arcpy.ListDatasets(feature_type='feature')&lt;/P&gt;&lt;P&gt;datasets = [''] + datasets if datasets is not None else []&lt;/P&gt;&lt;P&gt;for ds in datasets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in arcpy.ListFeatureClasses(feature_dataset=ds):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path = os.path.join(arcpy.env.workspace, ds, fc)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print path&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#feature class list&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayer(df, , "BOTTOM") #&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;as should be the code in addLayer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Dec 2014 17:06:05 GMT</pubDate>
    <dc:creator>GustavoCordero</dc:creator>
    <dc:date>2014-12-16T17:06:05Z</dc:date>
    <item>
      <title>feature class list and display results in dataframe</title>
      <link>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686587#M53123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using arcgis 10.2.2&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a line of commands with python&lt;/P&gt;&lt;P&gt; list, every feature class in a feature dataset&lt;/P&gt;&lt;P&gt;and then display me in my data frame so that they can see on my map&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="c" style="color: #008000;"&gt;# Set the workspace. List all of the polygon feature classes that &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="c" style="color: #008000;"&gt;# start with 'G'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="c" style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;env&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;workspace&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s" style="color: #a31515;"&gt;"D:/St_Johns/data.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="n"&gt;fcs&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ListFeatureClasses&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515;"&gt;"G*"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s" style="color: #a31515;"&gt;"polygon"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="p"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="p"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to have this result in my dataframe&lt;/P&gt;&lt;P&gt;&amp;nbsp; all polygons polygons starting with "G"&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="p"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="p"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;I have to do in my scrip to have the polygons in my dataframe?&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="p"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Dec 2014 17:26:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686587#M53123</guid>
      <dc:creator>GustavoCordero</dc:creator>
      <dc:date>2014-12-15T17:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: feature class list and display results in dataframe</title>
      <link>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686588#M53124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you have the list of featureclasses you can loop through the featureclass names and add them to you TOC. &lt;/P&gt;&lt;P&gt;Before the loop you should get your mxd object, the dataframe where you want to add the layers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To get you going, have a look at the AddLayer method:&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//00s300000025000000" title="http://resources.arcgis.com/en/help/main/10.2/index.html#//00s300000025000000"&gt;ArcGIS Help (10.2, 10.2.1, and 10.2.2)&lt;/A&gt; &lt;/P&gt;&lt;P&gt;... and maybe you are interested in learning a little more on the arcpy.mapping module:&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Getting_started_with_arcpy_mapping_tutorial/00s30000006w000000/" title="http://resources.arcgis.com/en/help/main/10.2/index.html#/Getting_started_with_arcpy_mapping_tutorial/00s30000006w000000/"&gt;ArcGIS Help (10.2, 10.2.1, and 10.2.2)&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Dec 2014 03:51:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686588#M53124</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-12-16T03:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: feature class list and display results in dataframe</title>
      <link>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686589#M53125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm new to programming, you Might help me&lt;/P&gt;&lt;P&gt;I try to follow your advice&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#import modules&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#create MXD project to know where to send the &lt;STRONG&gt;Feature&lt;/STRONG&gt; classs &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument ("CURRENT")&lt;/P&gt;&lt;P&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#Route information &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = r'C:\Users\Infomacion.gdb'&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#feature class list&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;datasets = arcpy.ListDatasets(feature_type='feature')&lt;/P&gt;&lt;P&gt;datasets = [''] + datasets if datasets is not None else []&lt;/P&gt;&lt;P&gt;for ds in datasets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in arcpy.ListFeatureClasses(feature_dataset=ds):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path = os.path.join(arcpy.env.workspace, ds, fc)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print path&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#feature class list&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayer(df, , "BOTTOM") #&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;as should be the code in addLayer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Dec 2014 17:06:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686589#M53125</guid>
      <dc:creator>GustavoCordero</dc:creator>
      <dc:date>2014-12-16T17:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: feature class list and display results in dataframe</title>
      <link>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686590#M53126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I assume based on your original question that you want to obtain all feature classes that start with "G" and add them to the current mxd. In that case you can do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#import modules
import os
import arcpy

# input workspace
ws = r'C:\Users\Infomacion.gdb'
arcpy.env.workspace = ws

# feature dataset list
datasets = arcpy.ListDatasets(feature_type='feature')
datasets.append('')

# create a list with the featureclasses
lst_fcs = []
for ds in datasets:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in arcpy.ListFeatureClasses(wild_card="G*", feature_type="polygon", feature_dataset=ds):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path = os.path.join(ws, ds, fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_fcs.append(path)

# create MXD and dataframe objects
mxd = arcpy.mapping.MapDocument ("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

# loop through feature class list
for fc in lst_fcs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.Layer(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, lyr, "BOTTOM")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, when you have the path to the featureclass, you can create a layer object (line 26) which can be added to the dataframe.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:52:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686590#M53126</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T04:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: feature class list and display results in dataframe</title>
      <link>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686591#M53127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you very much everything works perfect&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Dec 2014 14:20:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/feature-class-list-and-display-results-in/m-p/686591#M53127</guid>
      <dc:creator>GustavoCordero</dc:creator>
      <dc:date>2014-12-17T14:20:22Z</dc:date>
    </item>
  </channel>
</rss>

