<?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: How to retrieve polygon geometry? in File Geodatabase API Questions</title>
    <link>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27757#M29</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you, I've got it implemented and working here now.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 Apr 2011 06:14:13 GMT</pubDate>
    <dc:creator>KarlHedlund</dc:creator>
    <dc:date>2011-04-27T06:14:13Z</dc:date>
    <item>
      <title>How to retrieve polygon geometry?</title>
      <link>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27753#M25</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It feels a bit weird that I would first have to get the geometry, then check its shape and geometry type, then retrieve it once again.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;attrQueryRow.GetGeometry(geometry);
int shapeType;
geometry.GetShapeType(shapeType);
GeometryType geometryType = (GeometryType)(geometry.GeometryType(shapeType));

vector&amp;lt;Point&amp;gt; retrievedPoints;

&amp;nbsp; switch(geometryType)
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; case GeometryType::geometryPolygon:
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int numPoints;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((MultiPointShapeBuffer*)&amp;amp;geometry)-&amp;gt;GetNumPoints(numPoints);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(numPoints &amp;gt; 1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retrievedPoints.resize(numPoints);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Point* testP = &amp;amp;(retrievedPoints[0]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((MultiPointShapeBuffer*)&amp;amp;geometry)-&amp;gt;GetPoints(testP);&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In this example, retrievedPoints gets filled with Point objects with x = 0 and y = 0, which is not correct. If I would take the same geometry and use it as a point geometry, I would get one correct point coordinate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I missing something?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Apr 2011 11:49:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27753#M25</guid>
      <dc:creator>KarlHedlund</dc:creator>
      <dc:date>2011-04-20T11:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve polygon geometry?</title>
      <link>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27754#M26</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It seems you are supposed to just send a new pointer and the GetPoints() will allocate memory for its points and set the pointer to that memory, but is there a method that frees the memory?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 04:58:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27754#M26</guid>
      <dc:creator>KarlHedlund</dc:creator>
      <dc:date>2011-04-21T04:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve polygon geometry?</title>
      <link>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27755#M27</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; It feels a bit weird that I would first have to get the geometry, then check its shape and geometry type, then retrieve it once again.&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; &lt;PRE class="lia-code-sample line-numbers language-none"&gt;attrQueryRow.GetGeometry(geometry);
int shapeType;
geometry.GetShapeType(shapeType);
GeometryType geometryType = (GeometryType)(geometry.GeometryType(shapeType));

vector&amp;lt;Point&amp;gt; retrievedPoints;

&amp;nbsp; switch(geometryType)
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; case GeometryType::geometryPolygon:
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int numPoints;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((Multi&lt;SPAN style="color:&amp;quot;Red&amp;quot;;"&gt;Point&lt;/SPAN&gt;ShapeBuffer*)&amp;amp;geometry)-&amp;gt;GetNumPoints(numPoints);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(numPoints &amp;gt; 1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retrievedPoints.resize(numPoints);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Point* testP = &amp;amp;(retrievedPoints[0]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((MultiPointShapeBuffer*)&amp;amp;geometry)-&amp;gt;GetPoints(testP);&lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;In this example, retrievedPoints gets filled with Point objects with x = 0 and y = 0, which is not correct. If I would take the same geometry and use it as a point geometry, I would get one correct point coordinate.&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;Am I missing something?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is not necessary to retrieve the geometry more than once. One way is to figure out ahead of time what the geometry type is and instantiate the appropriate ShapeBuffer derived class and use that in the call to GetGeometry. The other is to use the ShapeBuffer base class and then do a reinterpret cast to one of the derived classes based on the geometry type - it is possible to do this because the derived classes have no additional state beyond what the base class has. This is what you have in your bit of sample code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem in your sample code appears to due to the fact that you are using the wrong shapebuffer derived class in your cast. You are casting to Multi&lt;/SPAN&gt;&lt;SPAN style="color:&amp;quot;Red&amp;quot;;"&gt;Point&lt;/SPAN&gt;&lt;SPAN&gt;ShapeBuffer but for Polygons (and Polylines) you should be using Multi&lt;/SPAN&gt;&lt;SPAN style="color:&amp;quot;Red&amp;quot;;"&gt;Part&lt;/SPAN&gt;&lt;SPAN&gt;ShapeBuffer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-David Sousa&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:07:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27755#M27</guid>
      <dc:creator>DavidSousa</dc:creator>
      <dc:date>2021-12-10T21:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve polygon geometry?</title>
      <link>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27756#M28</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It seems you are supposed to just send a new pointer and the GetPoints() will allocate memory for its points and set the pointer to that memory, but is there a method that frees the memory?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When using the ShapeBuffer classes, you need to keep in mind the fact that the accessor functions are working directly with the raw byte array.&amp;nbsp; None of these functions are allocating any memory, rather, they are calculating an offset to a particular position within the shape buffer (e.g., the parts array or points array) and then casting that pointer to the appropriate type (double, int, etc.).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The memory is freed automatically by the shape buffer destructor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-David Sousa&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 17:13:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27756#M28</guid>
      <dc:creator>DavidSousa</dc:creator>
      <dc:date>2011-04-21T17:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve polygon geometry?</title>
      <link>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27757#M29</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you, I've got it implemented and working here now.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Apr 2011 06:14:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/file-geodatabase-api-questions/how-to-retrieve-polygon-geometry/m-p/27757#M29</guid>
      <dc:creator>KarlHedlund</dc:creator>
      <dc:date>2011-04-27T06:14:13Z</dc:date>
    </item>
  </channel>
</rss>

