public void ExportNetworkModelGeoToXml(NetworkModelGeo networkModelGeo)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(NetworkModelGeo));

            using (FileStream fileStream = new FileStream(Config.dataGeoPath, FileMode.Create))
            {
                serializer.Serialize(fileStream, networkModelGeo);
            }
        }
Example #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DataHelper      dataHelper      = new DataHelper();
            NetworkModelUTM networkModelUTM = dataHelper.ImportNetworkModelUTMFromXML();
            NetworkModelGeo networkModelGeo = dataHelper.ConvertNetworkModelUTMToGeo(networkModelUTM);

            dataHelper.ExportNetworkModelGeoToXml(networkModelGeo);
            mapNetworkModel = dataHelper.ConvertNetworkModelGeoToMap(networkModelGeo);
            dataHelper.ExportMapNetworkModelToXml(mapNetworkModel);
            Draw3DLines();
            Draw3DPoints();
        }
        public NetworkModelGeo ConvertNetworkModelUTMToGeo(NetworkModelUTM networkModelUTM)
        {
            NetworkModelGeo networkModelGeo = new NetworkModelGeo();

            networkModelGeo.Substations = new SubstationsGeo()
            {
                Substations = new List <SubstationGeo>()
            };

            networkModelUTM.Substations.Substations.ForEach(substationUTM =>
            {
                UTMToLatitudeLongitude(substationUTM.X, substationUTM.Y, out double latitude, out double longitude);

                if (!double.IsNaN(latitude) && !double.IsNaN(longitude))
                {
                    SubstationGeo substationGeo = new SubstationGeo();
                    substationGeo.Id            = substationUTM.Id;
                    substationGeo.Name          = substationUTM.Name;
                    substationGeo.Latitude      = latitude;
                    substationGeo.Longitude     = longitude;

                    networkModelGeo.Substations.Substations.Add(substationGeo);
                }
            });

            networkModelGeo.Nodes = new NodesGeo()
            {
                Nodes = new List <NodeGeo>()
            };

            networkModelUTM.Nodes.Nodes.ForEach(nodeUTM =>
            {
                UTMToLatitudeLongitude(nodeUTM.X, nodeUTM.Y, out double latitude, out double longitude);

                if (!double.IsNaN(latitude) && !double.IsNaN(longitude))
                {
                    NodeGeo nodeGeo   = new NodeGeo();
                    nodeGeo.Id        = nodeUTM.Id;
                    nodeGeo.Name      = nodeUTM.Name;
                    nodeGeo.Latitude  = latitude;
                    nodeGeo.Longitude = longitude;

                    networkModelGeo.Nodes.Nodes.Add(nodeGeo);
                }
            });

            networkModelGeo.Switches = new SwitchesGeo()
            {
                Switches = new List <SwitchGeo>()
            };

            networkModelUTM.Switches.Switches.ForEach(switchUTM =>
            {
                UTMToLatitudeLongitude(switchUTM.X, switchUTM.Y, out double latitude, out double longitude);

                if (!double.IsNaN(latitude) && !double.IsNaN(longitude))
                {
                    SwitchGeo switchGeo = new SwitchGeo();
                    switchGeo.Id        = switchUTM.Id;
                    switchGeo.Name      = switchUTM.Name;
                    switchGeo.Status    = switchUTM.Status;
                    switchGeo.Latitude  = latitude;
                    switchGeo.Longitude = longitude;

                    networkModelGeo.Switches.Switches.Add(switchGeo);
                }
            });

            networkModelGeo.Lines = new LinesGeo()
            {
                Lines = new List <LineGeo>()
            };

            networkModelUTM.Lines.Lines.ForEach(lineUTM =>
            {
                bool isFirstEndSubstation  = networkModelGeo.Substations.Substations.Any(s => s.Id == lineUTM.FirstEnd);
                bool isSecondEndSubstation = networkModelGeo.Substations.Substations.Any(s => s.Id == lineUTM.SecondEnd);
                bool isFirstEndNode        = networkModelGeo.Nodes.Nodes.Any(n => n.Id == lineUTM.FirstEnd);
                bool isSecondEndNode       = networkModelGeo.Nodes.Nodes.Any(n => n.Id == lineUTM.SecondEnd);
                bool isFirstEndSwitch      = networkModelGeo.Switches.Switches.Any(s => s.Id == lineUTM.FirstEnd);
                bool isSecondEndSwitch     = networkModelGeo.Switches.Switches.Any(s => s.Id == lineUTM.SecondEnd);
                bool hasFirstEnd           = isFirstEndSubstation || isFirstEndNode || isFirstEndSwitch;
                bool hasSecondEnd          = isSecondEndSubstation || isSecondEndNode || isSecondEndSwitch;

                if (hasFirstEnd && hasSecondEnd)
                {
                    LineGeo lineGeo  = new LineGeo();
                    lineGeo.Vertices = new VerticesGeo()
                    {
                        Points = new List <PointGeo>()
                    };

                    lineUTM.Vertices.Points.ForEach(pointUTM =>
                    {
                        UTMToLatitudeLongitude(pointUTM.X, pointUTM.Y, out double latitude, out double longitude);

                        if (!double.IsNaN(latitude) && !double.IsNaN(longitude))
                        {
                            PointGeo pointGeo  = new PointGeo();
                            pointGeo.Latitude  = latitude;
                            pointGeo.Longitude = longitude;

                            lineGeo.Vertices.Points.Add(pointGeo);
                        }
                    });

                    if (lineGeo.Vertices.Points.Count >= 2)
                    {
                        lineGeo.Id                  = lineUTM.Id;
                        lineGeo.Name                = lineUTM.Name;
                        lineGeo.IsUnderground       = lineUTM.IsUnderground;
                        lineGeo.R                   = lineUTM.R;
                        lineGeo.ConductorMaterial   = lineUTM.ConductorMaterial;
                        lineGeo.LineType            = lineUTM.LineType;
                        lineGeo.ThermalConstantHeat = lineUTM.ThermalConstantHeat;
                        lineGeo.FirstEnd            = lineUTM.FirstEnd;
                        lineGeo.SecondEnd           = lineUTM.SecondEnd;

                        networkModelGeo.Lines.Lines.Add(lineGeo);
                    }
                }
            });

            return(networkModelGeo);
        }
        public MapNetworkModel ConvertNetworkModelGeoToMap(NetworkModelGeo networkModelGeo)
        {
            MapNetworkModel mapNetworkModel = new MapNetworkModel();

            mapNetworkModel.Points = new List <MapPoint>();

            networkModelGeo.Substations.Substations.ForEach(substationGeo =>
            {
                MapPoint mapPoint    = new MapPoint();
                mapPoint.Id          = substationGeo.Id;
                mapPoint.Description = substationGeo.Name;
                mapPoint.Type        = PointType.Substation;

                LatitudeLongitudeToPixels(substationGeo.Latitude, substationGeo.Longitude, out double x, out double y);
                mapPoint.X = x;
                mapPoint.Y = y;

                mapPoint.Connections = new List <long>();

                networkModelGeo.Lines.Lines.ForEach(lineGeo =>
                {
                    if (lineGeo.FirstEnd == mapPoint.Id || lineGeo.SecondEnd == mapPoint.Id)
                    {
                        mapPoint.Connections.Add(lineGeo.Id);
                    }
                });

                mapNetworkModel.Points.Add(mapPoint);
            });

            networkModelGeo.Nodes.Nodes.ForEach(nodeGeo =>
            {
                MapPoint mapPoint    = new MapPoint();
                mapPoint.Id          = nodeGeo.Id;
                mapPoint.Description = nodeGeo.Name;
                mapPoint.Type        = PointType.Node;

                LatitudeLongitudeToPixels(nodeGeo.Latitude, nodeGeo.Longitude, out double x, out double y);
                mapPoint.X = x;
                mapPoint.Y = y;

                mapPoint.Connections = new List <long>();

                networkModelGeo.Lines.Lines.ForEach(lineGeo =>
                {
                    if (lineGeo.FirstEnd == mapPoint.Id || lineGeo.SecondEnd == mapPoint.Id)
                    {
                        mapPoint.Connections.Add(lineGeo.Id);
                    }
                });

                mapNetworkModel.Points.Add(mapPoint);
            });

            networkModelGeo.Switches.Switches.ForEach(switchGeo =>
            {
                MapPoint mapPoint    = new MapPoint();
                mapPoint.Id          = switchGeo.Id;
                mapPoint.Description = switchGeo.Name;
                mapPoint.Type        = PointType.Switch;

                LatitudeLongitudeToPixels(switchGeo.Latitude, switchGeo.Longitude, out double x, out double y);
                mapPoint.X = x;
                mapPoint.Y = y;

                mapPoint.Connections = new List <long>();

                networkModelGeo.Lines.Lines.ForEach(lineGeo =>
                {
                    if (lineGeo.FirstEnd == mapPoint.Id || lineGeo.SecondEnd == mapPoint.Id)
                    {
                        mapPoint.Connections.Add(lineGeo.Id);
                    }
                });

                mapNetworkModel.Points.Add(mapPoint);
            });

            mapNetworkModel.Lines = new List <MapLine>();

            networkModelGeo.Lines.Lines.ForEach(lineGeo =>
            {
                MapLine mapLine     = new MapLine();
                mapLine.Id          = lineGeo.Id;
                mapLine.Description = lineGeo.Name;

                mapLine.Points = new List <MapPoint>();

                MapPoint firstMapPoint = mapNetworkModel.Points.Find(p => p.Id == lineGeo.FirstEnd);
                mapLine.Points.Add(firstMapPoint);

                lineGeo.Vertices.Points.ForEach(pointGeo =>
                {
                    LatitudeLongitudeToPixels(pointGeo.Latitude, pointGeo.Longitude, out double x, out double y);

                    MapPoint mapPoint = mapNetworkModel.Points.FirstOrDefault(p => p.X == x && p.Y == y);

                    if (mapPoint == null)
                    {
                        mapPoint             = new MapPoint();
                        mapPoint.Id          = 0;
                        mapPoint.Description = lineGeo.Name + "_connector";
                        mapPoint.Type        = PointType.Connector;
                        mapPoint.X           = x;
                        mapPoint.Y           = y;

                        mapNetworkModel.Points.Add(mapPoint);
                    }

                    mapLine.Points.Add(mapPoint);
                });

                MapPoint secondMapPoint = mapNetworkModel.Points.Find(p => p.Id == lineGeo.SecondEnd);
                mapLine.Points.Add(secondMapPoint);

                mapNetworkModel.Lines.Add(mapLine);
            });

            return(mapNetworkModel);
        }