<?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 out if a point is within the area bounded by a polygon? in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-out-if-a-point-is-within-the-area/m-p/273032#M6969</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to find out if a point is within the area bounded by a polygon.&amp;nbsp; Here's what got so far:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;IRelationalOperator2 pointRelationalOperator = MyPoly as IRelationalOperator2;
bool ok = pointRelationalOperator.Within(MyPoly as IGeometry); //this is ok the polygon contains itself&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;bool ok = pointRelationalOperator.Contains(MyPoly as IGeometry); //this is also ok&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next convert Polygon into a PointCollection, grab a point, and see if that point is "within()" the polygon.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
IPointCollection4 pc4 = MyPoly as IPointCollection4;
for (int i = 0; i &amp;lt; pc4.PointCount; i++)
{
IPoint thisPoint = pc4.get_Point(i);
bool isPointInPolygon = pointRelationalOperator.Within(thisPoint); //tried both Within and Contains
isPointInPolygon = pointRelationalOperator.Contains(thisPoint);
}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;isPointInPolygon is always false.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The polygon is non-empty, it is closed and it returns a length and has 347 points.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fyi, I am creating the polygon by loading up a shape file, then merging all the feature classes into one polygon according to this tutorial, &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000009t000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000009t000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 13:20:16 GMT</pubDate>
    <dc:creator>PatrickBurke</dc:creator>
    <dc:date>2021-12-11T13:20:16Z</dc:date>
    <item>
      <title>How to find out if a point is within the area bounded by a polygon?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-out-if-a-point-is-within-the-area/m-p/273032#M6969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to find out if a point is within the area bounded by a polygon.&amp;nbsp; Here's what got so far:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;IRelationalOperator2 pointRelationalOperator = MyPoly as IRelationalOperator2;
bool ok = pointRelationalOperator.Within(MyPoly as IGeometry); //this is ok the polygon contains itself&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;bool ok = pointRelationalOperator.Contains(MyPoly as IGeometry); //this is also ok&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next convert Polygon into a PointCollection, grab a point, and see if that point is "within()" the polygon.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
IPointCollection4 pc4 = MyPoly as IPointCollection4;
for (int i = 0; i &amp;lt; pc4.PointCount; i++)
{
IPoint thisPoint = pc4.get_Point(i);
bool isPointInPolygon = pointRelationalOperator.Within(thisPoint); //tried both Within and Contains
isPointInPolygon = pointRelationalOperator.Contains(thisPoint);
}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;isPointInPolygon is always false.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The polygon is non-empty, it is closed and it returns a length and has 347 points.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fyi, I am creating the polygon by loading up a shape file, then merging all the feature classes into one polygon according to this tutorial, &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000009t000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000009t000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:20:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-out-if-a-point-is-within-the-area/m-p/273032#M6969</guid>
      <dc:creator>PatrickBurke</dc:creator>
      <dc:date>2021-12-11T13:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out if a point is within the area bounded by a polygon?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-out-if-a-point-is-within-the-area/m-p/273033#M6970</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you a pass point, you can use CONTAINS method to check whether the point is COMPLETELY inside the polygon but return false if the point is on the boundary line or outside the polygon.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;IPointCollection4 pc4 = MyPoly as IPointCollection4;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (int i = 0; i &amp;lt; pc4.PointCount; i++)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IPoint thisPoint = pc4.get_Point(i);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bool isPointInPolygon = pointRelationalOperator.Within(thisPoint); //tried both Within and Contains&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;isPointInPolygon = pointRelationalOperator.Contains(thisPoint);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In th above piece of code, you are checking whether the polygon vertices are present inside the polygon. But the vertices fall on the boundary line of the polygon and hence CONTAINS method always returns false.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://edndoc.esri.com/arcobjects/9.1/componenthelp/esrigeometry/IRelationalOperator_Contains.htm"&gt;http://edndoc.esri.com/arcobjects/9.1/componenthelp/esrigeometry/IRelationalOperator_Contains.htm&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Sep 2010 08:08:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-find-out-if-a-point-is-within-the-area/m-p/273033#M6970</guid>
      <dc:creator>ThavitinaiduGulivindala</dc:creator>
      <dc:date>2010-09-11T08:08:19Z</dc:date>
    </item>
  </channel>
</rss>

