<?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: Create layer for each unique value of attribute(s) using layer definition in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-layer-for-each-unique-value-of-attribute-s/m-p/231303#M17928</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Two thoughts - &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. You can easily undupe a python list like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; x
[4, 4, 1, 2, 2, 3]
&amp;gt;&amp;gt;&amp;gt; list(set(x))
[1, 2, 3, 4]
&amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. I know this is the Python forum -- but want to note you could also do this task with no code using a unique fields iterator in model builder connected to the Make Feature Layer tool. The expression would include the model variable Value output by the iterator at each unique value of your field. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could cap it off using the Collect Values tool piped into AddLayerToGroup to do that final step Jake suggests. However, my experience with model builder is it is usually in my interest not to "gild the lily" so to speak, and focus on setting it up to automate tasks - not create exceedingly complex tools. Though every version adds a little more oomph!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 11:13:57 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2021-12-11T11:13:57Z</dc:date>
    <item>
      <title>Create layer for each unique value of attribute(s) using layer definition</title>
      <link>https://community.esri.com/t5/python-questions/create-layer-for-each-unique-value-of-attribute-s/m-p/231301#M17926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone have a python script that:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- given a layer with multiple attributes (e.g. species, age)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;will&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- split the layer into multiple layers; one layer for each unique value of the given attributes (e.g. canine_10, feline_04)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and ideally&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- does not do this by creating a new physical feature class or shapefile, but rather does it virtually via the layer definition&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- groups the resulting layers into nested group layers (one level for each attribute)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the advice,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Tim&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Mar 2012 18:25:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-layer-for-each-unique-value-of-attribute-s/m-p/231301#M17926</guid>
      <dc:creator>TimHaverland4</dc:creator>
      <dc:date>2012-03-15T18:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer for each unique value of attribute(s) using layer definition</title>
      <link>https://community.esri.com/t5/python-questions/create-layer-for-each-unique-value-of-attribute-s/m-p/231302#M17927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Tim,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is some code to get your started:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = "Rivers_USA"

list = []
outList = []

# append values to list
rows = arcpy.SearchCursor(fc)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(row.System)

del row, rows

# create unique list by removing duplicates
for n in list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if n not in outList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outList.append(n)

# create layer files
for n in outList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(fc, "River_" + n, "\"SYSTEM\" = " + "'" + n + "'")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SaveToLayerFile_management("River_" + n, r"C:\temp\python\River_" + n + ".lyr")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code creates layer files from a Rivers feature class based on an attribute called 'SYSTEM'.&amp;nbsp; All rivers that are part of the same system will be in one layer file.&amp;nbsp; You can then use the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/AddLayerToGroup/00s300000004000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;AddLayerToGroup&lt;/A&gt;&lt;SPAN&gt; function to add the layer files to a group layer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:13:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-layer-for-each-unique-value-of-attribute-s/m-p/231302#M17927</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T11:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer for each unique value of attribute(s) using layer definition</title>
      <link>https://community.esri.com/t5/python-questions/create-layer-for-each-unique-value-of-attribute-s/m-p/231303#M17928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Two thoughts - &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. You can easily undupe a python list like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; x
[4, 4, 1, 2, 2, 3]
&amp;gt;&amp;gt;&amp;gt; list(set(x))
[1, 2, 3, 4]
&amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. I know this is the Python forum -- but want to note you could also do this task with no code using a unique fields iterator in model builder connected to the Make Feature Layer tool. The expression would include the model variable Value output by the iterator at each unique value of your field. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could cap it off using the Collect Values tool piped into AddLayerToGroup to do that final step Jake suggests. However, my experience with model builder is it is usually in my interest not to "gild the lily" so to speak, and focus on setting it up to automate tasks - not create exceedingly complex tools. Though every version adds a little more oomph!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:13:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-layer-for-each-unique-value-of-attribute-s/m-p/231303#M17928</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T11:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer for each unique value of attribute(s) using layer definition</title>
      <link>https://community.esri.com/t5/python-questions/create-layer-for-each-unique-value-of-attribute-s/m-p/231304#M17929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks guys - that's very helpful and has me on my way. I did consider the model builder route but think the all-python method will afford me more control. If I'm successful creating a script tool that does this "virtual split layer on attribute(s)" function I'll share the code or working tool.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Mar 2012 14:01:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-layer-for-each-unique-value-of-attribute-s/m-p/231304#M17929</guid>
      <dc:creator>TimHaverland4</dc:creator>
      <dc:date>2012-03-21T14:01:54Z</dc:date>
    </item>
  </channel>
</rss>

