# Not drawing a straight line across the Greenwich meridian

**URL:** <https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764>\
**Category:** WPF\
**Created:** [August 3, 2010, 10:10pm UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764 "2010-08-03T22:10:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [August 3, 2010, 10:10pm UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764/1 "2010-08-03T22:10:46Z")

</div>

&nbsp;Guys,&nbsp;I&nbsp;need&nbsp;to&nbsp;tackle&nbsp;this&nbsp;Greenwich&nbsp;meridian&nbsp;problem&nbsp;where&nbsp;a&nbsp;straight&nbsp;line&nbsp;is&nbsp;drawn&nbsp;across&nbsp;the&nbsp;map&nbsp;projected&nbsp;in&nbsp;EPSG&nbsp;4326.&nbsp;&nbsp;I&nbsp;need&nbsp;to&nbsp;figure&nbsp;out&nbsp;a&nbsp;methodical&nbsp;way&nbsp;to&nbsp;split&nbsp;such&nbsp;a&nbsp;feature&nbsp;taking&nbsp;into&nbsp;consideration&nbsp;the&nbsp;map&nbsp;projection.&nbsp;&nbsp;&nbsp;

For&nbsp;example,&nbsp;if&nbsp;I&nbsp;have&nbsp;a&nbsp;line&nbsp;that&nbsp;goes&nbsp;around&nbsp;the&nbsp;world&nbsp;and&nbsp;my&nbsp;projection&nbsp;is,&nbsp;4326&nbsp;for&nbsp;example,&nbsp;i&nbsp;do&nbsp;not&nbsp;want&nbsp;a&nbsp;straight&nbsp;line&nbsp;across&nbsp;the&nbsp;map.&nbsp;&nbsp;So,&nbsp;I&nbsp;may&nbsp;have&nbsp;to&nbsp;split&nbsp;the&nbsp;line&nbsp;into&nbsp;a&nbsp;multi&nbsp;line....&nbsp;a&nbsp;solution&nbsp;of&nbsp;this&nbsp;nature.

Do&nbsp;you&nbsp;guys&nbsp;already&nbsp;have&nbsp;a&nbsp;way&nbsp;to&nbsp;handle&nbsp;this?&nbsp;&nbsp;I&nbsp;looked&nbsp;at&nbsp;the&nbsp;Proj4Projection&nbsp;class&nbsp;but&nbsp;could&nbsp;determine&nbsp;if&nbsp;any&nbsp;of&nbsp;these&nbsp;methods&nbsp;will&nbsp;do&nbsp;the&nbsp;trick.

Thanks,

Klaus

&nbsp;

&nbsp;

---

<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:** [August 4, 2010, 9:13am UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764/2 "2010-08-04T09:13:23Z")

</div>

I&nbsp;think&nbsp;that&nbsp;what&nbsp;you&nbsp;are&nbsp;describing&nbsp;is&nbsp;similar&nbsp;to&nbsp;the&nbsp;case&nbsp;handled&nbsp;in&nbsp;the&nbsp;Code&nbsp;Community&nbsp;project,&nbsp;_Polygon&nbsp;across&nbsp;Meridian_,&nbsp;[code.thinkgeo.com/projects/show/polygonmeridian](http://code.thinkgeo.com/projects/show/polygonmeridian).&nbsp;Here&nbsp;we&nbsp;split&nbsp;a&nbsp;polygon&nbsp;into&nbsp;a&nbsp;multi&nbsp;polygon,&nbsp;but&nbsp;for&nbsp;a&nbsp;line&nbsp;this&nbsp;is&nbsp;basically&nbsp;the&nbsp;same&nbsp;operation.&nbsp;Let&nbsp;us&nbsp;know&nbsp;if&nbsp;this&nbsp;is&nbsp;not&nbsp;what&nbsp;you&nbsp;are&nbsp;looking&nbsp;for.

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [August 4, 2010, 2:21pm UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764/3 "2010-08-04T14:21:20Z")

</div>

&nbsp;Precisely&nbsp;what&nbsp;I&nbsp;am&nbsp;looking&nbsp;for,&nbsp;thank&nbsp;you.

---

<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:** [August 4, 2010, 3:18pm UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764/4 "2010-08-04T15:18:22Z")

</div>

You&nbsp;are&nbsp;welcome.&nbsp;Let&nbsp;us&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;doubts.

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [August 4, 2010, 9:36pm UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764/5 "2010-08-04T21:36:34Z")

</div>

&nbsp;Did&nbsp;something&nbsp;similar&nbsp;for&nbsp;Lines&nbsp;and&nbsp;this&nbsp;is&nbsp;the&nbsp;method.&nbsp;&nbsp;The&nbsp;tricky&nbsp;part&nbsp;was&nbsp;to&nbsp;constrain&nbsp;the&nbsp;line&nbsp;within&nbsp;the&nbsp;map&nbsp;extent.&nbsp;&nbsp;This&nbsp;is&nbsp;not&nbsp;yet&nbsp;production&nbsp;ready&nbsp;but&nbsp;I&nbsp;just&nbsp;wanted&nbsp;to&nbsp;find&nbsp;out&nbsp;if&nbsp;you&nbsp;guys&nbsp;had&nbsp;a&nbsp;better&nbsp;way&nbsp;to&nbsp;get&nbsp;a&nbsp;line&nbsp;within&nbsp;a&nbsp;given&nbsp;extent.

`   public MultilineShape SplitLine180Meridian(LineShape line)        {            OffsetProjection offsetProjection = new OffsetProjection();            offsetProjection.Open();                 var worldExtent = new RectangleShape(-180, 90, 180, -90);            var westernLineVertices = new Collection<Vertex>();            var easternLineVertices = new Collection<Vertex>();            foreach (Vertex vertex in line.Vertices)            {                if (vertex.X > 0)                {                    westernLineVertices.Add(offsetProjection.ConvertToExternalProjection(vertex.X, vertex.Y));                    easternLineVertices.Add(vertex);                }                else                {                    westernLineVertices.Add(vertex);                    easternLineVertices.Add(offsetProjection.ConvertToInternalProjection(vertex.X, vertex.Y));                }            }            offsetProjection.Close();            var multiLineShape = new MultilineShape();            var westernLine = new LineShape(westernLineVertices);            var easternLine = new LineShape(easternLineVertices);                   	     // suspect....start            var crossingW = worldExtent.GetCrossing(westernLine).Points;             var crossingE = worldExtent.GetCrossing(easternLine).Points;                        var westLine = westernLine.GetLineOnALine(new PointShape( westernLine.Vertices.First()), crossingW.First());            var eastLine = easternLine.GetLineOnALine(crossingE.First(), new PointShape( easternLine.Vertices.Last()));                        var _wl = westLine as LineShape;            var _el = eastLine as LineShape;            // suspect...end                        multiLineShape.Lines.Add(_wl);            multiLineShape.Lines.Add(_el);            return multiLineShape;`

&nbsp;

---

<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:** [August 5, 2010, 3:31pm UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764/6 "2010-08-05T15:31:05Z")

</div>

After&nbsp;doing&nbsp;some&nbsp;investigation,&nbsp;it&nbsp;turns&nbsp;out&nbsp;that&nbsp;the&nbsp;task&nbsp;of&nbsp;splitting&nbsp;line&nbsp;on&nbsp;the&nbsp;180&nbsp;meridian&nbsp;is&nbsp;more&nbsp;complicated&nbsp;than&nbsp;with&nbsp;a&nbsp;polygon&nbsp;because&nbsp;the&nbsp;API&nbsp;GetIntersection&nbsp;lacks&nbsp;the&nbsp;support&nbsp;for&nbsp;line.&nbsp;I&nbsp;asked&nbsp;the&nbsp;develpment&nbsp;if&nbsp;there&nbsp;is&nbsp;another&nbsp;way&nbsp;to&nbsp;accomplish&nbsp;this&nbsp;or&nbsp;if&nbsp;we&nbsp;can&nbsp;relatively&nbsp;easily&nbsp;add&nbsp;the&nbsp;support&nbsp;for&nbsp;line&nbsp;in&nbsp;GetIntersection.&nbsp;In&nbsp;the&nbsp;meantime,&nbsp;I&nbsp;think&nbsp;that&nbsp;you&nbsp;are&nbsp;going&nbsp;to&nbsp;have&nbsp;to&nbsp;content&nbsp;yourself&nbsp;with&nbsp;using&nbsp;a&nbsp;MultilineShape&nbsp;that&nbsp;has&nbsp;the&nbsp;one&nbsp;LineShape&nbsp;for&nbsp;the&nbsp;east&nbsp;side&nbsp;and&nbsp;one&nbsp;LineShape&nbsp;for&nbsp;the&nbsp;west&nbsp;side.&nbsp;See&nbsp;the&nbsp;code&nbsp;below:

`private MultilineShape SplitLineAt180Meridian(LineShape line){        OffsetProjection offsetProjection = new OffsetProjection();    offsetProjection.Open();    LineShape westernLineShape = new LineShape();    LineShape easternLineShape = new LineShape();    foreach (Vertex vertex in line.Vertices)    {        if (vertex.X > 0)        {            westernLineShape.Vertices.Add(offsetProjection.ConvertToExternalProjection(vertex.X, vertex.Y));            easternLineShape.Vertices.Add(vertex);        }        else        {            westernLineShape.Vertices.Add(vertex);            easternLineShape.Vertices.Add(offsetProjection.ConvertToInternalProjection(vertex.X, vertex.Y));        }    }    offsetProjection.Close();    MultilineShape multilineShape = new MultilineShape();    multilineShape.Lines.Add(easternLineShape);    multilineShape.Lines.Add(westernLineShape);        return multilineShape;}`&nbsp;

&nbsp;

So,&nbsp;the&nbsp;result&nbsp;is&nbsp;going&nbsp;to&nbsp;look&nbsp;like&nbsp;the&nbsp;picture&nbsp;below.&nbsp;I&nbsp;hope&nbsp;this&nbsp;is&nbsp;of&nbsp;for&nbsp;you&nbsp;for&nbsp;now:

 ![](https://community.thinkgeo.com/uploads/default/original/2X/4/4c2cf06a8cb5e6c6d30adeb51e53d36fe0b83d91.jpg)

To&nbsp;accomplish&nbsp;the&nbsp;task&nbsp;completely&nbsp;in&nbsp;a&nbsp;way&nbsp;comparable&nbsp;to&nbsp;with&nbsp;a&nbsp;Polygon,&nbsp;we&nbsp;would&nbsp;need&nbsp;the&nbsp;GetIntersection&nbsp;function&nbsp;working&nbsp;as&nbsp;you&nbsp;can&nbsp;see&nbsp;in&nbsp;the&nbsp;picture&nbsp;below:

 ![](https://community.thinkgeo.com/uploads/default/original/2X/a/a38c73cbe886edc614c9625375895629bcc52d22.jpg)

&nbsp;

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [August 5, 2010, 4:13pm UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764/7 "2010-08-05T16:13:55Z")

</div>

&nbsp;Val,&nbsp;thanks&nbsp;for&nbsp;the&nbsp;response.

The&nbsp;section&nbsp;of&nbsp;code&nbsp;where&nbsp;I&nbsp;commented&nbsp;is&nbsp;suspect&nbsp;actually&nbsp;works&nbsp;to&nbsp;constraint&nbsp;the&nbsp;split&nbsp;lines&nbsp;within&nbsp;my&nbsp;map's&nbsp;extent.&nbsp;&nbsp;Initially,&nbsp;I&nbsp;was&nbsp;simply&nbsp;adding&nbsp;the&nbsp;split&nbsp;lines&nbsp;to&nbsp;a&nbsp;MultiLineShape&nbsp;obejct&nbsp;just&nbsp;like&nbsp;you&nbsp;did.&nbsp;&nbsp;But&nbsp;I&nbsp;needed&nbsp;the&nbsp;lines&nbsp;confined&nbsp;within&nbsp;my&nbsp;map&nbsp;extent.

Attached&nbsp;is&nbsp;the&nbsp;picture&nbsp;I&nbsp;get.&nbsp;&nbsp;Red&nbsp;line&nbsp;is&nbsp;original.&nbsp;&nbsp;Green&nbsp;line&nbsp;is&nbsp;actually&nbsp;a&nbsp;blue&nbsp;line&nbsp;but&nbsp;superimposed&nbsp;on&nbsp;original&nbsp;red&nbsp;line.&nbsp;&nbsp;Green&nbsp;segments&nbsp;are&nbsp;my&nbsp;split&nbsp;lines.&nbsp;&nbsp;

What&nbsp;is&nbsp;wrong&nbsp;with&nbsp;the&nbsp;proposed?

&nbsp;

`  var worldExtent = new RectangleShape(-180, 90, 180, -90);            var crossingW = worldExtent.GetCrossing(westernLine).Points;             var crossingE = worldExtent.GetCrossing(easternLine).Points;                        var westLine = westernLine.GetLineOnALine(new PointShape( westernLine.Vertices.First()), crossingW.First());            var eastLine = easternLine.GetLineOnALine(crossingE.First(), new PointShape( easternLine.Vertices.Last()));                        var _wl = westLine as LineShape;            var _el = eastLine as LineShape;                        multiLineShape.Lines.Add(_wl);            multiLineShape.Lines.Add(_el);`

&nbsp;

---

<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:** [August 9, 2010, 12:00pm UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764/8 "2010-08-09T12:00:32Z")

</div>

We&nbsp;don’t&nbsp;see&nbsp;any&nbsp;picture&nbsp;attached.&nbsp;You&nbsp;must&nbsp;have&nbsp;forgotten.&nbsp;It&nbsp;is&nbsp;a&nbsp;little&nbsp;difficult&nbsp;to&nbsp;tell&nbsp;if&nbsp;what&nbsp;you&nbsp;proposed&nbsp;is&nbsp;right&nbsp;without&nbsp;knowing&nbsp;about&nbsp;the&nbsp;line&nbsp;you&nbsp;are&nbsp;doing&nbsp;the&nbsp;operation&nbsp;on.&nbsp;If&nbsp;this&nbsp;is&nbsp;working&nbsp;for&nbsp;you&nbsp;then&nbsp;it&nbsp;must&nbsp;be&nbsp;correct&nbsp;for&nbsp;your&nbsp;cases&nbsp;but&nbsp;keep&nbsp;in&nbsp;mind&nbsp;that&nbsp;this&nbsp;is&nbsp;not&nbsp;going&nbsp;to&nbsp;work&nbsp;with&nbsp;any&nbsp;line.&nbsp;The&nbsp;line&nbsp;has&nbsp;to&nbsp;be&nbsp;in&nbsp;a&nbsp;certain&nbsp;direction,&nbsp;cannot&nbsp;cross&nbsp;multiple&nbsp;time&nbsp;the&nbsp;180&nbsp;degrees&nbsp;meridian&nbsp;etc.&nbsp;To&nbsp;have&nbsp;that&nbsp;operation&nbsp;working&nbsp;in&nbsp;any&nbsp;cases,&nbsp;a&nbsp;GetIntersection&nbsp;function&nbsp;for&nbsp;line&nbsp;would&nbsp;be&nbsp;necessary.&nbsp;We&nbsp;are&nbsp;still&nbsp;looking&nbsp;for&nbsp;an&nbsp;answer&nbsp;from&nbsp;the&nbsp;Development&nbsp;Team&nbsp;to&nbsp;know&nbsp;if&nbsp;we&nbsp;can&nbsp;add&nbsp;this&nbsp;function&nbsp;into&nbsp;our&nbsp;map&nbsp;control.&nbsp;Thank&nbsp;you.

---

<div class="post-metadata">

**Author:** ![Todd4](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/a88e57/32.png) [@Todd4](https://community.thinkgeo.com/u/Todd4)\
**Post date:** [June 26, 2013, 12:20pm UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764/9 "2013-06-26T12:20:44Z")

</div>

Has&nbsp;the&nbsp;GetIntersection&nbsp;gained&nbsp;functionality&nbsp;with&nbsp;lines&nbsp;as&nbsp;of&nbsp;now?&nbsp;It’s&nbsp;been&nbsp;three&nbsp;years&nbsp;so&nbsp;I&nbsp;would&nbsp;like&nbsp;to&nbsp;know&nbsp;if&nbsp;this&nbsp;has&nbsp;changed&nbsp;since&nbsp;Val’s&nbsp;reply.&nbsp;Thanks

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [June 27, 2013, 3:31am UTC](https://community.thinkgeo.com/t/not-drawing-a-straight-line-across-the-greenwich-meridian/2764/10 "2013-06-27T03:31:47Z")

</div>

Hi&nbsp;Todd,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Sorry,&nbsp;it&nbsp;looks&nbsp;we&nbsp;still&nbsp;haven’t&nbsp;the&nbsp;GetIntersection&nbsp;function.&nbsp;  
&nbsp;&nbsp;  
&nbsp;So&nbsp;what’s&nbsp;your&nbsp;scenario&nbsp;now?&nbsp;I&nbsp;think&nbsp;maybe&nbsp;we&nbsp;can&nbsp;try&nbsp;finding&nbsp;some&nbsp;other&nbsp;APIs&nbsp;for&nbsp;your&nbsp;target.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Don
