<?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: Get unique combinations of multiple field values in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17714#M1353</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the quest to change/uncover artifacts continues .... split layer by attributes was my first foray a decade or so ago... numpy now makes it so much easier.&amp;nbsp;&amp;nbsp; Alternatives for 'basic' tools, have also been revealed... Voronoi/Delauney, Near, Statistics, Kappa coeff ... to name a&amp;nbsp; few, have been given.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Mar 2016 22:47:31 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-03-03T22:47:31Z</dc:date>
    <item>
      <title>Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17707#M1346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've written a geoprocessing script in Arcpy v10.2 that merges contiguous polylines into multipart polylines. At the moment it can take an SQL expression as an input that selects certain features of the input feature class to apply the algorithm to (e.g. I only want to merge intersecting pipes if they operate at the same pressure range, so I'd use the selection query to only select pipes of that pressure range).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to modify this so instead of a selection query, you can select multiple fields from the input feature class, similar to the Dissolve tool. So for example, I could merge all intersecting pipes of the same material, diameter, and pressure range into separate, contiguous, multi-part polyline features.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm struggling to find a good way to identify all the unique combinations of values for the selected fields, and loop through each of these combinations, selecting them in turn and applying the algorithm to each of those selections.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The usual way to get unique values from one field is to add all the values to a list and then convert it into a set, but this gets tricky when you instead have multiple fields and you don't know how many fields the user will select! It doesn't seem possible to convert a list of lists to a set, as a set won't accept a list as an element as it's mutable. If I try converting the inner lists to tuples I get an error about tuples not being callable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Generally the code I've written to try to achieve this is a hacked together mess! There has to be a better way of doing this!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone suggest how I can do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, once I have each combination in a list (or maybe a dictionary, with the field name as the key?) is there a nice/efficient way to generate a SQL query to select the features with that combination of values?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Mar 2016 10:00:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17707#M1346</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2016-03-02T10:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17708#M1347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use the &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/frequency.htm"&gt;Frequency &lt;/A&gt;tool (if you have an Advanced/ArcInfo license) otherwise use the &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/summary-statistics.htm"&gt;Summary Statistics&lt;/A&gt; tool with the fields you want to get unique combinations for as the "Case Fields".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can then access the output with a search cursor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Mar 2016 22:42:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17708#M1347</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2016-03-02T22:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17709#M1348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; font-size: 14px;"&gt;The usual way to get unique values from one field is to add all the values to a list and then convert it into a set, but this gets tricky when you instead have multiple fields and you don't know how many fields the user will select!&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Can't you use the above method to build and filter a list of unique &lt;STRONG&gt;concatenated&lt;/STRONG&gt; values, like [field1_field2_field3, field1_field2_field3, etc.]?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Mar 2016 22:52:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17709#M1348</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2016-03-02T22:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17710#M1349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, that'll work for getting the unique combinations, but I'm having some difficulty using those to select out one combination at a time to apply my process to.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At the moment I'm trying to use the SearchCursor to loop through each combination and build a SQL selection query for that combination by concatenating strings together. This isn't ideal though as I have to have lots of if statements to handle different data types and when it runs into NULL values it can't cope either - I could write more string concatenations to deal with NULLS but surely there must be a better way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's what I have so far (is there a 'code' tag in this new forum??):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Use a SearchCursor to loop through each combination, build a selection query, and apply the algorithm to that selection
with arcpy.da.SearchCursor(inputLines, dissolveFields) as cursor:

&amp;nbsp; selectionQuery = ''

&amp;nbsp; for row in cursor:


&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in row:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(field)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if count &amp;lt; len(row):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if type(field) == 'str':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionQuery += arcpy.AddFieldDelimiters(arcpy.env.scratchGDB, dissolveFields[count]) + " = '" + field + "' AND "
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif type(field) == 'int':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionQuery += arcpy.AddFieldDelimiters(arcpy.env.scratchGDB, dissolveFields[count]) + " = " + int(field) + " AND "
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif type(field) == 'float':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionQuery += arcpy.AddFieldDelimiters(arcpy.env.scratchGDB, dissolveFields[count]) + " = " + float(field) + " AND "
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if type(field) == 'str':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionQuery += arcpy.AddFieldDelimiters(arcpy.env.scratchGDB, dissolveFields[count]) + " = '" + field + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif type(field) == 'int':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionQuery += arcpy.AddFieldDelimiters(arcpy.env.scratchGDB, dissolveFields[count]) + " = " + int(field)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif type(field) == 'float':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionQuery += arcpy.AddFieldDelimiters(arcpy.env.scratchGDB, dissolveFields[count]) + " = " + float(field)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1


