コード例 #1
0
        public static void SaveGPSData(List <GpsPointData> points, int filterIndex, string fileName)
        {
            string     ext        = Path.GetExtension(fileName);
            ExportType exportType = (ExportType)Enum.Parse(typeof(ExportType), ext.Trim('.'));

            if (filterIndex == 3)//(exportType == ExportType.gpx)
            {
                List <Waypoint> list = new List <Waypoint>();
                foreach (GpsPointData i in points)
                {
                    list.Add(new Waypoint(i));
                }

                GpxV2 v2 = new GpxV2();
                v2.waypoints = list.ToArray();
                string xml = SerializeToString(v2);
                File.WriteAllText(fileName, xml);
            }
            else if (filterIndex == 2) //simple KML (exportType == ExportType.kml)
            {
                kml kml = new kml();
                kml.SaveToFile(points, fileName);
            }
            else if (filterIndex == 1) //extended KML (exportType == ExportType.kml)
            {
                GPSDataParser.FileFormats.KML.KmlEx kml = new GPSDataParser.FileFormats.KML.KmlEx();
                kml.SaveToFile(points, fileName);
            }
        }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        //start at zero
        placemark_index = 0;

        //load kml data
        serializer = new XmlSerializer(typeof(kml));
        stream     = new FileStream(bandung, FileMode.Open);
        container  = (kml)serializer.Deserialize(stream);
        stream.Close();
    }
コード例 #3
0
ファイル: ApsoilKML.aspx.cs プロジェクト: rafatahmed/APSoil
        /// <summary>
        /// Return the inital KMZ as requested by the apsim.info web site.
        /// </summary>
        private byte[] MyDataKMZ()
        {
            kml KmlContainer = new kml();

            Document KmlDoc = new Document();

            KmlDoc.Name.Text            = "APSoil characterised soils";
            KmlDoc.Snippet.Text         = "Fully characterised soil sites for use with APSIM and Yield Prophet.";
            KmlDoc.Description.UseCDATA = true;
            KmlDoc.Description.Text     = "<p>The soil sites displayed are from APSoil</p>";
            KmlContainer.Documents.Add(KmlDoc);

            NetworkLink KmlNetworkLink = new NetworkLink("APSoil soils", "All characterised soils");

            KmlNetworkLink.Link.Href.Text         = ourPath + "/ApsoilKML.aspx?Mode=1";
            KmlNetworkLink.Link.RefreshMode.Value = refreshModeEnum.onExpire;
            KmlDoc.Features.NetworkLinks.Add(KmlNetworkLink);

            return(KmlContainer.GetKMZ("APSRU_Sites.kml"));
        }
コード例 #4
0
ファイル: KMLHelper.cs プロジェクト: emitsakis/glosa-mobile
        public static IList <kmlDocumentPlacemark> LoadPlacemarksFromFile(string file)
        {
            var list     = new List <kmlDocumentPlacemark>();
            var assembly = typeof(KMLHelper).GetTypeInfo().Assembly;

            Stream stream = assembly.GetManifestResourceStream(file);

            if (stream != null)
            {
                XmlSerializer          serializer = new XmlSerializer(typeof(kml));
                kml                    kml        = serializer.Deserialize(stream) as kml;
                kmlDocumentPlacemark[] placemark  = kml.Document.Placemark;
                list.AddRange(placemark);
            }
            else
            {
                throw new FileNotFoundException("Could not find file", file);
            }

            return(list);
        }
