# Negative Buffering on a PolygonShape

**URL:** <https://community.thinkgeo.com/t/negative-buffering-on-a-polygonshape/2338>\
**Category:** WinForms\
**Created:** [January 30, 2014, 8:17am UTC](https://community.thinkgeo.com/t/negative-buffering-on-a-polygonshape/2338 "2014-01-30T08:17:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/87869e/32.png) [@Richard5](https://community.thinkgeo.com/u/Richard5)\
**Post date:** [January 30, 2014, 8:17am UTC](https://community.thinkgeo.com/t/negative-buffering-on-a-polygonshape/2338/1 "2014-01-30T08:17:10Z")

</div>

We&nbsp;are&nbsp;currently&nbsp;using&nbsp;DesktopEdition&nbsp;6.0.0.368.&nbsp;&nbsp;  
  
  
  
I&nbsp;am&nbsp;trying&nbsp;to&nbsp;use&nbsp;the&nbsp;Buffer&nbsp;method&nbsp;on&nbsp;a&nbsp;PolygonShape&nbsp;to&nbsp;create&nbsp;a&nbsp;buffer&nbsp;outside&nbsp;or&nbsp;inside&nbsp;the&nbsp;polygon.&nbsp;&nbsp;&nbsp;polygonShape.Buffer&nbsp;seems&nbsp;to&nbsp;correctly&nbsp;return&nbsp;the&nbsp;buffer&nbsp;outside&nbsp;the&nbsp;polygon&nbsp;when&nbsp;I&nbsp;use&nbsp;a&nbsp;positive&nbsp;distance&nbsp;giving&nbsp;me&nbsp;a&nbsp;larger&nbsp;“MultipolygonShape”.&nbsp;&nbsp;&nbsp;However&nbsp;when&nbsp;I&nbsp;make&nbsp;the&nbsp;distance&nbsp;negative,&nbsp;polygonShape.Buffer&nbsp;returns&nbsp;the&nbsp;same&nbsp;polygonShape&nbsp;vertices&nbsp;in&nbsp;the&nbsp;“MultipolygonShape”.&nbsp;&nbsp;&nbsp;My&nbsp;units&nbsp;are&nbsp;Geography.DecimalDegrees&nbsp;and&nbsp;DistanceUnit.Kilometer.  
  
  
  
I&nbsp;found&nbsp;the&nbsp;Negative&nbsp;Buffering&nbsp;sample&nbsp;application&nbsp;so&nbsp;I&nbsp;cut&nbsp;and&nbsp;pasted&nbsp;the&nbsp;code&nbsp;from&nbsp;the&nbsp;sample.&nbsp;&nbsp;It&nbsp;gets&nbsp;the&nbsp;perimeter&nbsp;of&nbsp;the&nbsp;polygonShape&nbsp;&nbsp;as&nbsp;a&nbsp;Lineshape&nbsp;and&nbsp;then&nbsp;uses&nbsp;the&nbsp;lineShape.Buffer&nbsp;to&nbsp;get&nbsp;a&nbsp;MultipolygonShape.&nbsp;&nbsp;Then&nbsp;it&nbsp;does&nbsp;a&nbsp;GetDifference&nbsp;using&nbsp;the&nbsp;orignal&nbsp;polygonShape&nbsp;and&nbsp;the&nbsp;multipolygonShape&nbsp;returned&nbsp;from&nbsp;the&nbsp;lineShape.Buffer.&nbsp;&nbsp;Using&nbsp;this&nbsp;code&nbsp;doesn’t&nbsp;seem&nbsp;to&nbsp;work&nbsp;either&nbsp;as&nbsp;the&nbsp;lineShape.Buffer&nbsp;always&nbsp;returns&nbsp;“null”&nbsp;for&nbsp;the&nbsp;multipolygonShape&nbsp;when&nbsp;I&nbsp;use&nbsp;a&nbsp;distance&nbsp;that&nbsp;is&nbsp;negative.&nbsp;&nbsp;Note&nbsp;it&nbsp;does&nbsp;retrun&nbsp;a&nbsp;valid&nbsp;multipolygonShape&nbsp;when&nbsp;the&nbsp;distance&nbsp;is&nbsp;positive&nbsp;and&nbsp;the&nbsp;sample&nbsp;code&nbsp;as&nbsp;it&nbsp;donwloads&nbsp;is&nbsp;coded&nbsp;with&nbsp;a&nbsp;positive&nbsp;50&nbsp;in&nbsp;DistanceUnit.Meters.  
  
  
  
I&nbsp;found&nbsp;the&nbsp;following&nbsp;note&nbsp;"

You&nbsp;can&nbsp;also&nbsp;pass&nbsp;a&nbsp;negative&nbsp;distance,&nbsp; **Buffer** &nbsp;will&nbsp;then&nbsp;decrease&nbsp;the&nbsp;perimeter&nbsp;of&nbsp;the&nbsp; **BaseShape** &nbsp;in&nbsp;all&nbsp;directions.&nbsp;A&nbsp;negative&nbsp;Distance&nbsp;will&nbsp;work&nbsp;with&nbsp;only&nbsp; **BaseAreaShape** &nbsp;and&nbsp;its&nbsp;derived&nbsp;classes&nbsp;( **Polygon** ,&nbsp; **StraightRectangle** ,&nbsp; **Ellipse** )  
  
on&nbsp;a&nbsp;page&nbsp;for&nbsp;“BaseShape”&nbsp;&nbsp;on&nbsp;the&nbsp;Desktop&nbsp;Edition.  
  
  
  
  
  
Does&nbsp;anyone&nbsp;have&nbsp;any&nbsp;idea&nbsp;what&nbsp;I&nbsp;am&nbsp;doing&nbsp;wrong?&nbsp;&nbsp;&nbsp;Can&nbsp;anyone&nbsp;give&nbsp;me&nbsp;an&nbsp;example&nbsp;that&nbsp;actually&nbsp;uses&nbsp;a&nbsp;negative&nbsp;distance&nbsp;and&nbsp;works?&nbsp;&nbsp;&nbsp;If&nbsp;the&nbsp;note&nbsp;above&nbsp;is&nbsp;correct,&nbsp;&nbsp;then&nbsp;how&nbsp;would&nbsp;the&nbsp;sample&nbsp;work&nbsp;by&nbsp;converting&nbsp;the&nbsp;polygonShape&nbsp;perimeter&nbsp;to&nbsp;a&nbsp;LineShape&nbsp;to&nbsp;do&nbsp;the&nbsp;Buffer&nbsp;when&nbsp;negative&nbsp;distance&nbsp;only&nbsp;works&nbsp;for&nbsp;polygon,&nbsp;StraightRectangle,&nbsp;and&nbsp;Ellipse?  
  
  
  
Thanks&nbsp;for&nbsp;any&nbsp;help&nbsp;you&nbsp;can&nbsp;provide.  
  
  
  
Richard

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [January 31, 2014, 2:18am UTC](https://community.thinkgeo.com/t/negative-buffering-on-a-polygonshape/2338/2 "2014-01-31T02:18:24Z")

</div>

Hi&nbsp;Richard,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;post,&nbsp;I&nbsp;think&nbsp;we&nbsp;don’t&nbsp;support&nbsp;negative&nbsp;buffer&nbsp;render,&nbsp;we&nbsp;do&nbsp;support&nbsp;user&nbsp;input&nbsp;a&nbsp;negative&nbsp;value,&nbsp;but&nbsp;inside&nbsp;the&nbsp;core,&nbsp;we&nbsp;will&nbsp;translate&nbsp;any&nbsp;negative&nbsp;value&nbsp;or&nbsp;value&nbsp;less&nbsp;than&nbsp;0.02&nbsp;to&nbsp;0.02&nbsp;then&nbsp;caculate&nbsp;the&nbsp;buffer&nbsp;shape.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Could&nbsp;you&nbsp;please&nbsp;attach&nbsp;your&nbsp;negative&nbsp;buffer&nbsp;sample&nbsp;here&nbsp;and&nbsp;I&nbsp;can&nbsp;do&nbsp;some&nbsp;test?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know&nbsp;your&nbsp;problems.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary

---

<div class="post-metadata">

**Author:** ![Richard5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/87869e/32.png) [@Richard5](https://community.thinkgeo.com/u/Richard5)\
**Post date:** [February 3, 2014, 9:25am UTC](https://community.thinkgeo.com/t/negative-buffering-on-a-polygonshape/2338/3 "2014-02-03T09:25:21Z")

</div>

Gray,  
  
  
  
Thanks&nbsp;for&nbsp;the&nbsp;quick&nbsp;response.&nbsp;  
  
  
  
The&nbsp;sample&nbsp;code&nbsp;that&nbsp;I&nbsp;would&nbsp;provide&nbsp;is&nbsp;just&nbsp;the&nbsp;code&nbsp;from&nbsp;the&nbsp;MapSuite&nbsp;samples&nbsp;for&nbsp;Negative&nbsp;Buffering.&nbsp;Here&nbsp;it&nbsp;is&nbsp;with&nbsp;a&nbsp;minor&nbsp;changes&nbsp;to&nbsp;test&nbsp;if&nbsp;the&nbsp;Buffer&nbsp;call&nbsp;returns&nbsp;null&nbsp;which&nbsp;was&nbsp;my&nbsp;original&nbsp;error.&nbsp;&nbsp;Since&nbsp;the&nbsp;code&nbsp;was&nbsp;not&nbsp;testing&nbsp;for&nbsp;null&nbsp;it&nbsp;would&nbsp;crash&nbsp;the&nbsp;app&nbsp;on&nbsp;the&nbsp;exception&nbsp;when&nbsp;the&nbsp;MultipolygonShape&nbsp;was&nbsp;null&nbsp;and&nbsp;it&nbsp;tried&nbsp;to&nbsp;do&nbsp;the&nbsp;GetDifference&nbsp;on&nbsp;an&nbsp;object&nbsp;that&nbsp;didn’t&nbsp;exist.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;static&nbsp;MultipolygonShape&nbsp;NegativeBufferPolygon(PolygonShape&nbsp;polygonShape,&nbsp;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GeographyUnit&nbsp;polygonShapeUnit,&nbsp;double&nbsp;distance,&nbsp;DistanceUnit&nbsp;distanceUnit)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;1)&nbsp;Gets&nbsp;the&nbsp;perimeter&nbsp;of&nbsp;the&nbsp;polygon&nbsp;as&nbsp;a&nbsp;LineShape.  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LineShape&nbsp;perimeterLineShape&nbsp;=&nbsp;GetPerimeter(polygonShape);  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;2)&nbsp;Buffers&nbsp;the&nbsp;perimeter&nbsp;by&nbsp;the&nbsp;set&nbsp;distance.  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MultipolygonShape&nbsp;bufferPerimeterMultiPolygonShape&nbsp;=&nbsp;perimeterLineShape.Buffer(  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Math.Abs(distance),&nbsp;polygonShapeUnit,&nbsp;distanceUnit);  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;3)&nbsp;Performs&nbsp;the&nbsp;geometric&nbsp;operation&nbsp;of&nbsp;getting&nbsp;the&nbsp;Difference&nbsp;of&nbsp;the&nbsp;buffered&nbsp;perimeter&nbsp;and&nbsp;the&nbsp;polygon  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//to&nbsp;get&nbsp;the&nbsp;final&nbsp;buffer&nbsp;result.  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MultipolygonShape&nbsp;bufferMultiPolygonShape&nbsp;=&nbsp;null;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(null&nbsp;!=&nbsp;bufferPerimeterMultiPolygonShape)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bufferMultiPolygonShape&nbsp;=&nbsp;polygonShape.GetDifference(bufferPerimeterMultiPolygonShape);  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;bufferMultiPolygonShape;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;///&nbsp;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;///&nbsp;Get&nbsp;the&nbsp;Perimeter&nbsp;of&nbsp;PolygonShape&nbsp;as&nbsp;a&nbsp;LineShape  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;///&nbsp;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;///&nbsp;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;///&nbsp;\<returns\>\</returns\>  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;static&nbsp;LineShape&nbsp;GetPerimeter(PolygonShape&nbsp;polygonShape)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LineShape&nbsp;perimeterLineShape&nbsp;=&nbsp;new&nbsp;LineShape();  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(Vertex&nbsp;vertex&nbsp;in&nbsp;polygonShape.OuterRing.Vertices)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;perimeterLineShape.Vertices.Add(new&nbsp;Vertex(vertex.X,&nbsp;vertex.Y));  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;perimeterLineShape;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
  
  
  
  
  
I&nbsp;believe&nbsp;I&nbsp;have&nbsp;figured&nbsp;it&nbsp;out.&nbsp;&nbsp;This&nbsp;routine&nbsp;always&nbsp;expects&nbsp;the&nbsp;distance&nbsp;as&nbsp;a&nbsp;positve&nbsp;number&nbsp;and&nbsp;only&nbsp;calculates&nbsp;a&nbsp;“Negative&nbsp;Buffer”.&nbsp;&nbsp;It&nbsp;will&nbsp;not&nbsp;work&nbsp;to&nbsp;create&nbsp;a&nbsp;buffer&nbsp;outside/larger&nbsp;than&nbsp;the&nbsp;original&nbsp;polygon.&nbsp;&nbsp;I&nbsp;have&nbsp;to&nbsp;use&nbsp;different&nbsp;code&nbsp;to&nbsp;create&nbsp;the&nbsp;larger/outside&nbsp;polygon&nbsp;buffer&nbsp;(&nbsp;in&nbsp;particular&nbsp;when&nbsp;I&nbsp;need&nbsp;a&nbsp;“Positive”&nbsp;buffer&nbsp;(if&nbsp;that&nbsp;is&nbsp;the&nbsp;correct&nbsp;term),&nbsp;&nbsp;I&nbsp;just&nbsp;use&nbsp;the&nbsp;“polygonShape.Buffer”&nbsp;without&nbsp;doing&nbsp;the&nbsp;GetPerimeter&nbsp;or&nbsp;the&nbsp;GetDifference&nbsp;calls.&nbsp;  
  
  
  
My&nbsp;issue&nbsp;with&nbsp;the&nbsp;sample&nbsp;was&nbsp;that&nbsp;the&nbsp;Buffer&nbsp;and&nbsp;GetDifference&nbsp;will&nbsp;return&nbsp;null&nbsp;for&nbsp;the&nbsp;MultipolygonShape&nbsp;when&nbsp;the&nbsp;distance&nbsp;value&nbsp;will&nbsp;result&nbsp;in&nbsp;“no&nbsp;polygon”.&nbsp;&nbsp;So&nbsp;when&nbsp;the&nbsp;distance&nbsp;specified&nbsp;is&nbsp;large&nbsp;enough&nbsp;that&nbsp;there&nbsp;is&nbsp;no&nbsp;area&nbsp;left&nbsp;inside&nbsp;of&nbsp;the&nbsp;original&nbsp;polygon,&nbsp;the&nbsp;returned&nbsp;Mulitpolygonshape&nbsp;is&nbsp;null.&nbsp;&nbsp;By&nbsp;testing&nbsp;the&nbsp;return&nbsp;values&nbsp;and&nbsp;handling&nbsp;them&nbsp;appropriately&nbsp;(in&nbsp;my&nbsp;code&nbsp;I&nbsp;assume&nbsp;that&nbsp;a&nbsp;null&nbsp;Multipolygonshape&nbsp;means&nbsp;the&nbsp;entire&nbsp;original&nbsp;polygon&nbsp;is&nbsp;included),&nbsp;&nbsp;I&nbsp;have&nbsp;my&nbsp;code&nbsp;working&nbsp;in&nbsp;a&nbsp;reasonable&nbsp;way&nbsp;and&nbsp;producing&nbsp;the&nbsp;“Negative&nbsp;Buffering”&nbsp;shape&nbsp;as&nbsp;well&nbsp;as&nbsp;a&nbsp;“Positive&nbsp;Buffering”&nbsp;shape.&nbsp;  
  
  
  
I&nbsp;hope&nbsp;this&nbsp;might&nbsp;help&nbsp;anyone&nbsp;else&nbsp;who&nbsp;is&nbsp;working&nbsp;with&nbsp;this&nbsp;sample.  
  
  
  
Thanks&nbsp;for&nbsp;the&nbsp;help.  
  
Richard

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [February 3, 2014, 9:58pm UTC](https://community.thinkgeo.com/t/negative-buffering-on-a-polygonshape/2338/4 "2014-02-03T21:58:17Z")

</div>

Hi&nbsp;Richard,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;sharing&nbsp;your&nbsp;experience,&nbsp;that&nbsp;will&nbsp;be&nbsp;helpful!&nbsp;  
&nbsp;&nbsp;  
&nbsp;Anymore&nbsp;queries,&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary
