# Adding a PolygonShape

**URL:** <https://community.thinkgeo.com/t/adding-a-polygonshape/1061>\
**Category:** WinForms\
**Created:** [February 19, 2010, 2:37pm UTC](https://community.thinkgeo.com/t/adding-a-polygonshape/1061 "2010-02-19T14:37:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![levirosol](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/levirosol/32/25009_2.png) [@levirosol](https://community.thinkgeo.com/u/levirosol)\
**Post date:** [February 19, 2010, 2:37pm UTC](https://community.thinkgeo.com/t/adding-a-polygonshape/1061/1 "2010-02-19T14:37:54Z")

</div>

I&nbsp;must&nbsp;be&nbsp;missing&nbsp;something&nbsp;simple.&nbsp;I&nbsp;have&nbsp;created&nbsp;a&nbsp;series&nbsp;of&nbsp;vertices&nbsp;to&nbsp;build&nbsp;a&nbsp;polygon.&nbsp;If&nbsp;i&nbsp;create&nbsp;a&nbsp;LineShape&nbsp;from&nbsp;them&nbsp;and&nbsp;add&nbsp;them&nbsp;to&nbsp;my&nbsp;layer,&nbsp;everything&nbsp;works&nbsp;perfectly:&nbsp;

&nbsp;

`linePoints.Add(new Vertex(minXminY));linePoints.Add(new Vertex(maxXminY));linePoints.Add(new Vertex(maxXmaxY));linePoints.Add(new Vertex(minXmaxY));linePoints.Add(new Vertex(minXminY));line = new LineShape(linePoints);newPolyLayer.FeatureSource.AddFeature(line);`

Now,&nbsp;if&nbsp;i&nbsp;load&nbsp;that&nbsp;line&nbsp;into&nbsp;a&nbsp;PolygonShape&nbsp;and&nbsp;do&nbsp;the&nbsp;same&nbsp;process&nbsp;to&nbsp;add&nbsp;it&nbsp;to&nbsp;the&nbsp;layer,&nbsp;nothing&nbsp;shows&nbsp;up&nbsp;on&nbsp;my&nbsp;map.&nbsp;Do&nbsp;i&nbsp;need&nbsp;to&nbsp;do&nbsp;something&nbsp;differently&nbsp;when&nbsp;working&nbsp;with&nbsp;a&nbsp;PolygonShape&nbsp;vs&nbsp;a&nbsp;LineShape??

`PolygonShape pathPart = new PolygonShape(line.GetWellKnownText().Replace("LINESTRING", "POLYGON(") + ")");newPolyLayer.FeatureSource.AddFeature(pathPart);`

Here's&nbsp;an&nbsp;example&nbsp;of&nbsp;the&nbsp;WKT:  
  
POLYGON((-96.5510170619308&nbsp;45.192079,-96.5510949380692&nbsp;45.192079,-96.5510949380692&nbsp;45.1921065365298,-96.5510170619308&nbsp;45.1921065365298,-96.5510170619308&nbsp;45.192079))

In&nbsp;both&nbsp;instances,&nbsp;the&nbsp;FeatureSource&nbsp;has&nbsp;the&nbsp;transaction&nbsp;open,&nbsp;and&nbsp;the&nbsp;layer&nbsp;is&nbsp;open.  
Also&nbsp;in&nbsp;both&nbsp;cases&nbsp;I&nbsp;set&nbsp;the&nbsp;defaultLineStyle&nbsp;and&nbsp;add&nbsp;the&nbsp;layer&nbsp;to&nbsp;the&nbsp;overlay,&nbsp;then&nbsp;refresh&nbsp;the&nbsp;map

`newPolyLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.SimpleColors.Black, 1, true);labelOverlay.Layers.Add("myLayer", newPolyLayer);map.Refresh();`

---

<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:** [February 19, 2010, 7:43pm UTC](https://community.thinkgeo.com/t/adding-a-polygonshape/1061/2 "2010-02-19T19:43:37Z")

</div>

levi,

Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;your&nbsp;sample&nbsp;code&nbsp;is&nbsp;very&nbsp;helpful&nbsp;to&nbsp;find&nbsp;the&nbsp;problem.

The&nbsp;PolygonShape&nbsp;is&nbsp;inherited&nbsp;from&nbsp;AreaBaseShape,&nbsp;so&nbsp;you&nbsp;need&nbsp;to&nbsp;set&nbsp;the&nbsp;DefaultAreaStyle&nbsp;to&nbsp;the&nbsp;layer&nbsp;which&nbsp;contains&nbsp;polygon.&nbsp;The&nbsp;code&nbsp;likes&nbsp;below:

`            newPolyLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Black));            newPolyLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Width = 1;            newPolyLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.LineJoin = DrawingLineJoin.Round;            newPolyLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;`

Please&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;more&nbsp;questions.

Thanks

James

---

<div class="post-metadata">

**Author:** ![levirosol](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/levirosol/32/25009_2.png) [@levirosol](https://community.thinkgeo.com/u/levirosol)\
**Post date:** [February 22, 2010, 8:36am UTC](https://community.thinkgeo.com/t/adding-a-polygonshape/1061/3 "2010-02-22T08:36:42Z")

</div>

Perfect.&nbsp;With&nbsp;this&nbsp;info&nbsp;I’m&nbsp;able&nbsp;to&nbsp;ditch&nbsp;the&nbsp;LineShape&nbsp;and&nbsp;WKT&nbsp;altogether&nbsp;and&nbsp;just&nbsp;new&nbsp;up&nbsp;a&nbsp;RingShape&nbsp;with&nbsp;my&nbsp;vertices.&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;API&nbsp;Documentation&nbsp;and&nbsp;Code&nbsp;Community&nbsp;didn’t&nbsp;help&nbsp;much&nbsp;when&nbsp;I&nbsp;was&nbsp;looking&nbsp;for&nbsp;samples&nbsp;for&nbsp;doing&nbsp;this,&nbsp;or&nbsp;for&nbsp;some&nbsp;other&nbsp;simple&nbsp;things.&nbsp;Is&nbsp;there&nbsp;any&nbsp;other&nbsp;documentation&nbsp;that&nbsp;I&nbsp;can&nbsp;access&nbsp;that&nbsp;goes&nbsp;over&nbsp;some&nbsp;of&nbsp;these&nbsp;101&nbsp;type&nbsp;processes?

---

<div class="post-metadata">

**Author:** ![Val](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e56c9b/32.png) [@Val](https://community.thinkgeo.com/u/Val)\
**Post date:** [February 22, 2010, 4:06pm UTC](https://community.thinkgeo.com/t/adding-a-polygonshape/1061/4 "2010-02-22T16:06:09Z")

</div>

Unfortunately,&nbsp;we&nbsp;currently&nbsp;don’t&nbsp;have&nbsp;the&nbsp;documentation&nbsp;to&nbsp;explain&nbsp;high&nbsp;level,&nbsp;101&nbsp;type&nbsp;of&nbsp;topics&nbsp;such&nbsp;as&nbsp;explaining&nbsp;what&nbsp;style&nbsp;to&nbsp;use&nbsp;for&nbsp;what&nbsp;type&nbsp;of&nbsp;shape&nbsp;and&nbsp;why.You&nbsp;are&nbsp;right&nbsp;to&nbsp;express&nbsp;concern&nbsp;that&nbsp;we&nbsp;lack&nbsp;such&nbsp;a&nbsp;documentation.&nbsp;  
&nbsp;&nbsp;&nbsp;We&nbsp;have&nbsp;had&nbsp;in&nbsp;plan&nbsp;to&nbsp;have&nbsp;such&nbsp;a&nbsp;documentation&nbsp;for&nbsp;a&nbsp;long&nbsp;time.&nbsp;Soon,&nbsp;we&nbsp;will&nbsp;start&nbsp;working&nbsp;on&nbsp;that&nbsp;and&nbsp;the&nbsp;documentation&nbsp;will&nbsp;be&nbsp;in&nbsp;a&nbsp;Wikipedia&nbsp;format.&nbsp;&nbsp;  
&nbsp;&nbsp;Thank&nbsp;you&nbsp;for&nbsp;reminding&nbsp;us&nbsp;of&nbsp;how&nbsp;important&nbsp;this&nbsp;is&nbsp;that&nbsp;we&nbsp;finally&nbsp;bring&nbsp;to&nbsp;our&nbsp;users&nbsp;the&nbsp;most&nbsp;complete&nbsp;documentation.

---

<div class="post-metadata">

**Author:** ![levirosol](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/levirosol/32/25009_2.png) [@levirosol](https://community.thinkgeo.com/u/levirosol)\
**Post date:** [February 23, 2010, 9:39am UTC](https://community.thinkgeo.com/t/adding-a-polygonshape/1061/5 "2010-02-23T09:39:49Z")

</div>

Good&nbsp;to&nbsp;hear.

Maybe&nbsp;this&nbsp;is&nbsp;another&nbsp;101&nbsp;thing...

I&nbsp;have&nbsp;this&nbsp;object:&nbsp;

`MultipolygonShape outline = MultipolygonShape.Union(path);`

And&nbsp;I&nbsp;need&nbsp;to&nbsp;apply&nbsp;a&nbsp;negative&nbsp;buffer&nbsp;to&nbsp;it.&nbsp;I&nbsp;went&nbsp;the&nbsp;route&nbsp;of&nbsp;

`outline.Buffer(-2, GeographyUnit.DecimalDegree, DistanceUnit.Meter);`

But&nbsp;get&nbsp;an&nbsp;inxedOutOfRange&nbsp;exception&nbsp;on&nbsp;distance.&nbsp;So,&nbsp;I&nbsp;took&nbsp;a&nbsp;look&nbsp;at&nbsp;the&nbsp;NegativeBuffer&nbsp;code&nbsp;sample.&nbsp;What&nbsp;it's&nbsp;doing&nbsp;makes&nbsp;sense,&nbsp;however,&nbsp;in&nbsp;the&nbsp;GetPerimeter&nbsp;method,&nbsp;OuterRing&nbsp;is&nbsp;called&nbsp;to&nbsp;get&nbsp;a&nbsp;collection&nbsp;of&nbsp;vertices&nbsp;on&nbsp;the&nbsp;PolygonShape.&nbsp;My&nbsp;issue&nbsp;is&nbsp;that&nbsp;I'm&nbsp;using&nbsp;a&nbsp;MultiPolygonShape&nbsp;and&nbsp;not&nbsp;a&nbsp;PolygonShape.&nbsp;Is&nbsp;there&nbsp;an&nbsp;easy&nbsp;conversion&nbsp;here?&nbsp;Or&nbsp;better&nbsp;yet,&nbsp;is&nbsp;there&nbsp;an&nbsp;easy&nbsp;way&nbsp;to&nbsp;get&nbsp;a&nbsp;list&nbsp;of&nbsp;vertices&nbsp;for&nbsp;my&nbsp;MultiPolygonShape?

---

<div class="post-metadata">

**Author:** ![levirosol](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/levirosol/32/25009_2.png) [@levirosol](https://community.thinkgeo.com/u/levirosol)\
**Post date:** [February 23, 2010, 11:09am UTC](https://community.thinkgeo.com/t/adding-a-polygonshape/1061/6 "2010-02-23T11:09:55Z")

</div>

The&nbsp;answer&nbsp;to&nbsp;get&nbsp;the&nbsp;NegativeBuffer&nbsp;code&nbsp;to&nbsp;work&nbsp;was&nbsp;to&nbsp;use&nbsp;the&nbsp;Polygons&nbsp;property&nbsp;on&nbsp;MultiPolygonShape

`foreach (PolygonShape polygon in outline.Polygons){// call it here}`

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [February 23, 2010, 2:07pm UTC](https://community.thinkgeo.com/t/adding-a-polygonshape/1061/7 "2010-02-23T14:07:46Z")

</div>

Levi,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;One&nbsp;other&nbsp;thing&nbsp;to&nbsp;add&nbsp;is&nbsp;that&nbsp;with&nbsp;the&nbsp;developer&nbsp;build&nbsp;we&nbsp;have&nbsp;fixed&nbsp;the&nbsp;Buffer&nbsp;method&nbsp;to&nbsp;support&nbsp;negative&nbsp;buffering.&nbsp;&nbsp;In&nbsp;the&nbsp;past&nbsp;we&nbsp;did&nbsp;not&nbsp;allow&nbsp;it&nbsp;but&nbsp;it&nbsp;is&nbsp;part&nbsp;of&nbsp;the&nbsp;next&nbsp;release&nbsp;to&nbsp;have&nbsp;the&nbsp;API&nbsp;accept&nbsp;negative&nbsp;values.&nbsp;&nbsp;If&nbsp;you&nbsp;get&nbsp;the&nbsp;latest&nbsp;developer&nbsp;build&nbsp;this&nbsp;should&nbsp;work&nbsp;for&nbsp;you&nbsp;if&nbsp;interested.&nbsp;  
&nbsp;&nbsp;  
&nbsp;David

---

<div class="post-metadata">

**Author:** ![Val](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/e56c9b/32.png) [@Val](https://community.thinkgeo.com/u/Val)\
**Post date:** [February 25, 2010, 10:10am UTC](https://community.thinkgeo.com/t/adding-a-polygonshape/1061/8 "2010-02-25T10:10:26Z")

</div>

&nbsp;I&nbsp;would&nbsp;like&nbsp;to&nbsp;also&nbsp;comment&nbsp;that&nbsp;in&nbsp;the&nbsp;older&nbsp;versions&nbsp;of&nbsp;Map&nbsp;Suite,&nbsp;it&nbsp;is&nbsp;still&nbsp;possible&nbsp;to&nbsp;apply&nbsp;negative&nbsp;buffering.&nbsp;You&nbsp;can&nbsp;see&nbsp;that&nbsp;in&nbsp;the&nbsp;project&nbsp;of&nbsp;the&nbsp;Code&nbsp;Community,&nbsp;_Negative&nbsp;Buffering_.

[code.thinkgeo.com/projects/s...ebuffering](http://code.thinkgeo.com/projects/show/negativebuffering)

&nbsp;

&nbsp;
