Example #1
0
        static void Main(string[] args)
        {
            String  inFile  = @"C:\tmp\Test\Ferrocarril Belgrano.kml";
            String  outFile = @"C:\tmp\Test\out.kml";
            KmlFile kmlFile = null;

            using (Stream fileStream = File.OpenRead(inFile))
            {
                kmlFile = KmlFile.Load(fileStream);
            }
            Kml      kml = kmlFile.Root as Kml;
            Document d   = kml.Feature as Document;
            Folder   f   = (Folder)d.Features.FirstOrDefault();
            Folder   f2  = (Folder)f.Features.FirstOrDefault();

            Document doc = new Document();

            doc.Name = "MyTestKml";
            d.Schemas.ToList().ForEach(s => doc.AddSchema(s.Clone()));
            doc.AddFeature(f2.Clone());

            // This allows us to save and Element easily.
            KmlFile kmlOut = KmlFile.Create(doc, false);

            using (var stream = System.IO.File.OpenWrite(outFile))
            {
                kmlOut.Save(stream);
            }
        }
Example #2
0
        /// <summary>
        /// Compiles regions with locations, merging the peakbagger and base sets of formations from *.csv files.
        /// </summary>
        /// <param name="filePathRegionsKml">The file path to the KML file containing the regions.</param>
        /// <param name="filePathCsv">The file path to the *.csv file containing the base formation sets.</param>
        /// <param name="filePathPeakbaggerCsvSource">The file path to the master peakbagger *.csv file.</param>
        /// <param name="filePathPeakbaggerCsv">The file path to the filtered peakbagger *.csv file.</param>
        /// <returns>Regions.</returns>
        public static Region CollateLocationsFromCsv(string filePathRegionsKml,
                                                     string filePathCsv,
                                                     string filePathPeakbaggerCsvSource,
                                                     string filePathPeakbaggerCsv = "")
        {
            // Get regions
            Region regions = Kml.ReadRegions(filePathRegionsKml);

            // Add database locations
            List <FormationMatcher> locations = GetFormationsFromCsv(filePathCsv);

            regions.AddFormationsByRegionName(locations);

            // Get peakbagger locations
            bool             potentialLocationsAreSaved = !string.IsNullOrWhiteSpace(filePathPeakbaggerCsv);
            List <Formation> locationsPeakbagger        = potentialLocationsAreSaved
                ? GetPeakbaggerFormationsFromCsvFiltered(filePathPeakbaggerCsv)
                : GetPeakbaggerFormationsFromCsvOriginal(filePathPeakbaggerCsvSource, new Extents(regions.Extents), saveToCsv: true);

            regions.AddFormationsByCoordinates(locationsPeakbagger);

            // Add locations to the appropriate region
            foreach (Region region in regions)
            {
                region.MergeFormations();
                region.CondensePotentialMatches();
            }

            return(regions);
        }
Example #3
0
        // 鼠标左键按下
        private void gmapControl_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && !gmapControl.CanDragMap)//空格按下后漫游
            {
                var lngLat = gmapControl.FromLocalToLatLng(e.X, e.Y);
                centerPoint.Lng = lngLat.Lng;
                centerPoint.Lat = lngLat.Lat;
                Kml kml = new Kml();
                kml.Placemark.Name = "draw_circle" + Utils.ElementIndex;

                KmlCircle circleKml = new KmlCircle();
                circleKml.FillColor      = Color.FromArgb(50, Color.Blue);
                circleKml.Position       = new MapLngLat(lngLat.Lng, lngLat.Lat);
                circleKml.RandomPosition = circleKml.Position;
                circleKml.Radius         = 0;
                circleKml.StrokeColor    = Color.Gray;
                circleKml.StrokeWidth    = 2;
                kml.Placemark.Graph      = circleKml;
                IMFElement element = null;
                drawn         = layer.AddElement(kml, out element);
                circleElement = element as IMFCircle;

                gmapControl.MouseMove += gmapControl_MouseMove;
                gmapControl.MouseUp   += gmapControl_MouseUp;
            }
        }
