private static Microsoft.SqlServer.Types.SqlGeography CreateGeographyPolygon(Esri.ArcGISRuntime.Geometry.Polygon polygon, int cs)
        {
            var b = new Microsoft.SqlServer.Types.SqlGeographyBuilder();

            b.SetSrid(cs);

            var rings = Utilities.SplitMultiPolygon(polygon).ToList();

            if (rings.Count > 1)
            {
                b.BeginGeography(Microsoft.SqlServer.Types.OpenGisGeographyType.MultiPolygon);
            }

            foreach (var outerRing in rings)
            {
                b.BeginGeography(Microsoft.SqlServer.Types.OpenGisGeographyType.Polygon);
                CreateGeographyFigures(new Esri.ArcGISRuntime.Geometry.ReadOnlyPart[] { outerRing.Item1 }.Union(outerRing.Item2), b, true);
                b.EndGeography();
            }

            if (rings.Count > 1)
            {
                b.EndGeography();
            }
            return(b.ConstructedGeography);
        }
        private static Microsoft.SqlServer.Types.SqlGeography CreateGeographyLineString(Esri.ArcGISRuntime.Geometry.Polyline polyline, int cs)
        {
            var b = new Microsoft.SqlServer.Types.SqlGeographyBuilder();

            b.SetSrid(cs);
            b.BeginGeography(
                polyline.Parts.Count <= 1 ?
                Microsoft.SqlServer.Types.OpenGisGeographyType.LineString :
                Microsoft.SqlServer.Types.OpenGisGeographyType.MultiLineString);

            CreateGeographyFigures(polyline.Parts, b, false);

            b.EndGeography();
            return(b.ConstructedGeography);
        }
        private static Microsoft.SqlServer.Types.SqlGeography CreateGeographyPoint(Esri.ArcGISRuntime.Geometry.MapPoint p, int cs)
        {
            if (!p.HasZ && !p.HasM)
            {
                return(Microsoft.SqlServer.Types.SqlGeography.Point(p.Y, p.X, cs));
            }

            var b = new Microsoft.SqlServer.Types.SqlGeographyBuilder();

            b.SetSrid(cs);
            b.BeginGeography(Microsoft.SqlServer.Types.OpenGisGeographyType.Point);
            b.BeginFigure(p.Y, p.X, p.HasZ ? (double?)p.Z : null,
                          p.HasM ? (double?)p.M : null);
            b.EndFigure();
            b.EndGeography();
            return(b.ConstructedGeography);
        }
        private static Microsoft.SqlServer.Types.SqlGeography CreateGeographyMultipoint(Esri.ArcGISRuntime.Geometry.Multipoint multipoint, int cs)
        {
            var b = new Microsoft.SqlServer.Types.SqlGeographyBuilder();

            b.SetSrid(cs);
            b.BeginGeography(Microsoft.SqlServer.Types.OpenGisGeographyType.MultiPoint);

            foreach (var p in multipoint.Points)
            {
                b.BeginGeography(Microsoft.SqlServer.Types.OpenGisGeographyType.Point);
                b.BeginFigure(p.Y, p.X,
                              p.HasZ ? (double?)p.Z : null,
                              p.HasM ? (double?)p.M : null);
                b.EndFigure();
                b.EndGeography();
            }
            b.EndGeography();
            return(b.ConstructedGeography);
        }
 private static void CreateGeographyFigures(IEnumerable <Esri.ArcGISRuntime.Geometry.ReadOnlyPart> parts,
                                            Microsoft.SqlServer.Types.SqlGeographyBuilder b, bool close)
 {
     foreach (var part in parts)
     {
         if (part.Count == 0)
         {
             continue;
         }
         var p = part.Points[0];
         b.BeginFigure(p.Y, p.X, p.HasZ ? (double?)p.Z : null, p.HasM ? (double?)p.M : null);
         for (int i = 1; i < part.Count; i++)
         {
             p = part.Points[i];
             b.AddLine(p.Y, p.X, p.HasZ ? (double?)p.Z : null, p.HasM ? (double?)p.M : null);
         }
         if (close)
         {
             p = part.Points[0];
             b.AddLine(p.X, p.Y, p.HasZ ? (double?)p.Z : null, p.HasM ? (double?)p.M : null);
         }
         b.EndFigure();
     }
 }