private static Microsoft.SqlServer.Types.SqlGeometry CreateGeometryPolygon(Esri.ArcGISRuntime.Geometry.Polygon polygon, int cs) { var b = new Microsoft.SqlServer.Types.SqlGeometryBuilder(); b.SetSrid(cs); var rings = Utilities.SplitMultiPolygon(polygon).ToList(); if (rings.Count > 1) { b.BeginGeometry(Microsoft.SqlServer.Types.OpenGisGeometryType.MultiPolygon); } foreach (var outerRing in rings) { b.BeginGeometry(Microsoft.SqlServer.Types.OpenGisGeometryType.Polygon); CreateGeometryFigures(new Esri.ArcGISRuntime.Geometry.ReadOnlyPart[] { outerRing.Item1 }.Union(outerRing.Item2), b, true); b.EndGeometry(); } if (rings.Count > 1) { b.EndGeometry(); } return(b.ConstructedGeometry); }
private static Microsoft.SqlServer.Types.SqlGeometry CreateGeometryLineString(Esri.ArcGISRuntime.Geometry.Polyline polyline, int cs) { var b = new Microsoft.SqlServer.Types.SqlGeometryBuilder(); b.SetSrid(cs); b.BeginGeometry( polyline.Parts.Count <= 1 ? Microsoft.SqlServer.Types.OpenGisGeometryType.LineString : Microsoft.SqlServer.Types.OpenGisGeometryType.MultiLineString); CreateGeometryFigures(polyline.Parts, b, false); b.EndGeometry(); return(b.ConstructedGeometry); }
private static Microsoft.SqlServer.Types.SqlGeometry CreateGeometryPoint(Esri.ArcGISRuntime.Geometry.MapPoint p, int cs) { if (!p.HasZ && !p.HasM) { return(Microsoft.SqlServer.Types.SqlGeometry.Point(p.X, p.Y, cs)); } var b = new Microsoft.SqlServer.Types.SqlGeometryBuilder(); b.SetSrid(cs); b.BeginGeometry(Microsoft.SqlServer.Types.OpenGisGeometryType.Point); b.BeginFigure(p.X, p.Y, p.HasZ ? (double?)p.Z : null, p.HasM ? (double?)p.M : null); b.EndFigure(); b.EndGeometry(); return(b.ConstructedGeometry); }
private static Microsoft.SqlServer.Types.SqlGeometry CreateGeometryMultipoint(Esri.ArcGISRuntime.Geometry.Multipoint multipoint, int cs) { var b = new Microsoft.SqlServer.Types.SqlGeometryBuilder(); b.SetSrid(cs); b.BeginGeometry(Microsoft.SqlServer.Types.OpenGisGeometryType.MultiPoint); foreach (var p in multipoint.Points) { b.BeginGeometry(Microsoft.SqlServer.Types.OpenGisGeometryType.Point); b.BeginFigure(p.X, p.Y, p.HasZ ? (double?)p.Z : null, p.HasM ? (double?)p.M : null); b.EndFigure(); b.EndGeometry(); } b.EndGeometry(); return(b.ConstructedGeometry); }
private static void CreateGeometryFigures(IEnumerable <Esri.ArcGISRuntime.Geometry.ReadOnlyPart> parts, Microsoft.SqlServer.Types.SqlGeometryBuilder b, bool close) { foreach (var part in parts.Select(p => p.Points)) { if (part.Count == 0) { continue; } var p = part[0]; b.BeginFigure(p.X, p.Y, p.HasZ ? (double?)p.Z : null, p.HasM ? (double?)p.M : null); for (int i = 1; i < part.Count; i++) { p = part[i]; b.AddLine(p.X, p.Y, p.HasZ ? (double?)p.Z : null, p.HasM ? (double?)p.M : null); } if (close) { p = part[0]; b.AddLine(p.X, p.Y, p.HasZ ? (double?)p.Z : null, p.HasM ? (double?)p.M : null); } b.EndFigure(); } }