コード例 #5
0
ファイル: Main.xaml.cs プロジェクト: codingsf/loosoft
        private void SaveConfig()
        {
            if (Regex.IsMatch(tbxheight.Text, "^\\d+$") == false)
            {
                MessageBox.Show("高度只能是数字格式");
                return;
            }
            if (Regex.IsMatch(tbxtipsinterval.Text, "^\\d+$") == false)
            {
                MessageBox.Show("气泡显示时长只能是数字格式");
                return;
            }

            if (Regex.IsMatch(tbxdetailinterval.Text, "^\\d+$") == false)
            {
                MessageBox.Show("详细页面显示时长只能是数字格式");
                return;
            }
            if (Regex.IsMatch(tbxmainpageinterval.Text, "^\\d+$") == false)
            {
                MessageBox.Show("首页停留时间只能是数字格式");
                return;
            }
            if (Regex.IsMatch(incomeRate.Text, "^\\d+\\.\\d+$") == false)
            {
                MessageBox.Show("收益转化率只能是小数");
                return;
            }
            List <CheckBox> cboxes = findCheckBox(this.displayItems, true);

            if (cboxes.Count < 4)
            {
                MessageBox.Show("至少需要选择4个首页汇总项目");
                return;
            }
            if (cboxes.Count > 5)
            {
                MessageBox.Show("最多不能超过5个显示首页汇总项目");
                return;
            }

            if (string.IsNullOrEmpty(tboxhyc.Text) == false)
            {
                FileUtil.WriteFile(Environment.CurrentDirectory, "text.txt", string.Format("hyc={0}", tboxhyc.Text));
            }

            config.langInfo     = string.Format("{0}-{1}", cbxMasterLanguage.SelectedValue, cbxLanguage.SelectedValue);
            config.MainInterval = tbxmainpageinterval.Text;
            config.domain       = tboxDomain.Text;
            config.CounterType  = cbxCounterType.SelectedIndex;
            config.currencyType = cbxCurrencyType.SelectedIndex;
            config.CounterUser  = tbxUserName.Text;
            string displayItems = string.Empty;

            foreach (CheckBox cbox in cboxes)
            {
                displayItems += string.Format("{0}|", Array.FindIndex(ConfigPara.displayItemsName.ToArray(), i => i.Equals(cbox.Name)));
            }
            config.displayItems = displayItems;
            displayItems        = string.Empty;
            cboxes = findCheckBox(displayPages, true);
            if (cboxes.Count < 1)
            {
                MessageBox.Show("至少需要选择1个电站子页面");
                return;
            }
            foreach (CheckBox cbox in cboxes)
            {
                displayItems += string.Format("{0}|", Array.FindIndex(ConfigPara.displayPageName.ToArray(), i => i.Equals(cbox.Name)));
            }
            config.displayPages = displayItems;//显示页面配置
            decimal rate = 0;

            decimal.TryParse(incomeRate.Text, out rate);
            config.incomeRate = rate;
            foreach (PlantInfoVo plantInfoVo in config.PlantsInfo)
            {
                if (!config.height.Equals(tbxheight.Text))
                {
                    plantInfoVo.height = tbxheight.Text;
                }
                if (!config.TipsInterval.Equals(tbxtipsinterval.Text))
                {
                    plantInfoVo.tipInterval = tbxtipsinterval.Text;
                }
                if (!config.DetailInterval.Equals(tbxdetailinterval.Text))
                {
                    plantInfoVo.detailInterval = tbxdetailinterval.Text;
                }
            }

            config.height         = tbxheight.Text;
            config.TipsInterval   = tbxtipsinterval.Text;
            config.DetailInterval = tbxdetailinterval.Text;
            if (config.CounterType == ConfigPara.currentUser)
            {
                if (string.IsNullOrEmpty(config.CounterUser))
                {
                    MessageBox.Show("请输入用户名!");
                    tbxUserName.Focus();
                    return;
                }
            }

            config.sysname = tboxSysname.Text;

            // if (selected == 0)
            {
                //展示电站列表
                List <PlantInfoVo> checkedPlants = new List <PlantInfoVo>();
                //
                //List<PlantInfoVo> allPlants = new List<PlantInfoVo>();
                //foreach (UIElement c in plantsList.Children)
                //{
                //    if (c is CheckBox)
                //    {
                //        CheckBox cbox = c as CheckBox;
                //        PlantInfoVo tempVo = config.PlantsInfo.Single(model => string.Format("pid_{0}", model.plantId).Equals(cbox.Name));
                //        tempVo.Longitude = double.Parse(findTextBox(string.Format("tboxlong_{0}", tempVo.plantId)));
                //        tempVo.latitude = double.Parse(findTextBox(string.Format("tboxlat_{0}", tempVo.plantId)));
                //        tempVo.height = findTextBox(string.Format("tboxhei_{0}", tempVo.plantId));
                //        tempVo.design_power = findTextBox(string.Format("tboxdesignpower_{0}", tempVo.plantId));
                //        tempVo.detailInterval = findTextBox(string.Format("tboxdetailtime_{0}", tempVo.plantId));
                //        tempVo.tipInterval = findTextBox(string.Format("tboxtiptime_{0}", tempVo.plantId));
                //        if (cbox.IsChecked == true)
                //        {
                //            checkedPlants.Add(tempVo);
                //        }
                //        allPlants.Add(tempVo);
                //    }

                //}

                string[] pidArray = addPids.Split('|');
                foreach (string pid in pidArray)
                {
                    if (string.IsNullOrEmpty(pid))
                    {
                        continue;
                    }
                    checkedPlants.Add(config.PlantsInfo.FirstOrDefault(p => p.plantId.Equals(pid)));
                }
                config.TipsPlantsInfo = checkedPlants;
                //config.PlantsInfo = allPlants;
            }

            //if (selected == 1)
            //{
            //自动演示电站列表
            //List<PlantInfoVo> tipscheckedPlants = new List<PlantInfoVo>();
            //for (int x = 0; x < tipsplantsList.Children.Count; x++)
            //{
            //    if (tipsplantsList.Children[x] is CheckBox)
            //    {
            //        CheckBox check = tipsplantsList.Children[x] as CheckBox;
            //        if (check.IsChecked == true)
            //        {
            //            tipscheckedPlants.Add(pvos.Single(model => string.Format("pid_{0}", model.plantId).Equals(check.Name)));
            //        }
            //    }
            //}
            //config.TipsPlantsInfo = tipscheckedPlants;
            //  }

            //保存配置的电站到 KML 文件 plant.kml

            kml kml = new kml();
            List <GroundOverlay> groundoverlaies = new List <GroundOverlay>();

            foreach (PlantInfoVo piv in config.PlantsInfo)
            {
                String desc = "";
                if (config.TipsPlantsInfo != null && config.TipsPlantsInfo.Contains(piv))
                {
                    desc = "<font size=4>装机容量:" + piv.design_power + " kW</font><hr><font size=4>" + "城市:" + piv.city + "</font><br/><font size=4>国家:" + piv.country + "</font><hr><a href='http://localhost:8111/web?plantId=" + piv.plantId + "' target='_self'><font size=4>点击查看详细信息</font></a>";
                }
                else
                {
                    desc = "<font size=4>装机容量:" + piv.design_power + " kW</font><hr><font size=4>" + "城市:" + piv.city + "</font><br/><font size=4>国家:" + piv.country + "</font><hr>";
                }
                kml.Document.Add(new Placemark(piv.plantName, desc, "#globeIcon", "1", new Placemark.KMLPoint(piv.latitude, piv.Longitude, "1", "relativeToGround"), new Placemark.LookAt()
                {
                    altitude = "0", heading = "137.6356988109601", latitude = "-152.6659616588421", longitude = "-152.6659616588421", range = "334944.723968608", tilt = "42.37613018389006"
                }));
                //kml.Document.Add(new Placemark(piv.plantName + "-1", desc, "#globeIcon1", "1", new Placemark.KMLPoint(piv.latitude, piv.Longitude, "1", "relativeToGround"), new Placemark.LookAt() { altitude = "0", heading = "137.6356988109601", latitude = "-152.6659616588421", longitude = "-152.6659616588421", range = "334944.723968608", tilt = "42.37613018389006" }));
                //kml.Document.Add(new Placemark(piv.plantName + "-2", desc, "#globeIcon2", "0", new Placemark.KMLPoint(piv.latitude, piv.Longitude, "1", "relativeToGround"), new Placemark.LookAt() { altitude = "0", heading = "137.6356988109601", latitude = "-152.6659616588421", longitude = "-152.6659616588421", range = "334944.723968608", tilt = "42.37613018389006" }));
                groundoverlaies.Add(new GroundOverlay
                {
                    name       = piv.plantName + "overlay",
                    icon       = config.domain + "/demoimg/3x.png",
                    visibility = "0",
                    LatLonBox  = new GroundOverlay.LatLonBx {
                        east = piv.Longitude - 1.5, rotation = 160, north = piv.latitude - 1.5, south = piv.latitude + 1.5, west = piv.Longitude + 1.5
                    },
                    LookAt = new GroundOverlay.Look
                    {
                        altitude  = "1",
                        heading   = "124",
                        latitude  = "1",
                        longitude = "1",
                        range     = "",
                        tilt      = ""
                    }
                });

                groundoverlaies.Add(new GroundOverlay
                {
                    name       = piv.plantName + "overlay-1",
                    icon       = config.domain + "/demoimg/3x-1.png",
                    visibility = "0",
                    LatLonBox  = new GroundOverlay.LatLonBx {
                        east = piv.Longitude - 1.5, rotation = 160, north = piv.latitude - 1.5, south = piv.latitude + 1.5, west = piv.Longitude + 1.5
                    },
                    LookAt = new GroundOverlay.Look
                    {
                        altitude  = "1",
                        heading   = "124",
                        latitude  = "1",
                        longitude = "1",
                        range     = "",
                        tilt      = ""
                    }
                });
            }
            kml.SaveToFile("plant.kml", groundoverlaies, config.domain);
            //config.MainInterval = this.tboxMainPage.Text;
            //config.DetailInterval = this.tboxDetailPage.Text;
            XMLHelper.SerializerXML <ConfigPara>(System.Environment.CurrentDirectory + "\\config.xml", config);
            MessageBox.Show("参数保存成功", "系统提示", MessageBoxButton.OK);
        }
