# Line Buffering Question

**URL:** <https://community.thinkgeo.com/t/line-buffering-question/2213>\
**Category:** WinForms\
**Created:** [April 17, 2013, 11:06am UTC](https://community.thinkgeo.com/t/line-buffering-question/2213 "2013-04-17T11:06:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergei](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/e495f1/32.png) [@Sergei](https://community.thinkgeo.com/u/Sergei)\
**Post date:** [April 17, 2013, 11:06am UTC](https://community.thinkgeo.com/t/line-buffering-question/2213/1 "2013-04-17T11:06:46Z")

</div>

Hi.

I&nbsp;would&nbsp;like&nbsp;to&nbsp;know&nbsp;how&nbsp;buffering&nbsp;is&nbsp;applied&nbsp;to&nbsp;the&nbsp;line&nbsp;shape.

The&nbsp;bounding&nbsp;box&nbsp;height&nbsp;of&nbsp;the&nbsp;buffer&nbsp;result&nbsp;is&nbsp;more&nbsp;(270&nbsp;feet)&nbsp;than&nbsp;expected&nbsp;(200&nbsp;feet)

&nbsp;

`      'Create horizontal line 100 feet long      Dim p1 As New PointShape(-95.606609822483733, 41.805456965812482)      Dim p2 As New PointShape(-95.606609822483733, 41.805456965812482)      p2.TranslateByOffset(100, 0, GeographyUnit.DecimalDegree, DistanceUnit.Feet)      Dim ls As New LineShape      ls.Vertices.Add(New Vertex(p1))      ls.Vertices.Add(New Vertex(p2))      'Check the length of the line = 100.974975459508 - Approximately correct      Console.WriteLine("Length: " & ls.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Feet))      'Apply 100 feet buffer to the line      Dim mps As MultipolygonShape = ls.Buffer(100, GeographyUnit.DecimalDegree, DistanceUnit.Feet)      'Get bounding box from the buffer result      Dim ext As RectangleShape = mps.GetBoundingBox      'Check the width of the bounding box = 302.92317075103 - Approximately correct      ls = New LineShape      ls.Vertices.Add(New Vertex(ext.UpperLeftPoint))      ls.Vertices.Add(New Vertex(ext.UpperRightPoint))      Console.WriteLine("Width: " & ls.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Feet))      'Check the height of the bounding box = 270.923746270921 - Expected +- 200 feet      'Where extra 70.92 feet come from?      ls = New LineShape      ls.Vertices.Add(New Vertex(ext.UpperLeftPoint))      ls.Vertices.Add(New Vertex(ext.LowerLeftPoint))      Console.WriteLine("Height: " & ls.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Feet))`

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [April 19, 2013, 4:34am UTC](https://community.thinkgeo.com/t/line-buffering-question/2213/2 "2013-04-19T04:34:18Z")

</div>

&nbsp;Hi&nbsp;Sergei,&nbsp;

Thanks&nbsp;for&nbsp;your&nbsp;post,&nbsp;the&nbsp;reason&nbsp;for&nbsp;this&nbsp;phenomenon&nbsp;is&nbsp;that&nbsp;both&nbsp;NTS&nbsp;and&nbsp;SqlTypes&nbsp;will&nbsp;buffer&nbsp;by&nbsp;decimal&nbsp;degree,&nbsp;our&nbsp;core&nbsp;will&nbsp;change&nbsp;the&nbsp;100&nbsp;feet&nbsp;distance&nbsp;to&nbsp;decimal&nbsp;degree&nbsp;by&nbsp;using

DecimalDegreeHelper.&nbsp;GetLongitudeDifferenceFromDistance(double&nbsp;distance,&nbsp;DistanceUnit&nbsp;distanceUnit,&nbsp;double&nbsp;latitude).&nbsp;And&nbsp;when&nbsp;latitude&nbsp;is&nbsp;41.805456965812482,&nbsp;100&nbsp;feet&nbsp;longitude&nbsp;line&nbsp;covers&nbsp;more&nbsp;degrees&nbsp;than&nbsp;when&nbsp;latitude&nbsp;is&nbsp;0,&nbsp;so&nbsp;the&nbsp;distance&nbsp;buffered&nbsp;latitude&nbsp;is&nbsp;larger&nbsp;than&nbsp;ecpected.&nbsp;

If&nbsp;you&nbsp;change&nbsp;

&nbsp;&nbsp;&nbsp;Dim&nbsp;p1&nbsp;As&nbsp;New&nbsp;PointShape(-95.606609822483733,&nbsp;41.805456965812482)

&nbsp;&nbsp;&nbsp;Dim&nbsp;p2&nbsp;As&nbsp;New&nbsp;PointShape(-95.606609822483733,&nbsp;41.805456965812482)

To&nbsp;

&nbsp;&nbsp;&nbsp;Dim&nbsp;p1&nbsp;As&nbsp;New&nbsp;PointShape(-95.606609822483733,&nbsp;0)  
&nbsp;&nbsp;&nbsp;Dim&nbsp;p2&nbsp;As&nbsp;New&nbsp;PointShape(-95.606609822483733,&nbsp;0)

You&nbsp;will&nbsp;find&nbsp;out&nbsp;that&nbsp;the&nbsp;height&nbsp;will&nbsp;be&nbsp;about&nbsp;&nbsp;200.

&nbsp;

Hope&nbsp;it&nbsp;helps&nbsp;

Johnny

---

<div class="post-metadata">

**Author:** ![Sergei](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/e495f1/32.png) [@Sergei](https://community.thinkgeo.com/u/Sergei)\
**Post date:** [April 19, 2013, 8:55am UTC](https://community.thinkgeo.com/t/line-buffering-question/2213/3 "2013-04-19T08:55:10Z")

</div>

Johnny,

thank&nbsp;you&nbsp;for&nbsp;response.

Calculating&nbsp;the&nbsp;height&nbsp;has&nbsp;nothing&nbsp;to&nbsp;do&nbsp;with&nbsp;the&nbsp;Y&nbsp;value.

Y&nbsp;can&nbsp;be&nbsp;any&nbsp;decimal&nbsp;degree&nbsp;value&nbsp;and&nbsp;when&nbsp;buffer&nbsp;is&nbsp;applied,&nbsp;height&nbsp;should&nbsp;be&nbsp;the&nbsp;same&nbsp;regardless&nbsp;of&nbsp;Y.

Here&nbsp;is&nbsp;the&nbsp;same&nbsp;example&nbsp;again&nbsp;but&nbsp;this&nbsp;time&nbsp;I'm&nbsp;using&nbsp;Micrsofoft&nbsp;Sql&nbsp;Server&nbsp;STBuffer&nbsp;function&nbsp;and&nbsp;height&nbsp;is&nbsp;correct&nbsp;now.

This&nbsp;is&nbsp;the&nbsp;new&nbsp;output:

&nbsp;

Length:&nbsp;100.974975459508

Width:&nbsp;300.454959392744

Height:&nbsp;200.228274310505

`Imports ThinkGeoImports ThinkGeo.MapSuiteImports ThinkGeo.MapSuite.CoreImports ThinkGeo.MapSuite.DesktopEditionImports Microsoft.SqlServer.TypesImports System.Data.SqlTypes  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load    Try      'Create horizontal line 100 feet long      Dim p1 As New PointShape(-95.606609822483733, 41.805456965812482)      Dim p2 As New PointShape(-95.606609822483733, 41.805456965812482)      p2.TranslateByOffset(100, 0, GeographyUnit.DecimalDegree, DistanceUnit.Feet)      Dim ls As New LineShape      ls.Vertices.Add(New Vertex(p1))      ls.Vertices.Add(New Vertex(p2))      'Check the length of the line = 100.974975459508 - Approximately correct      Console.WriteLine("Length: " & ls.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Feet))      'Apply 100 feet buffer to the line      'Dim mps As MultipolygonShape = ls.Buffer(100, GeographyUnit.DecimalDegree, DistanceUnit.Feet)      Dim ps As PolygonShape = Buffer(100, ls)      'Get bounding box from the buffer result      'Dim ext As RectangleShape = mps.GetBoundingBox      Dim ext As RectangleShape = ps.GetBoundingBox      'Check the width of the bounding box = 302.92317075103 - Approximately correct      ls = New LineShape      ls.Vertices.Add(New Vertex(ext.UpperLeftPoint))      ls.Vertices.Add(New Vertex(ext.UpperRightPoint))      Console.WriteLine("Width: " & ls.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Feet))      'Check the height of the bounding box = 270.923746270921 - Expected +- 200 feet      'Where extra 70.92 feet come from?      ls = New LineShape      ls.Vertices.Add(New Vertex(ext.UpperLeftPoint))      ls.Vertices.Add(New Vertex(ext.LowerLeftPoint))      Console.WriteLine("Height: " & ls.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Feet))  End Sub  Private Function Buffer(feet As Double, ls As ThinkGeo.MapSuite.Core.LineShape) As ThinkGeo.MapSuite.Core.PolygonShape    Dim wkt As String = ls.GetWellKnownText    Dim srid As Integer = 4326    Dim sc As New System.Data.SqlTypes.SqlChars(wkt)    Dim geom As Microsoft.SqlServer.Types.SqlGeometry = Microsoft.SqlServer.Types.SqlGeometry.STGeomFromText(sc, srid)    If Not geom.STIsValid Then      geom = geom.MakeValid      geom = geom.STUnion(geom.STStartPoint)      sc = New System.Data.SqlTypes.SqlChars(geom.ToString)    End If    Dim geog As Microsoft.SqlServer.Types.SqlGeography = Microsoft.SqlServer.Types.SqlGeography.STGeomFromWKB(geom.STAsBinary, srid)    'convert feet to meters    wkt = geog.STBuffer(feet / 3.2808).ToString    Dim bs As ThinkGeo.MapSuite.Core.BaseShape = ThinkGeo.MapSuite.Core.BaseShape.CreateShapeFromWellKnownData(wkt)    Return CType(bs, ThinkGeo.MapSuite.Core.PolygonShape)          End Function`&nbsp;&nbsp;Here&nbsp;is&nbsp;buffer&nbsp;applied&nbsp;to&nbsp;the&nbsp;100x100&nbsp;feet&nbsp;rectangle:

 ![](https://community.thinkgeo.com/uploads/default/original/2X/f/f4166f68732b31a86a18556c7b53eda870843022.png)

---

<div class="post-metadata">

**Author:** ![Edgar](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@Edgar](https://community.thinkgeo.com/u/Edgar)\
**Post date:** [April 22, 2013, 6:14am UTC](https://community.thinkgeo.com/t/line-buffering-question/2213/4 "2013-04-22T06:14:48Z")

</div>

Hi&nbsp;Sergei,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;further&nbsp;information,&nbsp;and&nbsp;I&nbsp;noticed&nbsp;that&nbsp;you&nbsp;are&nbsp;using&nbsp;SqlGeography.STBuffer,&nbsp;but&nbsp;inside&nbsp;our&nbsp;core&nbsp;we&nbsp;are&nbsp;using&nbsp;SqlGeometry.STBuffer,&nbsp;the&nbsp;same&nbsp;result&nbsp;with&nbsp;ours&nbsp;will&nbsp;be&nbsp;found&nbsp;by&nbsp;using&nbsp;the&nbsp;following&nbsp;code:&nbsp;  
&nbsp;geom.STBuffer(DecimalDegreesHelper.GetLongitudeDifferenceFromDistance(100,&nbsp;DistanceUnit.Feet,&nbsp;41.805456965812482)).ToString());&nbsp;  
&nbsp;Instead&nbsp;of&nbsp;&nbsp;  
&nbsp;geog.STBuffer(feet&nbsp;/&nbsp;3.2808).ToString();&nbsp;  
&nbsp;&nbsp;  
&nbsp;If&nbsp;you&nbsp;have&nbsp;any&nbsp;question,&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Hope&nbsp;it&nbsp;helps.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Edgar&nbsp;