&amp;nbsp; arcpy.AddMessage(selectionQuery)

&amp;nbsp; # Apply selection query and create working copy
&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion(inputLines, arcpy.env.scratchGDB, 'SuperStrings_temp_in', selectionQuery)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:42:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17710#M1349</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2021-12-10T20:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17711#M1350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I do not understand why esri continues to make 'basic' tools only available at the Advanced level, yet provide the opportunity to do so via other means...&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/55577"&gt;Free Frequency ... join the cause  &lt;/A&gt; &lt;/P&gt;&lt;P&gt;code sample included, using a different approach than those already given&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Mar 2016 14:26:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17711#M1350</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-03T14:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17712#M1351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/20451"&gt;Dan Evans&lt;/A&gt;​ see &lt;A href="https://community.esri.com/migration-blogpost/55181"&gt;Code Formatting... the basics++&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I edited your post to add the formatting.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Mar 2016 22:26:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17712#M1351</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2016-03-03T22:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17713#M1352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's not unheard of that ESRI would change a tools license level &lt;A href="https://community.esri.com/migrated-users/3116"&gt;Dan Patterson&lt;/A&gt;​, back at ArcGIS 9.0, the 'Add Join' tool was &lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=993&amp;amp;t=178015#526356"&gt;Advanced/ArcInfo only&lt;/A&gt;... it's now available with all licenses.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But that was a slightly different case where the same functionality was available in the menus/toolbars at any license level, but not as a GP tool and ESRI was sorting that out. Whereas with 'Frequency', I assume the license level is an artifact from its origin as the Arc/INFO (workstation) frequency command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That said, it's still what I would consider a 'basic' tool, with the same functionality available via other methods even without resorting* to code...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;* I say resorting, but code is often my first choice. That count_combos_demo.py is a neat script btw&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Mar 2016 22:37:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17713#M1352</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2016-03-03T22:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17714#M1353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the quest to change/uncover artifacts continues .... split layer by attributes was my first foray a decade or so ago... numpy now makes it so much easier.&amp;nbsp;&amp;nbsp; Alternatives for 'basic' tools, have also been revealed... Voronoi/Delauney, Near, Statistics, Kappa coeff ... to name a&amp;nbsp; few, have been given.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Mar 2016 22:47:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17714#M1353</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-03T22:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17715#M1354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wrote the tool in &lt;A _jive_internal="true" href="https://community.esri.com/blogs/richard_fairhurst/2015/06/07/multiple-field-key-to-single-field-key-tool-relate-two-layers-based-on-more-than-one-field"&gt;this Blog&lt;/A&gt; specifically for use with the output of the Frequency Tool or Summary Statistics tool when multiple fields are used for the unique case values.&amp;nbsp; It creates a new Long field in both the original source and the frequency output to generate a single unique Long number to represent each multi-field unique combination.&amp;nbsp; It should handle all normal data field types and Null values.&amp;nbsp; The sort order of the unique field values should be correct for each field type (i.e., strings sort as strings, numbers sort as numbers, dates sort as dates, etc.) and the fields can be prioritized in any order.&amp;nbsp; The 10.3 version is better than the 10.2 version, but both work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Mar 2016 22:51:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17715#M1354</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2016-03-03T22:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17716#M1355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;IMG alt="HolyGrail051.jpg" class="image-1 jive-image" src="http://www.intriguing.com/mp/_pictures/grail/large/HolyGrail051.jpg" style="height: auto;" /&gt;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/laugh.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Mar 2016 22:54:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17716#M1355</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2016-03-03T22:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17717#M1356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes... the quest... many great images there on that link&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Mar 2016 23:07:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17717#M1356</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-03T23:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17718#M1357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looks like I've solved it by using Summary Statistics to get the unique combinations, then looping over the unique combinations with a SearchCursor. Within this SearchCursor I have another SearchCursor looping over all my input features and an InsertCursor to write only the matches into a temporary feature class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for the help. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 11:26:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17718#M1357</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2016-03-04T11:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17719#M1358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Embedded cursors only works for small sets of data.&amp;nbsp; The larger the data grows the inefficiency becomes exponentially bad.&amp;nbsp; Loading a dictionary from the table with the data you want to read only with the unique combinations as the key and values of the fields to write in a list and then using an insert cursor based on the dictionary matches is incredibly fast.&amp;nbsp; I discourage everyone from using embedded cursors.&amp;nbsp; They are a poor solution.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 16:22:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17719#M1358</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2016-03-04T16:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17720#M1359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know it's inefficient (I got it working and it took 13 hours to run on my data!) but I spent several days last week tearing my hair out trying to get it to work the efficient way, without success!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Mar 2016 09:05:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17720#M1359</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2016-03-07T09:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17721#M1360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I didn't see a copy of sample data you are trying to use, is it possible to get one, so I can try the alternative approach&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Mar 2016 11:13:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17721#M1360</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-07T11:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17722#M1361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry but I can't share any of the actual data. I can give you an idea of the schema though if that helps?&lt;/P&gt;&lt;P&gt;It's a pipe network (just a standard line feature class though, no geometric network stuff), each feature is a section of pipe (split at fairly arbitrary points). Each section has an 8-digit unique ID, and a number of attributes such as material (2-letter text code), diameter (floating point number), diameter units (either inches or millimetres), pressure tier (Low, Medium and High), etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want is to combine contiguous sections of pipes with the same attributes into multi-part features. I will then assign each one a unique 'subsystem' ID, and spatial join this back on to the original features. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Dissolve tool isn't suitable even with 'create multipart features' or 'unsplit lines' checked, as this either combines ALL features with the selected attributes the same (not just those that are connected) in the former case, and will only combine lines that can be combined into single-part features in the latter case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The main issue I'm having trying to do it with dicts etc. is building a SQL query to select out each unique combination of attributes. It gets very messy when I have to start dealing with different data types.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't know if that helps or makes sense. Let me know if you'd like any more info. Thanks for helping.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Mar 2016 12:06:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17722#M1361</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2016-03-08T12:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17723#M1362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Lets take it out of your field into concept stage... If you can extrapolate to this, then I think I have a solution at least for the reclassification to facilitate querying:&amp;nbsp;&amp;nbsp; Consider&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fields:&amp;nbsp;&amp;nbsp; prefix, state, pets,&lt;/P&gt;&lt;P&gt;you have 2 prefixes: (A, The)&lt;/P&gt;&lt;P&gt;4 states: (wet, dry, sleep, hungry) &lt;/P&gt;&lt;P&gt;3 pets: (cat, dog, fish)&lt;/P&gt;&lt;P&gt;you want all the combinations of the concatenation of the fields values. This will enable a reclassification&amp;nbsp; of the data so that it makes it easier to query and do "stuff" with the results of the query.&amp;nbsp;&amp;nbsp; For "A hungry cat" or "A wet fish" may be class 1 and class 2, but you don't want to query the full slate and you may have numbers in one field and text in another.&amp;nbsp; You just want the data reclassified so that you don't miss any possible combination. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Mar 2016 14:45:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17723#M1362</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-08T14:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: Get unique combinations of multiple field values</title>
      <link>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17724#M1363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually, the Dissolve tool will work to solve this problem, but not directly on the lines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; Buffer the lines a very small distance (0.01 meter/feet for instance).&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; Dissolve the buffers with the unique Case fields set for all fields that you want to group and uncheck the multi-part feature option.&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; Add a Long field called SUBSYSTEM to the dissolved buffers and calculate the ObjectID/FID into it.&lt;/P&gt;&lt;P&gt;4.&amp;nbsp; Spatial Join the lines as the target and the dissolved buffer as the join features with the One to Many option.&lt;/P&gt;&lt;P&gt;5.&amp;nbsp; Select all lines where the case fields of the original lines match the case fields of the dissolved buffers.&lt;/P&gt;&lt;P&gt;6.&amp;nbsp; Dissolve the selected lines with the case fields including all of the original fields plus the SUBSYSTEM field and check the create multi-part feature option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The lines will be combined into a single multi-part feature that all have the same case field values, but only as long as they touch within the small distance you specified.&amp;nbsp; Separate features will be created for any set of case field values where the line groups do not touch each other within the small distance you specified.&amp;nbsp; Each multi-part line feature will have a unique SUBSYSTEM field value you can use for your relate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is no need to loop through the separate case field value sets, since all sets are handled at once by the process above.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Mar 2016 18:17:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-unique-combinations-of-multiple-field-values/m-p/17724#M1363</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2016-03-08T18:17:51Z</dc:date>
    </item>
  </channel>
</rss>