コード例 #6
0
ファイル: ApsoilKML.aspx.cs プロジェクト: rafatahmed/APSoil
        /// <summary>
        /// This is called directly by Google Earth when it wants KML data.
        /// </summary>
        private byte[] NetworkLinkData()
        {
            kml      KmlContent = new kml();
            Document KmlDoc     = new Document("Test", "");

            KmlContent.Documents.Add(KmlDoc);

            KML_22_Beta1.Style APSRUIcon = new KML_22_Beta1.Style();
            APSRUIcon.IconStyle.Icon.Href.Text = "http://apsimdev.apsim.info/ApsoilWeb/shovel.png";
            APSRUIcon.IconStyle.Scale.Value    = 0.7;
            APSRUIcon.LabelStyle.Scale.Value   = 0.7;
            APSRUIcon.id = "APSRUIconID";
            KmlDoc.StyleSelector.Style.Add(APSRUIcon);

            Dictionary <string, Folder> Folders = new Dictionary <string, Folder>();

            ApsoilWeb.Service SoilsDB = new Apsoil.ApsoilWeb.Service();
            foreach (string Name in SoilsDB.AllSoilNames(false))
            {
                string FolderName = Name;
                if (FolderName.Contains("/"))
                {
                    FolderName = FolderName.Substring(0, FolderName.LastIndexOf('/'));
                }

                Soil Soil = Soil.Create(SoilsDB.SoilXML(Name));
                if (Soil != null)
                {
                    string BalloonDescription = "<p><b>" + Soil.Name + "</b></p><p><i>"
                                                + Soil.Comments + "</i></p>";

                    string DataSourceComments = Soil.DataSource;
                    if (DataSourceComments != null && DataSourceComments != "")
                    {
                        BalloonDescription += "<p><i>Data source: " + DataSourceComments + "</i></p>";
                    }

                    BalloonDescription += "<img src=\"" + ourPath + "SoilChart.aspx?Name=" + Name + "\"/>";

                    BalloonDescription += "<p><a href=\"" + ourPath + "GetSoil.aspx?Name=" + Name + "\">Download soil in APSIM format (copy and paste contents to your simulation).</a></p>";
                    BalloonDescription += "<p><a name=\"link_id\" id=\"link_id\"  href=\"Download.html\" onclick=\"window.open('" + ourPath + "Excel.aspx?Name=" + Name + "');\">Download soil as an EXCEL spreadsheet</a></p>";

                    string SoilName = Soil.Name;
                    if (Soil.ApsoilNumber != "")
                    {
                        SoilName = Soil.ApsoilNumber;
                    }
                    Placemark plmMyPlaceMark = new Placemark(SoilName,
                                                             BalloonDescription,
                                                             Soil.Latitude,
                                                             Soil.Longitude,
                                                             0, altitudeModeEnum.clampToGround);
                    plmMyPlaceMark.Description.UseCDATA = true;
                    plmMyPlaceMark.Description.Text     = BalloonDescription;
                    plmMyPlaceMark.StyleUrl.Text        = "#APSRUIconID";

                    Folder F = GetFolder(FolderName, Folders, KmlDoc);
                    F.Features.Placemarks.Add(plmMyPlaceMark);
                }
            }

            KmlContent.NetworkLinkControl.Expires.Value        = DateTime.Now.AddDays(7);
            KmlContent.NetworkLinkControl.LinkDescription.Text = "Characterised sites - " + DateTime.Now.ToString("dd MMM yyyy HH:mm:ss");
            return(KmlContent.GetKMZ("NetworkData.kml"));
        }