<?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 How to find the center of a complex shaped feature. in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-the-center-of-a-complex-shaped-feature/m-p/291433#M7569</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a feature with the shape as shown below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]32089[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to draw an image at the center of this feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was using a very simple algorithm to determine the center of the feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Clearly this does not work for all shapes (the icon is painted on the hypotenuse of the triangle) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My algorithm will likely fail for round objects to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a common way to get the center of a feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 10 Mar 2014 19:13:29 GMT</pubDate>
    <dc:creator>RickeyTom</dc:creator>
    <dc:date>2014-03-10T19:13:29Z</dc:date>
    <item>
      <title>How to find the center of a complex shaped feature.</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-the-center-of-a-complex-shaped-feature/m-p/291433#M7569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a feature with the shape as shown below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]32089[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to draw an image at the center of this feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was using a very simple algorithm to determine the center of the feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Clearly this does not work for all shapes (the icon is painted on the hypotenuse of the triangle) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My algorithm will likely fail for round objects to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a common way to get the center of a feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2014 19:13:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-the-center-of-a-complex-shaped-feature/m-p/291433#M7569</guid>
      <dc:creator>RickeyTom</dc:creator>
      <dc:date>2014-03-10T19:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the center of a complex shaped feature.</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-the-center-of-a-complex-shaped-feature/m-p/291434#M7570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Does the &lt;/SPAN&gt;&lt;STRONG&gt;Centroid &lt;/STRONG&gt;&lt;SPAN&gt;property off the &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//002m00000094000000"&gt;IArea &lt;/A&gt;&lt;SPAN&gt;interface give you a more accurate center?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Envelope, GeoEllipse, GeoPolygon, Multipatch, Polygon, and Ring are all geometry types that implement IArea.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2014 19:53:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-the-center-of-a-complex-shaped-feature/m-p/291434#M7570</guid>
      <dc:creator>ErinBrimhall</dc:creator>
      <dc:date>2014-03-10T19:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the center of a complex shaped feature.</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-the-center-of-a-complex-shaped-feature/m-p/291435#M7571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Does the &lt;STRONG&gt;Centroid &lt;/STRONG&gt;property off the &lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//002m00000094000000" rel="nofollow" target="_blank"&gt;IArea &lt;/A&gt;interface give you a more accurate center?&lt;BR /&gt;&lt;BR /&gt;Envelope, GeoEllipse, GeoPolygon, Multipatch, Polygon, and Ring are all geometry types that implement IArea.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I saw something about this in the forums, and I will pursue that. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My current challenge is to determine, how to get an IArea from an IEnvelop (which is associated with an IFeature)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2014 19:59:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-the-center-of-a-complex-shaped-feature/m-p/291435#M7571</guid>
      <dc:creator>RickeyTom</dc:creator>
      <dc:date>2014-03-10T19:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the center of a complex shaped feature.</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-the-center-of-a-complex-shaped-feature/m-p/291436#M7572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can simply cast the IEnvelope object as an IArea, but keep in mind that the Envelope is the smallest rectangle that the geometry can fit inside.&amp;nbsp; So the centroid of the Envelope will still resemble the point drawn in your original post's screenshot.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You might want to try something like the method below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

private IPoint GetCentroid(IFeature feature)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; IArea area = feature.Shape as IArea;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (area == null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return null; // Or throw an exception here, or handle other Geometry types that don't implement IArea, etc.

&amp;nbsp;&amp;nbsp;&amp;nbsp; return area.Centroid;
}

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:02:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-the-center-of-a-complex-shaped-feature/m-p/291436#M7572</guid>
      <dc:creator>ErinBrimhall</dc:creator>
      <dc:date>2021-12-11T14:02:51Z</dc:date>
    </item>
  </channel>
</rss>