Example #4
0
        /// <summary>
        /// 创建图元
        /// </summary>
        /// <param name="kml"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public IMFElement CreateElement(Kml kml, ILayer layer)
        {
            KmlText textKml = kml.Placemark.Graph as KmlText;

            if (textKml == null)
            {
                return(null);
            }
            if (textKml.Position == null)
            {
                return(null);
            }

            int index = -1;

            //图层
            IGlobeGraphicsLayer graphicsLayer = layer as IGlobeGraphicsLayer;

            MapFrame.ArcGlobe.Element.Text_ArcGlobe textElement = null;
            this.Dosomething((Action) delegate()
            {
                //图元
                textElement = new MapFrame.ArcGlobe.Element.Text_ArcGlobe(graphicsLayer, textKml);
                GlobeGraphicsElementPropertiesClass properties = new GlobeGraphicsElementPropertiesClass();
                properties.Rasterize = textKml.Rasterize;
                graphicsLayer.AddElement(textElement, properties, out index);
                textElement.Index       = index; //指定索引
                textElement.ElementName = kml.Placemark.Name;
            }, true);

            return(textElement);
        }
Example #5
0
        private static Kml NewGxKml()
        {
            Kml kml = new Kml();

            kml.AddNamespacePrefix(KmlNamespaces.GX22Prefix, KmlNamespaces.GX22Namespace);
            return(kml);
        }
Example #6
0
        private string StringOf(Kml kml)
        {
            Serializer serializer = new Serializer();

            serializer.Serialize(kml);
            return(serializer.Xml);
        }
Example #7
0
        public string GetMultiTrackKml()
        {
            trackNo = trackNo + 1;
            Kml      kml             = NewGxKml();
            Document updatedDocument = GetUpdatedDocument();

            if (trackNo == 1)
            {
                kml.Feature = updatedDocument;
                return(StringOf(kml));
            }

            CreateCollection createCollection = new CreateCollection();

            createCollection.Add(updatedDocument);

            Update update = new Update();

            update.AddUpdate(createCollection);

            NetworkLinkControl networkLinkControl = new NetworkLinkControl();

            networkLinkControl.Cookie = $"seq={lastSeq}";
            networkLinkControl.Update = update;

            kml.NetworkLinkControl = networkLinkControl;
            return(StringOf(kml));
        }
Example #8
0
        /// <summary>
        /// 鼠标左键双击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void mapControl_eventLButtonDbClick(object sender, _DHOSOFTMapControlEvents_eventLButtonDbClickEvent e)
        {
            if (!isControl && listPoints.Count > 2)
            {
                if (!string.IsNullOrEmpty(tempName))
                {
                    mapControl.MgsDelObject(tempName);
                }

                Kml        kml     = new Kml();
                KmlPolygon polygon = new KmlPolygon();
                polygon.PositionList = listPoints;
                polygon.FillColor    = Color.FromArgb(0, Color.White);
                polygon.OutLineColor = Color.Red;
                polygon.OutLineSize  = 3;
                kml.Placemark.Name   = "mgis_polygon" + Utils.ElementIndex;
                kml.Placemark.Graph  = polygon;
                IMFElement element = null;
                layer.AddElement(kml, out element);
                polygonElement = element as IMFPolygon;
                RegistCommondExecutedEvent();
                ReleaseCommond();//修改  陈静
                isFinish = true;
                listPoints.Clear();
            }
        }
