Polyline not crossing international Dateline

1517
4
Jump to solution
07-22-2019 11:10 AM
AlanFlythe
New Contributor II

Hello,

I have a simple WPF .NET application using the v100.5 ESRI ArcGISRuntime that creates a polyline with two points, one in San Diego, California, the other in Kwajalein Atoll on an ESRI basemap. The lat/longs are entered in WGS84. I found this article 

https://community.esri.com/thread/118744 and tried that solution but the line never crosses the International Dateline, instead it takes the long way around the world (See attached PNG). Here is the code:

using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using System;
using System.Windows;
using System.Windows.Controls;

namespace ESRI_Test
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
// Graphics overlay to display the graphics.
private GraphicsOverlay _graphicsOverlay;
private Graphic _countryBorderPolylineGraphic;

public MainWindow()
{
InitializeComponent();
// Create a map with a topographic basemap.
Map newMap = new Map(BasemapType.DarkGrayCanvasVector, 21.339723, -157.945774, 2);

// Assign the map to the MapView.
MyMapView.Map = newMap;
var test = newMap.SpatialReference;

// Create a graphics overlay to hold the various graphics.
_graphicsOverlay = new GraphicsOverlay();

// Add the created graphics overlay to the MapView.
MyMapView.GraphicsOverlays.Add(_graphicsOverlay);


// Add the map points to the point collection.
PointCollection newborderCountryPointCollection = new PointCollection(SpatialReferences.WebMercator)
{
(MapPoint)GeometryEngine.NormalizeCentralMeridian((MapPoint) GeometryEngine.Project(new MapPoint(-157.945774, 21.339723, SpatialReferences.Wgs84), SpatialReferences.WebMercator)),
(MapPoint)GeometryEngine.NormalizeCentralMeridian((MapPoint) GeometryEngine.Project(new MapPoint(167.726017, 8.719545, SpatialReferences.Wgs84), SpatialReferences.WebMercator))
};

// Create a polyline geometry from the point collection.
Polyline newborderCountryPolyline = new Polyline(newborderCountryPointCollection);

// Create a simple line symbol
SimpleLineSymbol newcountryBorderSimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dot, System.Drawing.Color.Blue, 5);

// Create the graphic - comprised of a polyline shape and line symbol.
Graphic _newcountryBorderPolylineGraphic = new Graphic(newborderCountryPolyline, newcountryBorderSimpleLineSymbol);
_graphicsOverlay.Graphics.Add(_newcountryBorderPolylineGraphic);
}
}
}

Any thoughts what I am missing? Or doing wrong?

Thanks in advance for the help

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

You need to enter longitudes that are outside the -180 to 180 range.

If your point locations are normalized between -180 and 180 longitude (which they probably will be), add 360 if you're crossing the date line heading east, or subtract 360 if you're crossing the dateline heading west.

So, in your example above instead of specifying a line from -157.945774, 21.339723 to 167.726017, 8.719545 (which is a long eastward line), you want to specify a line from -157.945774, 21.339723 to -192.273983 (i.e. 167.726017 - 360), 8.719545 (which is a shorter westward line).

Similarly, if your direction of travel were reversed you'd have a line from 167.726017, 8.719545 to 202.054226, 21.339723.

Does that help?

View solution in original post

0 Kudos
4 Replies
Nicholas-Furness
Esri Regular Contributor

You need to enter longitudes that are outside the -180 to 180 range.

If your point locations are normalized between -180 and 180 longitude (which they probably will be), add 360 if you're crossing the date line heading east, or subtract 360 if you're crossing the dateline heading west.

So, in your example above instead of specifying a line from -157.945774, 21.339723 to 167.726017, 8.719545 (which is a long eastward line), you want to specify a line from -157.945774, 21.339723 to -192.273983 (i.e. 167.726017 - 360), 8.719545 (which is a shorter westward line).

Similarly, if your direction of travel were reversed you'd have a line from 167.726017, 8.719545 to 202.054226, 21.339723.

Does that help?

0 Kudos
AlanFlythe
New Contributor II

So that does fix it for the WPF .NET  app (See the blue line below)

However, in another application, using the ESRI Javascript API v4.12, that we are doing that had the same problem, your fix stops drawing the line at the International dateline.

I know this is the .NET forum so I can post this question in the Javascript forum, I was just curious why this would work with .NET and not with Javascript.

Thanks for your help.

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Hmm. It does surprise me a little, although nuanced differences between Runtime and JS API are to be expected.

I would ask the question in their space (https://community.esri.com/discussion/create.jspa?containerType=14&containerID=2128) and reference your comment above. Sorry I can't provide more info!

0 Kudos
AlanFlythe
New Contributor II

Thanks for the help Nicholas.

Anyone that wants to know about the Javascript solution, here is the link https://community.esri.com/message/866160-polyline-not-crossing-the-international-dateline

0 Kudos