${IS6_ServerGeometry_Title}

${IS6_ServerGeometry_Description}

 /// <summary>${IS6_ServerGeometry_method_FromJson_D}</summary>
 /// <param name="jsonObject">${IS6_ServerGeometry_method_FromJson_param_jsonObject}</param>
 /// <returns>${IS6_ServerGeometry_method_FromJson_return}</returns>
 public static ServerGeometry FromJson(JsonObject jsonObject)
 {
     if (jsonObject == null)
     {
         return null;
     }
     ServerGeometry geometry = new ServerGeometry();
     geometry.Feature = (ServerFeatureType)(int)jsonObject["feature"];
     geometry.ID = (int)jsonObject["id"];
     JsonArray parts = (JsonArray)jsonObject["parts"];
     if (parts != null && parts.Count > 0)
     {
         geometry.Parts = new List<int>();
         for (int i = 0; i < parts.Count; i++)
         {
             geometry.Parts.Add((int)parts[i]);
         }
     }
     JsonArray point2Ds = (JsonArray)jsonObject["points"];
     if (point2Ds != null && point2Ds.Count > 0)
     {
         geometry.Point2Ds = new Point2DCollection();
         for (int i = 0; i < point2Ds.Count; i++)
         {
             geometry.Point2Ds.Add(JsonHelper.ToPoint2D((JsonObject)point2Ds[i]));
         }
     }
     return geometry;
 }
        internal static string ToJson(ServerGeometry serverGeometry)
        {
            if (serverGeometry == null)
            {
                return null;
            }

            string json = "{";
            List<string> list = new List<string>();

            list.Add(string.Format("\"feature\":{0}", (int)serverGeometry.Feature));
            list.Add(string.Format("\"id\":{0}", serverGeometry.ID));

            if (serverGeometry.Parts != null && serverGeometry.Parts.Count > 0)
            {
                List<string> parts = new List<string>();
                foreach (int i in serverGeometry.Parts)
                {
                    parts.Add(i.ToString());
                }
                list.Add(string.Format("\"parts\":[{0}]", string.Join(",", parts.ToArray())));
            }
            else
            {
                list.Add(string.Format("\"parts\":[]"));
            }
            if (serverGeometry.Point2Ds != null && serverGeometry.Point2Ds.Count > 0)
            {
                List<string> ps = new List<string>();
                foreach (Point2D p in serverGeometry.Point2Ds)
                {
                    ps.Add(JsonHelper.FromPoint2D(p));
                }
                list.Add(string.Format("\"points\":[{0}]", string.Join(",", ps.ToArray())));
            }
            else
            {
                list.Add(string.Format("\"points\":null"));
            }
            json += string.Join(",", list.ToArray());
            json += "}";
            return json;
        }
Ejemplo n.º 3
0
        /// <summary>${IS6_Utility_method_GeometryToServerGeometry_D}</summary>
        /// <returns>${IS6_Utility_method_GeometryToServerGeometry_return}</returns>
        /// <param name="geo">${IS6_Utility_method_GeometryToServerGeometry_param_geo}</param>
        public static ServerGeometry ToServerGeometry(this Geometry geo)
        {
            if (geo == null)
            {
                return null;
            }

            ServerGeometry sg = new ServerGeometry();

            Point2DCollection list = new Point2DCollection();
            List<int> parts = new List<int>();

            if (geo is GeoRegion)
            {
                for (int i = 0; i < ((GeoRegion)geo).Parts.Count; i++)
                {
                    for (int j = 0; j < ((GeoRegion)geo).Parts[i].Count; j++)
                    {
                        list.Add(new Point2D(((GeoRegion)geo).Parts[i][j].X, ((GeoRegion)geo).Parts[i][j].Y));
                    }
                    parts.Add(((GeoRegion)geo).Parts[i].Count);
                }
                sg.Feature = ServerFeatureType.Polygon;
            }

            if (geo is GeoCircle)
            {
                for (int i = 0; i < ((GeoCircle)geo).Parts.Count; i++)
                {
                    for (int j = 0; j < ((GeoCircle)geo).Parts[i].Count; j++)
                    {
                        list.Add(new Point2D(((GeoCircle)geo).Parts[i][j].X, ((GeoCircle)geo).Parts[i][j].Y));
                    }
                    parts.Add(((GeoCircle)geo).Parts[i].Count);
                }
                sg.Feature = ServerFeatureType.Polygon;
            }

            if (geo is GeoLine)
            {
                for (int i = 0; i < ((GeoLine)geo).Parts.Count; i++)
                {
                    for (int j = 0; j < ((GeoLine)geo).Parts[i].Count; j++)
                    {
                        list.Add(new Point2D(((GeoLine)geo).Parts[i][j].X, ((GeoLine)geo).Parts[i][j].Y));
                    }
                    parts.Add(((GeoLine)geo).Parts[i].Count);
                }
                sg.Feature = ServerFeatureType.Line;
            }

            if (geo is GeoPoint)
            {
                list.Add(new Point2D(((GeoPoint)geo).X, ((GeoPoint)geo).Y));
                parts.Add(list.Count);
                sg.Feature = ServerFeatureType.Point;
            }

            sg.Point2Ds = list;
            sg.Parts = parts;
            sg.ID = -1;
            return sg;
        }