Example #9
0
 /// <summary>
 /// 鼠标按下开始绘制
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void mapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
 {
     if (e.button == 1 && !isControl)
     {
         MapLngLat lngLat = new MapLngLat(e.mapX, e.mapY);
         if (listMapPoints.Count == 0)
         {
             listMapPoints.Add(lngLat);
             Kml kml = new Kml();
             kml.Placemark.Name = "arc_Polygon" + Utils.ElementIndex;
             Color outlineColor = Color.Blue;
             Color fillColor    = Color.Black;
             kml.Placemark.Graph = new KmlPolygon()
             {
                 FillColor = fillColor, OutLineColor = outlineColor, OutLineSize = 1, PositionList = listMapPoints
             };
             IMFElement element = null;
             layer.AddElement(kml, out element);
             polygonElement = element as IMFPolygon;
             isFinish       = false;//为不完成状态
         }
         else if (listMapPoints.Find(p => p.Lng == e.mapX && p.Lat == e.mapY) == null)
         {
             listMapPoints.Add(lngLat);
         }
     }
 }
Example #10
0
        private static string DoCell(H3Index h3, H3ToGeoBoundaryArguments argParser)
        {
            var sb = new StringBuilder();
            var gb = h3.ToGeoBoundary();

            if (argParser.Kml)
            {
                string name = string.IsNullOrEmpty(argParser.KmlName)
                                  ? "H3 Geometry"
                                  : argParser.KmlDescription;
                string desc = string.IsNullOrEmpty(argParser.KmlDescription)
                                  ? "Generated by h3ToGeoBoundary"
                                  : argParser.KmlDescription;

                sb.Append(Kml.PtsHeader(name, desc));
                sb.Append(Kml.OutputBoundaryKML(gb, h3.ToString()));
                sb.Append(Kml.PtsFooter());
            }
            else
            {
                sb.AppendLine(h3.ToString());
                sb.Append(Utility.GeoBoundaryPrintLines(gb));
            }

            return(sb.ToString());
        }
Example #11
0
        private static string DoCell(H3Index h3, H3ToGeoArguments argParser)
        {
            var sb = new StringBuilder();
            var gc = h3.ToGeoCoord();

            if (argParser.Kml)
            {
                string name = string.IsNullOrEmpty(argParser.KmlName)
                                  ? "H3 Geometry"
                                  : argParser.KmlDescription;
                string desc = string.IsNullOrEmpty(argParser.KmlDescription)
                                  ? "Generated by h3ToGeo"
                                  : argParser.KmlDescription;

                sb.Append(Kml.PtsHeader(name, desc));
                sb.Append(Kml.OutputPointKml(gc, h3.ToString()));
                sb.Append(Kml.PtsFooter());
            }
            else
            {
                sb.Append($"{gc.Latitude.RadiansToDegrees(),10:f8}, {gc.Longitude.RadiansToDegrees(),10:f8}");
            }

            return(sb.ToString());
        }
Example #12
0
        /// <summary>
        /// 创建图元
        /// </summary>
        /// <param name="kml">图元的kml</param>
        /// <param name="layer">图元所在的图层</param>
        /// <returns></returns>
        public IMFElement CreateElement(Kml kml, ILayer layer)
        {
            KmlPolygon polygonKml = kml.Placemark.Graph as KmlPolygon;

            if (polygonKml == null)
            {
                return(null);
            }
            if (polygonKml.PositionList == null)
            {
                return(null);
            }

            int index = -1;
            Polygon_ArcGlobe polygonElement = null;

            this.Dosomething((Action) delegate()
            {
                //图层
                IGlobeGraphicsLayer graphicsLayer = layer as IGlobeGraphicsLayer;
                //实例化图元
                polygonElement = new Polygon_ArcGlobe(graphicsLayer, polygonKml);

                //设置属性
                GlobeGraphicsElementPropertiesClass properties = new GlobeGraphicsElementPropertiesClass();
                properties.Rasterize = polygonKml.Rasterize;
                graphicsLayer.AddElement(polygonElement, properties, out index);
                polygonElement.Index       = index;                                 //指定索引
                polygonElement.ElementName = kml.Placemark.Name;
            }, true);

            return(polygonElement);
        }
