# MultipolygonShape.Contains()

**URL:** <https://community.thinkgeo.com/t/multipolygonshape-contains/1525>\
**Category:** WinForms\
**Created:** [December 5, 2010, 11:12pm UTC](https://community.thinkgeo.com/t/multipolygonshape-contains/1525 "2010-12-05T23:12:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@Michael5](https://community.thinkgeo.com/u/Michael5)\
**Post date:** [December 5, 2010, 11:12pm UTC](https://community.thinkgeo.com/t/multipolygonshape-contains/1525/1 "2010-12-05T23:12:34Z")

</div>

Hi&nbsp;there.

I've&nbsp;been&nbsp;having&nbsp;a&nbsp;play&nbsp;with&nbsp;the&nbsp;Desktop&nbsp;Eval&nbsp;Version&nbsp;3.0,&nbsp;and&nbsp;for&nbsp;the&nbsp;life&nbsp;of&nbsp;me&nbsp;can't&nbsp;get&nbsp;this&nbsp;(seemingly&nbsp;simple)&nbsp;thing&nbsp;to&nbsp;work.

I&nbsp;have&nbsp;a&nbsp;MultiPolygonShape&nbsp;object&nbsp;which&nbsp;may&nbsp;contain&nbsp;1&nbsp;or&nbsp;more&nbsp;PolygonShape&nbsp;objects.

Now,&nbsp;I'm&nbsp;trying&nbsp;to&nbsp;look&nbsp;through&nbsp;a&nbsp;collection&nbsp;of&nbsp;PointShape's&nbsp;(2500&nbsp;of&nbsp;them),&nbsp;and&nbsp;identify&nbsp;which&nbsp;fall&nbsp;within&nbsp;the&nbsp;MultiPolygonShape&nbsp;region.

&nbsp;

The&nbsp;function&nbsp;MultiPolygonShape.Contains(PointShape)&nbsp;seems&nbsp;like&nbsp;the&nbsp;obvious&nbsp;thing&nbsp;to&nbsp;use,&nbsp;but&nbsp;I&nbsp;can't&nbsp;get&nbsp;it&nbsp;to&nbsp;return&nbsp;anything&nbsp;at&nbsp;all.&nbsp;It's&nbsp;meant&nbsp;to&nbsp;return&nbsp;a&nbsp;bool,&nbsp;but&nbsp;I'm&nbsp;not&nbsp;getting&nbsp;true/false&nbsp;back.&nbsp;Same&nbsp;goes&nbsp;for&nbsp;some&nbsp;other&nbsp;functions&nbsp;I've&nbsp;tried&nbsp;(IsWithin(),&nbsp;Crosses(),&nbsp;Intersects(),&nbsp;etc).

I've&nbsp;confirmed&nbsp;that&nbsp;correct&nbsp;values&nbsp;are&nbsp;in&nbsp;each&nbsp;shape&nbsp;object,&nbsp;and&nbsp;I&nbsp;don't&nbsp;seem&nbsp;to&nbsp;get&nbsp;any&nbsp;error&nbsp;messages.

My&nbsp;first&nbsp;thought&nbsp;was&nbsp;that&nbsp;maybe&nbsp;the&nbsp;eval&nbsp;version&nbsp;limits&nbsp;this?&nbsp;But&nbsp;from&nbsp;looking&nbsp;around&nbsp;on&nbsp;the&nbsp;web&nbsp;it&nbsp;seems&nbsp;this&nbsp;isn't&nbsp;the&nbsp;case.

&nbsp;

Any&nbsp;ideas&nbsp;what&nbsp;may&nbsp;be&nbsp;causing&nbsp;this?

&nbsp;

Thanks&nbsp;in&nbsp;advance!

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [December 6, 2010, 3:05am UTC](https://community.thinkgeo.com/t/multipolygonshape-contains/1525/2 "2010-12-06T03:05:51Z")

</div>

Michael,

Thanks&nbsp;for&nbsp;your&nbsp;post.

I&nbsp;am&nbsp;not&nbsp;sure&nbsp;why&nbsp;you&nbsp;don't&nbsp;want&nbsp;to&nbsp;use&nbsp;bool&nbsp;to&nbsp;check&nbsp;if&nbsp;a&nbsp;polygon&nbsp;contains&nbsp;a&nbsp;pointShape,&nbsp;but&nbsp;I&nbsp;think&nbsp;it's&nbsp;a&nbsp;good&nbsp;way&nbsp;to&nbsp;do&nbsp;it.

`Collection<PointShape> result = new Collection<PointShape>();            foreach (PointShape pointShape in pointShapes)            {                if (pointShape.IsWithin(multipolygonShape))                {                    result.Add(pointShape);                }            }`

There&nbsp;is&nbsp;another&nbsp;way&nbsp;maybe&nbsp;look&nbsp;like&nbsp;more&nbsp;professional&nbsp;way&nbsp;but&nbsp;actual&nbsp;not&nbsp;good:

`InMemoryFeatureLayer layer = new InMemoryFeatureLayer();            foreach (PointShape pointShape in pointShapes)            {                layer.InternalFeatures.Add(new Feature(pointShape));            }            Collection<Feature> features = layer.QueryTools.GetFeaturesWithin(multipolygonShape, ReturningColumnsType.NoColumns);            foreach (Feature feature in features)            {                result.Add((PointShape)feature.GetShape());            }`

Please&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;misundestand.

Thanks

James

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [December 6, 2010, 3:09am UTC](https://community.thinkgeo.com/t/multipolygonshape-contains/1525/3 "2010-12-06T03:09:52Z")

</div>

Micheal,&nbsp;  
&nbsp;&nbsp;  
&nbsp;If&nbsp;you&nbsp;still&nbsp;can&nbsp;not&nbsp;solve&nbsp;your&nbsp;problem,&nbsp;please&nbsp;provide&nbsp;the&nbsp;sample&nbsp;data&nbsp;to&nbsp;us.&nbsp;The&nbsp;MultiPolygonShape&nbsp;and&nbsp;just&nbsp;one&nbsp;of&nbsp;PointShapes&nbsp;which&nbsp;will&nbsp;stop&nbsp;to&nbsp;cause&nbsp;your&nbsp;problem.&nbsp;The&nbsp;best&nbsp;way&nbsp;is&nbsp;send&nbsp;the&nbsp;wellknown&nbsp;text&nbsp;to&nbsp;us,&nbsp;you&nbsp;can&nbsp;call&nbsp;GetWellKnownText()&nbsp;method&nbsp;of&nbsp;any&nbsp;shapes.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;  
&nbsp;James

---

<div class="post-metadata">

**Author:** ![Michael5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@Michael5](https://community.thinkgeo.com/u/Michael5)\
**Post date:** [December 7, 2010, 4:46pm UTC](https://community.thinkgeo.com/t/multipolygonshape-contains/1525/4 "2010-12-07T16:46:34Z")

</div>

Hi&nbsp;James,

Thanks&nbsp;for&nbsp;the&nbsp;quick&nbsp;reply.

The&nbsp;issue&nbsp;isn't&nbsp;that&nbsp;I&nbsp;don't&nbsp;want&nbsp;to&nbsp;use&nbsp;bool,&nbsp;it's&nbsp;that&nbsp;I&nbsp;don't&nbsp;seem&nbsp;to&nbsp;be&nbsp;able&nbsp;to.&nbsp;The&nbsp;functions&nbsp;that&nbsp;I'm&nbsp;trying&nbsp;to&nbsp;use&nbsp;(Contains(),&nbsp;IsWithin(),&nbsp;Crosses(),&nbsp;Intersects(),&nbsp;etc)&nbsp;just&nbsp;don't&nbsp;seem&nbsp;to&nbsp;return&nbsp;anything,&nbsp;which&nbsp;doesn't&nbsp;make&nbsp;sense&nbsp;to&nbsp;me!

The&nbsp;first&nbsp;method&nbsp;that&nbsp;you&nbsp;posted&nbsp;is&nbsp;the&nbsp;one&nbsp;I've&nbsp;been&nbsp;trying,&nbsp;with&nbsp;no&nbsp;success.

I'll&nbsp;give&nbsp;the&nbsp;second&nbsp;method&nbsp;a&nbsp;shot&nbsp;shortly&nbsp;and&nbsp;let&nbsp;you&nbsp;know&nbsp;how&nbsp;it&nbsp;goes.&nbsp;If&nbsp;still&nbsp;no&nbsp;luck&nbsp;I'll&nbsp;post&nbsp;the&nbsp;shapes&nbsp;and&nbsp;hopefully&nbsp;we&nbsp;can&nbsp;see&nbsp;what's&nbsp;going&nbsp;on.

Thanks&nbsp;again.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [December 7, 2010, 9:40pm UTC](https://community.thinkgeo.com/t/multipolygonshape-contains/1525/5 "2010-12-07T21:40:52Z")

</div>

Michael,

You&nbsp;need&nbsp;to&nbsp;define&nbsp;a&nbsp;bool&nbsp;variable&nbsp;and&nbsp;equal&nbsp;to&nbsp;IsWithin(),&nbsp;such&nbsp;like&nbsp;code&nbsp;below:  
  
`bool result = pointShape.IsWithin(multipolygonShape);`  
the&nbsp;result&nbsp;variable&nbsp;is&nbsp;the&nbsp;return&nbsp;value,&nbsp;if&nbsp;you&nbsp;think&nbsp;the&nbsp;value&nbsp;of&nbsp;it&nbsp;is&nbsp;default,&nbsp;not&nbsp;return&nbsp;from&nbsp;IsWithin(),&nbsp;you&nbsp;can&nbsp;define&nbsp;a&nbsp;object&nbsp;myObject,&nbsp;the&nbsp;default&nbsp;value&nbsp;set&nbsp;to&nbsp;null,&nbsp;and&nbsp;after&nbsp;call&nbsp;method&nbsp;it&nbsp;will&nbsp;fill&nbsp;things.  
  
`Object myObject = null;            myObject = pointShape.IsWithin(multipolygonShape);            if (myObject == null)            {                Debug.WriteLine("don't return anything");            }            else            {                Debug.WriteLine("return something");            }`  
thanks  
  
James

---

<div class="post-metadata">

**Author:** ![Michael5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@Michael5](https://community.thinkgeo.com/u/Michael5)\
**Post date:** [December 7, 2010, 10:49pm UTC](https://community.thinkgeo.com/t/multipolygonshape-contains/1525/6 "2010-12-07T22:49:12Z")

</div>

Hi&nbsp;James,

Thanks,&nbsp;storing&nbsp;the&nbsp;result&nbsp;in&nbsp;a&nbsp;temporary&nbsp;Object&nbsp;seems&nbsp;to&nbsp;let&nbsp;me&nbsp;view&nbsp;the&nbsp;return&nbsp;result.&nbsp;Now&nbsp;the&nbsp;issue&nbsp;is&nbsp;that&nbsp;all&nbsp;my&nbsp;results&nbsp;seem&nbsp;to&nbsp;be&nbsp;false&nbsp;when&nbsp;doing:

MultipolygonShape.Contains(PointShape);

&nbsp;

&nbsp;

Here&nbsp;is&nbsp;an&nbsp;example&nbsp;of&nbsp;the&nbsp;MultiPolygonShape:

MULTIPOLYGON(((142.8662109375&nbsp;-36.65087890625,142.8662109375&nbsp;-36.15087890625,142.8662109375&nbsp;-35.65087890625,142.8662109375&nbsp;-35.15087890625,142.8662109375&nbsp;-34.65087890625,143.3662109375&nbsp;-34.65087890625,143.8662109375&nbsp;-34.65087890625,144.3662109375&nbsp;-34.65087890625,144.8662109375&nbsp;-34.65087890625,145.3662109375&nbsp;-34.65087890625,145.8662109375&nbsp;-34.65087890625,146.3662109375&nbsp;-34.65087890625,146.8662109375&nbsp;-34.65087890625,147.3662109375&nbsp;-34.65087890625,147.8662109375&nbsp;-34.65087890625,148.3662109375&nbsp;-34.65087890625,148.8662109375&nbsp;-34.65087890625,148.8662109375&nbsp;-35.15087890625,148.8662109375&nbsp;-35.65087890625,148.8662109375&nbsp;-36.15087890625,148.8662109375&nbsp;-36.65087890625,148.8662109375&nbsp;-37.15087890625,148.3662109375&nbsp;-37.15087890625,147.8662109375&nbsp;-37.15087890625,147.3662109375&nbsp;-37.15087890625,146.8662109375&nbsp;-37.15087890625,146.3662109375&nbsp;-37.15087890625,145.8662109375&nbsp;-37.15087890625,145.3662109375&nbsp;-37.15087890625,144.8662109375&nbsp;-37.15087890625,144.3662109375&nbsp;-37.15087890625,143.8662109375&nbsp;-37.15087890625,143.3662109375&nbsp;-37.15087890625,142.8662109375&nbsp;-37.15087890625,142.8662109375&nbsp;-36.65087890625)))

&nbsp;

and&nbsp;a&nbsp;point&nbsp;that&nbsp;I&nbsp;know&nbsp;should&nbsp;lie&nbsp;within&nbsp;that&nbsp;region:

POINT(146.89999&nbsp;-36.1&nbsp;)

Any&nbsp;ideas?

Thanks&nbsp;for&nbsp;the&nbsp;help&nbsp;so&nbsp;far!

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![Michael5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@Michael5](https://community.thinkgeo.com/u/Michael5)\
**Post date:** [December 7, 2010, 11:05pm UTC](https://community.thinkgeo.com/t/multipolygonshape-contains/1525/7 "2010-12-07T23:05:43Z")

</div>

Oh&nbsp;dear,&nbsp;I&nbsp;figured&nbsp;it&nbsp;out&nbsp;:x

For&nbsp;some&nbsp;reason&nbsp;a&nbsp;large&nbsp;portion&nbsp;of&nbsp;PointShape's&nbsp;had&nbsp;their&nbsp;longitude/latitude&nbsp;reversed.&nbsp;All&nbsp;fixed&nbsp;now!

&nbsp;

Thanks&nbsp;for&nbsp;the&nbsp;help&nbsp;James!

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [December 8, 2010, 1:33am UTC](https://community.thinkgeo.com/t/multipolygonshape-contains/1525/8 "2010-12-08T01:33:30Z")

</div>

Michael,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;am&nbsp;glad&nbsp;you&nbsp;solve&nbsp;your&nbsp;problem,&nbsp;I&nbsp;also&nbsp;just&nbsp;want&nbsp;to&nbsp;let&nbsp;you&nbsp;know&nbsp;the&nbsp;test&nbsp;result&nbsp;is&nbsp;true.&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BaseShape&nbsp;shape&nbsp;=&nbsp;BaseShape.CreateShapeFromWellKnownData("MULTIPOLYGON(((142.8662109375&nbsp;-36.65087890625,142.8662109375&nbsp;-36.15087890625,142.8662109375&nbsp;-35.65087890625,142.8662109375&nbsp;-35.15087890625,142.8662109375&nbsp;-34.65087890625,143.3662109375&nbsp;-34.65087890625,143.8662109375&nbsp;-34.65087890625,144.3662109375&nbsp;-34.65087890625,144.8662109375&nbsp;-34.65087890625,145.3662109375&nbsp;-34.65087890625,145.8662109375&nbsp;-34.65087890625,146.3662109375&nbsp;-34.65087890625,146.8662109375&nbsp;-34.65087890625,147.3662109375&nbsp;-34.65087890625,147.8662109375&nbsp;-34.65087890625,148.3662109375&nbsp;-34.65087890625,148.8662109375&nbsp;-34.65087890625,148.8662109375&nbsp;-35.15087890625,148.8662109375&nbsp;-35.65087890625,148.8662109375&nbsp;-36.15087890625,148.8662109375&nbsp;-36.65087890625,148.8662109375&nbsp;-37.15087890625,148.3662109375&nbsp;-37.15087890625,147.8662109375&nbsp;-37.15087890625,147.3662109375&nbsp;-37.15087890625,146.8662109375&nbsp;-37.15087890625,146.3662109375&nbsp;-37.15087890625,145.8662109375&nbsp;-37.15087890625,145.3662109375&nbsp;-37.15087890625,144.8662109375&nbsp;-37.15087890625,144.3662109375&nbsp;-37.15087890625,143.8662109375&nbsp;-37.15087890625,143.3662109375&nbsp;-37.15087890625,142.8662109375&nbsp;-37.15087890625,142.8662109375&nbsp;-36.65087890625)))");&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BaseShape&nbsp;shape1&nbsp;=&nbsp;BaseShape.CreateShapeFromWellKnownData("POINT(146.89999&nbsp;-36.1&nbsp;)");&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;result&nbsp;=&nbsp;shape.Contains(shape1);&nbsp;  
&nbsp;&nbsp;  
&nbsp;Let&nbsp;me&nbsp;know&nbsp;when&nbsp;you&nbsp;have&nbsp;more&nbsp;questions.&nbsp;  
&nbsp;James&nbsp;  
&nbsp;&nbsp;
