<?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: Getting a list of unique values from a field in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17617#M429</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure I understand your syntax. You're declaring sCenters as a local variable inside the function, so it will be unavailable outside that function. How are you getting the array out of that function?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 01 Jun 2015 17:37:29 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2015-06-01T17:37:29Z</dc:date>
    <item>
      <title>Getting a list of unique values from a field</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17613#M425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to retrieve a list of unique values from a particular field in a layer using ArcObjects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was using the IDataStatistics.UniqueValues, but it causes the results to be corrupted as soon as the function is exited (in ArcMap 10.2+).&amp;nbsp; I think it's related to some longstanding issues with IDataStatistics (&lt;A href="https://community.esri.com/thread/63506"&gt;Issues with ArcObjects and ArcGIS 10.1 SP1 IDataStatistics&lt;/A&gt;&amp;nbsp; as an example).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried using the DISTINCT prefix on the IQueryFilterDefinition2, per the end of the discussion on the last thread, but couldn't get it to work on a shapefile -- It did work on the same data in a File Geodatabase.&amp;nbsp; What are the limitations of IQueryFilterDefinition2?&amp;nbsp; Have any other suggestions to get a list of unique values quickly?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some Caveats:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;It's for commercial software and needs to support ArcMap 10.0-10.3.X&lt;/LI&gt;&lt;LI&gt;We work with all flavors of GeoFeatureLayers and need to support shp, pgdb, fgdb, sde, etc.&lt;/LI&gt;&lt;LI&gt;This function needs to run very quickly, because it's called every time the map refreshes (invalidates) and may be retrieving unique values from one column, from multiple layers with a large number of features each&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 May 2015 04:03:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17613#M425</guid>
      <dc:creator>Justin_ODell</dc:creator>
      <dc:date>2015-05-29T04:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a list of unique values from a field</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17614#M426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Justin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With regard to IDataStatistics.UniqueValues being corrupted, were you simply trying to return the value of this property (an IEnumerator instance) from your function?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since IDataStatistics functionality is cursor-based, it's not entirely surprising that the contents of UniqueValues becomes corrupt once your function completes and the objects are out of scope.&amp;nbsp; You should consider copying the contents of the UniqueValues property to a separate variable (array, IList, or similar) and returning that from your function.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 May 2015 18:02:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17614#M426</guid>
      <dc:creator>ErinBrimhall</dc:creator>
      <dc:date>2015-05-29T18:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a list of unique values from a field</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17615#M427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Erin!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No -- I was trying to return the values as an array of strings.&amp;nbsp; Here is a sample with the gist of my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Public Function getCentersFromLayer(... sCenters() As String, ...) As Long
&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pDataStatistics As IDataStatistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pDataStatistics = New DataStatistics
&amp;nbsp;&amp;nbsp;&amp;nbsp; pDataStatistics.Field = FIELD_NAME
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pDataStatistics.Cursor = pFeatureCursor

&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pEnumVar As IEnumVariantSimple
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pEnumVar = pDataStatistics.UniqueValues
&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim value As Variant
&amp;nbsp;&amp;nbsp;&amp;nbsp; value = pEnumVar.Next

&amp;nbsp;&amp;nbsp;&amp;nbsp; Do Until isEmpty(value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCenters(getCentersFromLayer) = CStr(value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = pEnumVar.Next
&amp;nbsp;&amp;nbsp;&amp;nbsp; Loop

End Function&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sCenters&amp;nbsp; (and the string array passed into it) had the correct values up until after control returned on line 19.&amp;nbsp; I even tried using the CopyString (ByVal) function below to replace the CStr() on line 15, to ensure I didn't have references to the original memory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Public Function CopyString (ByVal s as String) as String
&amp;nbsp;&amp;nbsp;&amp;nbsp; CopyString = s
End Function&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:42:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17615#M427</guid>
      <dc:creator>Justin_ODell</dc:creator>
      <dc:date>2021-12-10T20:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a list of unique values from a field</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17616#M428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sounds like you've already gone pretty far down the whole String/memory path, but one last thing to try: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/system.string.copy(v=vs.110).aspx?cs-save-lang=1&amp;amp;cs-lang=vb#code-snippet-1"&gt;String.Copy&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;The Copy method returns a String object that has the same value as the original string but represents a different object reference. &lt;STRONG&gt;It differs from an assignment operation, which assigns an existing string reference to an additional object variable&lt;/STRONG&gt;."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming that the contents of the UniqueValues property look correct as you iterate through, this problem &lt;EM&gt;should &lt;/EM&gt;be solvable through variable/memory management.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 15:58:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17616#M428</guid>
      <dc:creator>ErinBrimhall</dc:creator>
      <dc:date>2015-06-01T15:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a list of unique values from a field</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17617#M429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure I understand your syntax. You're declaring sCenters as a local variable inside the function, so it will be unavailable outside that function. How are you getting the array out of that function?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 17:37:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17617#M429</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2015-06-01T17:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a list of unique values from a field</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17618#M430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Passing it as a reference parameter.&amp;nbsp; In VBA, all parameters are passed by reference unless specified (eg. ByVal). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An excerpt from my example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim sOuterList() As String
&amp;nbsp;&amp;nbsp;&amp;nbsp; getListFromLayer(pDoc.FocusMap.Layer(0), sOuterList)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sadly, I think using VBA/VB6 also prevents us from using String.Copy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:42:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17618#M430</guid>
      <dc:creator>Justin_ODell</dc:creator>
      <dc:date>2021-12-10T20:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a list of unique values from a field</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17619#M431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, one more shot at string/memory copy in VBA: &lt;STRONG&gt;CopyMemory&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A couple references, &lt;A href="http://www.ex-designz.net/apidetail.asp?api_id=216"&gt;here&lt;/A&gt; and &lt;A href="http://www.xtremevbtalk.com/showthread.php?t=131483"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 19:52:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-a-list-of-unique-values-from-a-field/m-p/17619#M431</guid>
      <dc:creator>ErinBrimhall</dc:creator>
      <dc:date>2015-06-01T19:52:51Z</dc:date>
    </item>
  </channel>
</rss>