Example #13
0
        /// <summary>
        /// 鼠标按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mapControl_OnMouseDown(object sender, IGlobeControlEvents_OnMouseDownEvent e)
        {
            if (e.button != 1)
            {
                return;
            }
            MapLngLat lnglat = this.SceneToGeographyPoint(e.x, e.y);

            if (kml == null)
            {
                kml = new Kml();
                kml.Placemark.Name    = "绘制圆" + Utils.Index;
                circleKml             = new KmlCircle();
                circleKml.Description = "手动绘制的圆";
                circleKml.FillColor   = Color.FromArgb(70, Color.Orange);
                circleKml.StrokeColor = Color.FromArgb(70, Color.Red);
                circleKml.StrokeWidth = 2;
                circleKml.Rasterize   = true;
                circleKml.Position    = lnglat;
            }
            else
            {
                circleKml.RandomPosition = lnglat;
                drawn = layer.AddElement(kml, out circleElement);
            }
        }
Example #14
0
        /// <summary>
        /// 创建线图元
        /// </summary>
        /// <param name="kml">kml对象</param>
        /// <param name="gmapOverlay">图层</param>
        /// <returns></returns>
        public IMFElement CreateElement(Kml kml, GMapOverlay gmapOverlay)
        {
            KmlLineString line = kml.Placemark.Graph as KmlLineString;

            if (line == null)
            {
                return(null);
            }
            if (line.PositionList == null || line.PositionList.Count == 0)
            {
                return(null);
            }

            // 画线
            Line_GMap lineRoute = new Line_GMap(kml.Placemark.Name, line);

            // 将图元添加到图层
            if (gmapOverlay.Control.InvokeRequired)
            {
                gmapOverlay.Control.Invoke(new Action(delegate
                {
                    gmapOverlay.Routes.Add(lineRoute);
                }));
            }
            else
            {
                gmapOverlay.Routes.Add(lineRoute);
            }
            return(lineRoute);
        }
Example #15
0
        public ActionResult Upload()
        {
            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    var kmzFile   = KmzFile.Open(file.InputStream);
                    var kmlString = kmzFile.ReadKml();

                    Parser parser = new Parser();
                    parser.ParseString(kmlString, false);

                    Kml kml    = parser.Root as Kml;
                    var places = new Dictionary <string, Place>();

                    ExtractPlaces(kml.Feature as Feature, "", places);

                    var placeRepository = new OrmLitePlaceRepository(ApplicationManager.OpenConnection());

                    foreach (var place in places.Values)
                    {
                        place.UsageLevel = PlaceUsageLevel.Public;
                        placeRepository.Add(place);
                    }
                }
            }

            return(View("Import"));
        }
Example #16
0
        public static void Run()
        {
            KmlFile file = Program.OpenFile("Enter a file to show the placemarks of:");

            if (file == null)
            {
                return;
            }

            // It's good practice for the root element of the file to be a Kml element
            Kml kml = file.Root as Kml;

            if (kml != null)
            {
                List <Placemark> placemarks = new List <Placemark>();
                ExtractPlacemarks(kml.Feature, placemarks);

                // Sort using their names
                placemarks.Sort((a, b) => string.Compare(a.Name, b.Name));

                // Display the results
                foreach (var placemark in placemarks)
                {
                    Console.WriteLine(placemark.Name);
                }
            }
        }
