<?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: Creating layers for each attribute value via Arcpy script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53803#M4248</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Florin-Daniel,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can iterate through the feature class's field and append the values to a list, remove the duplicate values, and then iterate through the list to create a feature layer for each unique value.&amp;nbsp; Ex:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;list = []

with arcpy.SearchCursor('Soils', ['LandUse']) as cursor:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(row[0])

del cursor

#remove duplicates from list
list = dict.fromkeys(list)
list = list.keys()

for landuse in list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management('Soils', 'Soils_' + landuse, "LandUse = '" + landuse + "'")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 22:04:04 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-12-10T22:04:04Z</dc:date>
    <item>
      <title>Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53802#M4247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm having some trouble starting this script. Not sure how to start, as I have to create/output layers for each attribute value from a certain column named that has integers. They are all unique values.&lt;/P&gt;&lt;P&gt;My first thought was to somehow use MakeFeatureLayer but then again, how do you create the layers without making countless of local variables with layer name.&lt;/P&gt;&lt;P&gt;Another idea would be to use the SearchCursor to iterate each value, and place a layer for each but then again how would I do that.&lt;/P&gt;&lt;P&gt;Looking forward to some suggestions. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2015 13:40:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53802#M4247</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2015-04-28T13:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53803#M4248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Florin-Daniel,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can iterate through the feature class's field and append the values to a list, remove the duplicate values, and then iterate through the list to create a feature layer for each unique value.&amp;nbsp; Ex:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;list = []

with arcpy.SearchCursor('Soils', ['LandUse']) as cursor:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(row[0])

del cursor

#remove duplicates from list
list = dict.fromkeys(list)
list = list.keys()

for landuse in list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management('Soils', 'Soils_' + landuse, "LandUse = '" + landuse + "'")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:04:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53803#M4248</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-10T22:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53804#M4249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jake,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for dropping by. Sounds like an interesting solution, I'll try that and come back with a verdict. At the moment, I was using a different approach but it does not work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2015 14:28:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53804#M4249</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2015-04-28T14:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53805#M4250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I can't seem to make it work, getting a Runtime Error for my SearchCursor line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env

#variables locales
in_features = "D:/M1 Geomatique/Programmation II/Dossier/ELYTR_TR_BUREAU_VOTE_2015_polygon.shp"

list = []

with arcpy.SearchCursor(in_features, "CODE_SECTE") as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(row[0])

del cursor

#effacer les doubles
list = dict.fromkeys(list)
list = list.keys()

for val in list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(in_features, val)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:04:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53805#M4250</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2021-12-10T22:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53806#M4251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For the SearchCursor, you will need to pass the field as a list.&amp;nbsp; Ex:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.SearchCursor(in_features, ["CODE_SECTE"]) as cursor:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(row[0])&amp;nbsp; 
&amp;nbsp; 
del cursor &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:04:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53806#M4251</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-10T22:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53807#M4252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-data-access/searchcursor-class.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;SearchCursor help reference&lt;/A&gt; has a sample for getting unique values from a field:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

fc = 'c:/data/base.gdb/well'
field = 'Diameter'

# Use SearchCursor with list comprehension to return a
# unique set of values in the specified field
values = [row[0] for row in arcpy.da.SearchCursor(fc, field)]
uniqueValues = set(values)
print(uniqueValues)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:04:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53807#M4252</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2021-12-10T22:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53808#M4253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks again, made the correction but I am still getting a RunTime Error. I guess it has to be something with the loop?&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Runtime error &lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 14, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;AttributeError: __exit__&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;PRE class="python" style="display: none;"&gt;with arcpy.SearchCursor(in_features, ["CODE_SECTE"]) as cursor:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(ro&lt;/PRE&gt;&lt;DIV style="display: none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2015 17:28:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53808#M4253</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2015-04-28T17:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53809#M4254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reference Jeff, that was really helpful. Initially, I tried it, but it didn't worked out well, perhaps the rest of my code was wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Still, I would like to know how the other solution works out. I must be doing something wrong, for sure.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2015 17:36:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53809#M4254</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2015-04-28T17:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53810#M4255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried dropping the "with" statement?&amp;nbsp; That error has something to do with how the with statement catches errors and cleans up objects and it's not finding the __exit__ function for SearchCursor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="_jivemacro_uid_14302471395666936 jive_macro_code jive_text_macro" data-renderedposition="113_8_913_16" jivemacro_uid="_14302471395666936"&gt;&lt;P&gt;cursor = arcpy.SearchCursor(infeatures, ['CODE_SECTE'])&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2015 18:52:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53810#M4255</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2015-04-28T18:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53811#M4256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That would make perfect sense, I thought it had to do something with it. I've seen "with" being used mostly with da.SearchCursor not the other one,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Apr 2015 08:01:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53811#M4256</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2015-04-29T08:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating layers for each attribute value via Arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53812#M4257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a working solution for this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 May 2015 15:37:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-layers-for-each-attribute-value-via-arcpy/m-p/53812#M4257</guid>
      <dc:creator>DavidBrett</dc:creator>
      <dc:date>2015-05-27T15:37:52Z</dc:date>
    </item>
  </channel>
</rss>

