<?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: Polygon object references... in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/polygon-object-references/m-p/725480#M19350</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey guys,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Figured I'd reply as I seemingly found a solution.&amp;nbsp; Still have to do more testing, including stress tests, to validate how effective it is, but here goes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
//iterate through the query results and add them to the FEATURECOLLECTION.
while ((row = cursor.nextRow()) != null) {

 &lt;STRONG&gt;Feature feature1 = (Feature)row;
 Polygon currentPoly = (Polygon)feature1.getShapeCopy();&lt;/STRONG&gt;
 //Polygon currentPoly = (Polygon) row.getValue(9);
 switch (currentPoly.getGeometryType()) {
&amp;nbsp; case esriGeometryType.esriGeometryPolygon:
&amp;nbsp;&amp;nbsp; //build the geometry.
&amp;nbsp;&amp;nbsp; AgsGeometry geometry = new AgsGeometry(currentPoly);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; //build the feature.
&amp;nbsp;&amp;nbsp; AgsFeature feature = new AgsFeature(String.valueOf(row.getValue(0)),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geometry,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new HashMap&amp;lt;String,Object&amp;gt;());
 
&amp;nbsp;&amp;nbsp; features.add(feature);
&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; default:
&amp;nbsp;&amp;nbsp; throw new RuntimeException("Not implemented yet.");
&amp;nbsp; }
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 07:01:25 GMT</pubDate>
    <dc:creator>BillZborowski1</dc:creator>
    <dc:date>2021-12-12T07:01:25Z</dc:date>
    <item>
      <title>Polygon object references...</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/polygon-object-references/m-p/725479#M19349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi guys,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically what I'm doing is creating a wrapper around the Polygon class to include some extra variables I need for output.&amp;nbsp; I return query results and read them into a list, then created an ENCODE function to generate a specific JSON format I want to use.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem I'm having is that when I store a Polygon in an object list, if I then go back and write out the coordinates of the Polygon, every Polygon in the list writes the value of the LAST polygon retrieved in the search.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So if I run display(feature) it works as expected, if i add to the list and then display later, it takes the LAST polygon's value.&amp;nbsp; What gives?&amp;nbsp; This seems counter-intuitive.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
ICursor cursor = fclass.ITable_search(qf, true);
IRow row;
&amp;nbsp;&amp;nbsp; 
//create a list.
Collection&amp;lt;AgsFeature&amp;gt; features = new LinkedList&amp;lt;AgsFeature&amp;gt;();
&amp;nbsp;&amp;nbsp; 
//iterate through the query results and add them to the FEATURECOLLECTION.
while ((row = cursor.nextRow()) != null) {
 Polygon currentPoly = new Polygon();
 currentPoly = (Polygon)row.getValue(9);
 switch (currentPoly.getGeometryType()) {
&amp;nbsp; case esriGeometryType.esriGeometryPolygon:
&amp;nbsp;&amp;nbsp; //build the geometry.
&amp;nbsp;&amp;nbsp; AgsGeometry geometry = new AgsGeometry(currentPoly);
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; //build the feature.
&amp;nbsp;&amp;nbsp; AgsFeature feature = new AgsFeature(String.valueOf(row.getValue(0)),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geometry,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new HashMap&amp;lt;String,Object&amp;gt;());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; display(feature);
 
&amp;nbsp;&amp;nbsp; features.add(feature);
&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; default:
&amp;nbsp;&amp;nbsp; throw new RuntimeException("Not implemented yet.");
&amp;nbsp; }
}&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Sep 2010 19:59:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/polygon-object-references/m-p/725479#M19349</guid>
      <dc:creator>BillZborowski1</dc:creator>
      <dc:date>2010-09-08T19:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon object references...</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/polygon-object-references/m-p/725480#M19350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey guys,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Figured I'd reply as I seemingly found a solution.&amp;nbsp; Still have to do more testing, including stress tests, to validate how effective it is, but here goes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
//iterate through the query results and add them to the FEATURECOLLECTION.
while ((row = cursor.nextRow()) != null) {

 &lt;STRONG&gt;Feature feature1 = (Feature)row;
 Polygon currentPoly = (Polygon)feature1.getShapeCopy();&lt;/STRONG&gt;
 //Polygon currentPoly = (Polygon) row.getValue(9);
 switch (currentPoly.getGeometryType()) {
&amp;nbsp; case esriGeometryType.esriGeometryPolygon:
&amp;nbsp;&amp;nbsp; //build the geometry.
&amp;nbsp;&amp;nbsp; AgsGeometry geometry = new AgsGeometry(currentPoly);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; //build the feature.
&amp;nbsp;&amp;nbsp; AgsFeature feature = new AgsFeature(String.valueOf(row.getValue(0)),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geometry,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new HashMap&amp;lt;String,Object&amp;gt;());
 
&amp;nbsp;&amp;nbsp; features.add(feature);
&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; default:
&amp;nbsp;&amp;nbsp; throw new RuntimeException("Not implemented yet.");
&amp;nbsp; }
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:01:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/polygon-object-references/m-p/725480#M19350</guid>
      <dc:creator>BillZborowski1</dc:creator>
      <dc:date>2021-12-12T07:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Polygon object references...</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/polygon-object-references/m-p/725481#M19351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Bill,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The reason you have to do that is because of this line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;ICursor cursor = fclass.ITable_search(qf, true);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The "true" parameter (the recycling parameter) indicates that every time a new feature is returned from the geodatabase it overwrites the previous feature in memory. Your feature references were all pointing to the same memory at any one time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Provided you're just holding the polygons for later use and don't intend on modifying any of these features, keeping things as they are now (with recycling = true and the getShapeCopy method) is probably your best bet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;James&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Sep 2010 06:24:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/polygon-object-references/m-p/725481#M19351</guid>
      <dc:creator>JamesMacKay</dc:creator>
      <dc:date>2010-09-09T06:24:03Z</dc:date>
    </item>
  </channel>
</rss>