Example #17
0
        /// <summary>
        /// 左键弹起
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void mapControl_eventLButtonUp(object sender, _DHOSOFTMapControlEvents_eventLButtonUpEvent e)
        {
            //if (!isShift)
            //{
            //    isFinish = true;
            //    isMouseDown = false;
            //    RegistCommondExecutedEvent();
            //}

            if (!isControl)
            {
                if (!string.IsNullOrEmpty(tempName))
                {
                    mapControl.MgsDelObject(tempName);
                }
                Kml       kml    = new Kml();
                KmlCircle circle = new KmlCircle();
                kml.Placemark.Name    = "mgis_circle" + Utils.ElementIndex;
                circle.Position       = centerPoint;
                circle.RandomPosition = new MapLngLat(e.dLong, e.dLat);
                circle.StrokeColor    = System.Drawing.Color.Red;
                circle.FillColor      = System.Drawing.Color.FromArgb(0, System.Drawing.Color.White);
                circle.StrokeWidth    = 3;
                kml.Placemark.Graph   = circle;
                IMFElement element = null;
                layer.AddElement(kml, out element);
                circleElement = element as IMFCircle;
                RegistCommondExecutedEvent();
                ReleaseCommond();//修改  陈静
                isFinish    = true;
                isMouseDown = false;
            }
        }
Example #18
0
        /// <summary>
        /// 添加图元
        /// </summary>
        /// <param name="kml"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public IMFElement CreateElement(Kml kml, ILayer layer)
        {
            KmlCircle circleKml = kml.Placemark.Graph as KmlCircle;

            if (circleKml.Position == null)
            {
                return(null);
            }

            int             index         = -1;
            Circle_ArcGlobe circleElement = null;

            this.Dosomething((Action) delegate()
            {
                //图元
                IGlobeGraphicsLayer graphicsLayer = layer as IGlobeGraphicsLayer;

                circleElement = new Circle_ArcGlobe(graphicsLayer, circleKml);
                IGlobeGraphicsElementProperties properties = new GlobeGraphicsElementPropertiesClass();
                properties.Rasterize = circleKml.Rasterize;
                graphicsLayer.AddElement(circleElement, properties, out index);
                circleElement.Index       = index;
                circleElement.ElementName = kml.Placemark.Name;
            }, true);

            return(circleElement);
        }
Example #19
0
 /// <summary>
 /// 鼠标左键双击
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void mapControl_eventLButtonDbClick(object sender, _DHOSOFTMapControlEvents_eventLButtonDbClickEvent e)
 {
     if (!isControl && listPoints.Count >= 2)
     {
         if (!string.IsNullOrEmpty(tempName))
         {
             mapControl.MgsDelObject(tempName);
         }
         //if (listPoints.Count < 2) return;
         Kml           kml  = new Kml();
         KmlLineString line = new KmlLineString();
         line.PositionList   = listPoints;
         line.Color          = System.Drawing.Color.Red;
         line.Width          = 3;
         kml.Placemark.Name  = "mgis_line" + Utils.ElementIndex;
         kml.Placemark.Graph = line;
         IMFElement element = null;
         layer.AddElement(kml, out element);
         lineElement = element as IMFLine;
         RegistCommondExecutedEvent();
         ReleaseCommond();//修改  陈静
         listPoints.Clear();
         isFinish = true;
     }
 }
        private static void ProcessDelete(DeleteCollection delete, KmlFile file)
        {
            foreach (var source in delete)
            {
                if (source.TargetId != null)
                {
                    Feature feature = file.FindObject(source.TargetId) as Feature;
                    if (feature != null)
                    {
                        // Remove the Feature from the parent, which is either
                        // a Container or Kml
                        Container container = feature.Parent as Container;
                        if (container != null)
                        {
                            container.RemoveFeature(source.TargetId);
                        }
                        else
                        {
                            Kml kml = feature.Parent as Kml;
                            if (kml != null)
                            {
                                kml.Feature = null;
                            }
                        }

                        // Also remove it from the file
                        file.RemoveFeature(feature);
                    }
                }
            }
        }
