Help using NormalizeCentralMeridian (or spanning the antimeridian)

86
0
08-18-2022 02:53 PM
MattH
by
New Contributor II

 

I'm trying to display some geometries that span the antimeridian in a WPF app. Ultimately, the geometries will be pulled from a map service, but I have a simple rectangle polygon that I'm testing with. This seems to be a pretty common issue, and I've read through all of the examples that I could find. Most of the examples I've seen are using the JS API, and I'm having trouble getting the same results in the .Net SDK.

The working JS example here (https://codepen.io/andygup/pen/QeyerP) appears to call geodesicUtils.geodesicDensify() to resolve the issue. I didn't see any reference to NormalizeCentralMeridian() in this example, like I've seen in other examples. Porting that to .Net didn't work, though.

This example converts to WebMercator then uses NormalizeCentralMeridian() (https://jsbin.com/xegicih/2/edit?html,output), but again is in JS.

This post (https://community.esri.com/t5/arcgis-runtime-sdk-for-net-questions/polyline-not-crossing-internation...) is in .Net and suggested adding 360 to the negative western longitudes. Doing this will put a box in the correct place, but with an extra line at 180 degrees. The JS examples don't have this issue.

Can the .Net SDK display a geometry the same way as the JS examples?

Here is a sample of the code I've been working with:

 

private void addGraphic(Geometry.Geometry geometry)
  {
    SimpleLineSymbol outlineSymbol = 
      new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.Green, 2);
    Geometry.PointCollection points = 
      new Geometry.PointCollection(SpatialReferences.Wgs84)
      {
        new MapPoint(-178, -5),
        new MapPoint(-178, 5),
        new MapPoint(178, 5),
        new MapPoint(178, -5)
      };

      Polygon polygon = new Polygon(points);
      Geometry.Geometry g = GeometryEngine.NormalizeCentralMeridian(polygon);
      esriMap.SetViewpointGeometryAsync(g, 50);

      Graphic graphic = new Graphic(g, outlineSymbol);
      _overlay.Graphics.Add(graphic);
 }

 

 

Here's how I tried adding 360 to the longitudes. That got me a bit closer, but still not what I was looking for:

private void addGraphic(Geometry.Geometry geometry)
  {
    SimpleLineSymbol outlineSymbol = 
      new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.Green, 2);
    Geometry.PointCollection points = 
      new Geometry.PointCollection(SpatialReferences.Wgs84)
      {
        new MapPoint(-178, -5),
        new MapPoint(-178, 5),
        new MapPoint(178, 5),
        new MapPoint(178, -5)
      };

      Polygon polygon = new Polygon(points);
      Polygon newPoly;
      Geometry.PointCollection newPoints = 
        new Geometry.PointCollection(SpatialReferences.Wgs84);
      
      foreach (ReadOnlyPart gp in polygon.Parts)
      {
        foreach (MapPoint pt in gp.Points)
          {
            double x = pt.X;
            if(x<0){ x += 360; }
            newPoints.Add(new MapPoint(x, pt.Y));
          } 
       }
            newPoly = new Polygon(newPoints);
            //this puts a box in the correct place, 
            //but has an extra vertical line at 180
            esriMap.SetViewpointGeometryAsync(newPoly.Extent, 50);
            Graphic graphic = new Graphic(newPoly, outlineSymbol);
            _overlay.Graphics.Add(graphic);
}

 

0 Kudos
0 Replies