Example #21
0
        /// <summary>
        /// 鼠标弹起结束绘制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void mapControl_eventLButtonUp(object sender, _DHOSOFTMapControlEvents_eventLButtonUpEvent e)
        {
            if (!isControl)
            {
                MapLngLat p1 = new MapLngLat(e.dLong, listPoints[0].Lat);
                MapLngLat p2 = new MapLngLat(e.dLong, e.dLat);
                MapLngLat p3 = new MapLngLat(listPoints[0].Lng, e.dLat);
                listPoints.Add(p1);
                listPoints.Add(p2);
                listPoints.Add(p3);

                if (!string.IsNullOrEmpty(tempName))
                {
                    mapControl.MgsDelObject(tempName);
                }
                Kml        kml       = new Kml();
                KmlPolygon rectangle = new KmlPolygon();
                kml.Placemark.Name     = "mgis_rec" + Utils.ElementIndex;
                rectangle.PositionList = listPoints;
                rectangle.FillColor    = System.Drawing.Color.FromArgb(0, System.Drawing.Color.White);
                rectangle.OutLineColor = System.Drawing.Color.Red;
                rectangle.OutLineSize  = 3;
                kml.Placemark.Graph    = rectangle;
                IMFElement element = null;
                layer.AddElement(kml, out element);
                recElement = element as IMFPolygon;

                RegistCommondExecutedEvent();
                ReleaseCommond();//修改  陈静
                isFinish = true;
                listPoints.Clear();
            }
        }
Example #22
0
        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            string[] files = openFileDialog1.FileNames;

            Manifold.Interop.History logger = doc.Application.History;



            foreach (string str in files)
            {
                if (KmlFile(str))
                {
                    Kml kml = new Kml(str);
                    try
                    {
                        kml.Import(doc);
                    }
                    catch (Exception ex)
                    {
                        logger.Log(ex.Message + "\n", null);
                    }
                }
            }
            openFileDialog1.Dispose();
        }
Example #23
0
        /// <summary>
        /// 创建文字图元
        /// </summary>
        /// <param name="kml">kml对象</param>
        /// <param name="gmapOverlay">图层</param>
        /// <returns></returns>
        public IMFElement CreateElement(Kml kml, GMapOverlay gmapOverlay)
        {
            KmlText text = kml.Placemark.Graph as KmlText;

            if (text == null)
            {
                return(null);
            }
            if (text.Position == null)
            {
                return(null);
            }

            PointLatLng p = new PointLatLng(text.Position.Lat, text.Position.Lng);

            Text_GMap element = new Text_GMap(p, text, kml.Placemark.Name);

            // 添加图元到图层
            if (gmapOverlay.Control.InvokeRequired)
            {
                gmapOverlay.Control.Invoke(new Action(delegate
                {
                    gmapOverlay.Markers.Add(element);
                }));
            }
            else
            {
                gmapOverlay.Markers.Add(element);
            }

            return(element);
        }
Example #24
0
        /// <summary>
        /// 鼠标按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (e.button == 1 && !isControl)
            {
                downPoint = new MapLngLat(e.mapX, e.mapY);
                if (listMapPoints.Count == 0)
                {
                    listMapPoints.Add(downPoint);

                    Kml kmlLine = new Kml();
                    kmlLine.Placemark.Name = "arc_line" + Utils.ElementIndex;

                    KmlLineString line = new KmlLineString();
                    line.PositionList       = listMapPoints;
                    line.Color              = Color.Gray;
                    line.Width              = 2;
                    kmlLine.Placemark.Graph = line;
                    IMFElement element = null;
                    layer.AddElement(kmlLine, out element);
                    lineElement = element as IMFLine;//绘制完成后得到该图元
                    isFinish    = false;
                }
                //若重复点击同一个点则不添加
                else if (listMapPoints.Find(p => p.Lng == downPoint.Lng && p.Lat == downPoint.Lat) == null)
                {
                    listMapPoints.Add(downPoint);
                }
            }
        }
Example #25
0
        public void TestLegacyKml()
        {
            const string Xml =
                "<kml xmlns=\"http://earth.google.com/kml/2.2\">" +
                "<Placemark>" +
                "<name>My Placemark</name>" +
                "</Placemark>" +
                "</kml>";

            var parser = new Parser();

            parser.ParseString(Xml, false);

            Kml root = parser.Root as Kml;

            Assert.That(root, Is.Not.Null);

            // Make sure it didn't add the old namespace
            Assert.That(root.GetNamespaces(), Has.No.ContainKey(string.Empty));

            // Make sure it serializes
            Serializer serializer = new Serializer();

            Assert.That(() => serializer.Serialize(root), Throws.Nothing);
            Assert.That(serializer.Xml, Is.Not.Null.Or.Empty);
        }
Example #26
0
        public void TestSerialize()
        {
            const string Expected =
                "<kml xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns=\"http://www.opengis.net/kml/2.2\">" +
                "<Document>" +
                "<atom:author>" +
                "<atom:name>Name</atom:name>" +
                "</atom:author>" +
                "<atom:link href=\"http://www.example.com/\" />" +
                "</Document>" +
                "</kml>";

            Document document = new Document();

            document.AtomAuthor = new Author {
                Name = "Name"
            };
            document.AtomLink = new SharpKml.Dom.Atom.Link {
                Href = new Uri("http://www.example.com")
            };

            Kml root = new Kml();

            root.AddNamespacePrefix(KmlNamespaces.AtomPrefix, KmlNamespaces.AtomNamespace);
            root.Feature = document;

            Serializer serializer = new Serializer();

            serializer.SerializeRaw(root);

            Assert.That(serializer.Xml, Is.EqualTo(Expected));
        }
Example #27
0
        public void TestEmptyElement()
        {
            const string xml = @"<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://www.opengis.net/kml/2.2'>
  <Document>
    <Snippet/>
    <name>My Document</name>
    <Placemark>
        <name>My Placemark</name>
    </Placemark>
  </Document>
</kml>";

            var parser = new Parser();

            parser.ParseString(xml, true);

            Kml kml = parser.Root as Kml;

            Assert.That(kml, Is.Not.Null);

            Document document = kml.Feature as Document;

            Assert.That(document, Is.Not.Null);
            Assert.That(document.Name, Is.EqualTo("My Document"));

            Placemark placemark = document.Features.FirstOrDefault() as Placemark;

            Assert.That(placemark, Is.Not.Null);
            Assert.That(placemark.Name, Is.EqualTo("My Placemark"));
        }
Example #28
0
 /// <summary>
 /// 鼠标按下事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void mapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
 {
     if (e.button == 1 && !isMouseDown && !isControl)
     {
         //绘制矩形  四个点的位置集中在一个点上
         Kml kml = new Kml();
         kml.Placemark.Name = "arc_rectangle" + Utils.ElementIndex;
         KmlPolygon kmlRectangle = new KmlPolygon();
         kmlRectangle.Description  = "手动绘制的一个矩形";
         kmlRectangle.FillColor    = Color.Yellow;
         kmlRectangle.OutLineColor = Color.Black;
         kmlRectangle.OutLineSize  = 1;
         MapLngLat lnglat = new MapLngLat(e.mapX, e.mapY);
         pointList.Add(lnglat);
         pointList.Add(lnglat);
         pointList.Add(lnglat);
         pointList.Add(lnglat);
         kmlRectangle.PositionList = pointList;
         kml.Placemark.Graph       = kmlRectangle;
         IMFElement element = null;
         layer.AddElement(kml, out element);
         polygonElement = element as IMFPolygon;
         isMouseDown    = true;
         isFinish       = false;
     }
 }
Example #29
0
        public void TestWalkProperties()
        {
            Kml kml = new Kml();
            kml.Feature = new Folder(); // This will not be added to the Children collection

            Assert.That(ElementWalker.Walk(kml).Count(), Is.EqualTo(2));
        }
Example #30
0
        /// <summary>
        /// 创建图元
        /// </summary>
        /// <param name="kml"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public IMFElement CreateElement(Kml kml, ILayer layer)
        {
            KmlPoint pointKml = kml.Placemark.Graph as KmlPoint;

            if (pointKml.Position == null)
            {
                return(null);
            }

            int index = -1;

            //图层
            IGlobeGraphicsLayer graphicsLayer = layer as IGlobeGraphicsLayer;

            //图元
            Point_ArcGlobe pointElement = new Point_ArcGlobe(graphicsLayer, pointKml);

            this.Dosomething((Action) delegate()
            {
                IGlobeGraphicsElementProperties properties = new GlobeGraphicsElementPropertiesClass();
                properties.Rasterize = pointKml.Rasterize;                  //栅格化
                graphicsLayer.AddElement(pointElement, properties, out index);

                pointElement.Index       = index;                           //指定索引
                pointElement.ElementName = kml.Placemark.Name;
            }, true);

            return(pointElement);
        }
Example #31
0
        /// <summary>
        /// Write KML document as binary data directly into response OutputStream.
        /// </summary>
        /// <param name="context">ControllerContext in which execute operates</param>
        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.Clear();
            context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.HttpContext.Response.ContentType =
                IsCompressed ?
                    KMZ_MIME_TYPE :
                    KML_MIME_TYPE;

            Kml kml = new Kml(Document);

            using (var stream =
                IsCompressed ?
                    new MemoryStream(kml.ToKmz()) :
                    new MemoryStream(Encoding.UTF8.GetBytes(kml.ToString())))
            {
                stream.WriteTo(context.HttpContext.Response.OutputStream);
            }
        }
        private void GenerateKMLFromExcel()
        {
            try
            {

                Kml MyKml = new Kml();
                MyKml.GenerateKml();
                MyKml.AddStyle("Jad", "RED", textBoxIconColor.Text, textBoxIconSize.Text, textBoxLabelURL.Text, textBoxLabelSize.Text);
                string description = "";
                for (int i = 0; i < this.MydataGrid.Rows.Count - 1; i++)
                {
                    DataGridViewRow row = this.MydataGrid.Rows[i];

                    float Lon = float.Parse(row.Cells[comboBoxLongitude.Text].Value.ToString()); //make dynamic
                    float Lat = float.Parse(row.Cells[comboBoxLatitude.Text].Value.ToString()); //make dynamic
                    string labelURL = "";
                    description = textBoxDescription.Text.Replace("#date", DateTime.Now.ToShortDateString());
                    foreach (object x in listBox3.Items)
                    {
                        description = description.Replace
                            (x.ToString(), row.Cells[x.ToString().Replace("#", "")].Value.ToString());
                        labelURL = textBoxLabelURL.Text.
                            Replace(x.ToString(), row.Cells[x.ToString().Replace("#", "")].Value.ToString());
                    }

                    //double IconSize = (Persons * (double.Parse(textBoxMaxIconSize.Text))) / MaxPersons;
                    double IconSize = double.Parse(textBoxMaxIconSize.Text);
                    if (IconSize < double.Parse(textBoxMinIconSize.Text)) IconSize = double.Parse(textBoxMinIconSize.Text);
                    IconSize = Math.Round(IconSize, 1);
                    string Location = row.Cells[comboBoxMainItem.Text].Value.ToString(); //Make it dynamic
                    string DateToday = DateTime.Now.ToShortDateString();

                    if (checkBoxDynamicIcon.Checked)
                        MyKml.AddCPoint(Lat, Lon, Location, "Jad", description, textBoxIconColor.Text, IconSize.ToString(), labelURL, textBoxLabelSize.Text, textBoxLabelColor.Text);
                    else
                        MyKml.AddPoint(Lat, Lon, Location, "Jad", description);

                }
                MyKml.SaveKml();

                MessageBox.Show("Done creating KML - Google earth will open now");
                System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["KMLoutputFileName"].ToString() + ".kml");
            }
            catch (Exception ex)
            {
                textBox1.Text = textBox1.Text + " " + ex.Message;
            }
        }