在Google Earth 自动生成地理信息 C#

private   void  button1_Click( object  sender, System.EventArgs e)
        
{
            
//作者杨义贤
            XmlDeclaration xmlDec;
            XmlDocument xmlDoc;
//            XmlElement xmlElement;
            XmlElement xmlElementKML;
            XmlElement xmlElementDocument;
            XmlElement xmlElementStyle;
            XmlElement xmlElementScale;
            XmlElement xmlElementIcon;
            XmlElement xmlElementHref;
            XmlElement xmlElementStyleMap;
            XmlElement xmlElementPair;
            XmlElement xmlElementKey;
            XmlElement xmlElementStyleURL;
            XmlElement xmlElementFolder;
            XmlElement xmlElementPlaceMark;
            XmlElement xmlElementTessellate;
            XmlElement xmlElementCoordinates;
            XmlElement xmlElementPoint;
            XmlElement xmlElementName;
            XmlElement xmlElementDescription;
            XmlElement xmlElementLineString;
            XmlElement xmlElementAddress;
            XmlElement xmlElementLookAt;

            XmlElement xmlElementLongitude;
            XmlElement xmlElementLatitude;
            XmlElement xmlElementAltitude;
            XmlElement xmlElementRange;
            XmlElement xmlElementTilt;
            XmlElement xmlElementHeading;

//            XmlElement ele;
            XmlAttribute xmlAttribute;

            
//初始化XmlDocument
            xmlDoc = new XmlDocument();

            
///添加说明
            xmlDec = xmlDoc.CreateXmlDeclaration("1.0","UTF-8","");
            xmlDoc.AppendChild(xmlDec);
            xmlDec 
= null;

            
//添加KML
            xmlElementKML = xmlDoc.CreateElement("kml");

            xmlAttribute 
= xmlDoc.CreateAttribute("xmlns");
            xmlAttribute.Value 
= "http://earth.google.com/kml/2.1";
            xmlElementKML.Attributes.Append(xmlAttribute);
            xmlAttribute 
= null;

            xmlDoc.AppendChild(xmlElementKML);

            
//添加Document节点
            xmlElementDocument = xmlDoc.CreateElement("Document");
            xmlElementKML.AppendChild(xmlElementDocument);

            
//创建Name
            xmlElementName = xmlDoc.CreateElement("name");
            xmlElementName.InnerText 
= "Document Name";
            xmlElementDocument.AppendChild(xmlElementName);

            
//创建Style
            xmlElementStyle = xmlDoc.CreateElement("Style");
            xmlElementDocument.AppendChild(xmlElementStyle);

            
//创建StyleID
            xmlAttribute = xmlDoc.CreateAttribute("id");
            xmlAttribute.Value 
= "styleid1";
            xmlElementStyle.Attributes.Append(xmlAttribute);

            
//创建scale
            xmlElementScale = xmlDoc.CreateElement("scale");
            xmlElementScale.InnerText 
= "1.0";
            xmlElementStyle.AppendChild(xmlElementScale);

            
//创建Icon
            xmlElementIcon = xmlDoc.CreateElement("Icon");
            xmlElementStyle.AppendChild(xmlElementIcon);

            
//添加href
            xmlElementHref = xmlDoc.CreateElement("href");
            xmlElementHref.InnerText 
= "http://192.168.0.4/fm/images/text.png";
            xmlElementIcon.AppendChild(xmlElementHref);

            
//创建Style
            xmlElementStyle = xmlDoc.CreateElement("Style");
            xmlElementDocument.AppendChild(xmlElementStyle);

            
//StyleID
            xmlAttribute = xmlDoc.CreateAttribute("id");
            xmlAttribute.Value 
= "styleid2";
            xmlElementStyle.Attributes.Append(xmlAttribute);

            
//创建scale
            xmlElementScale = xmlDoc.CreateElement("scale");
            xmlElementScale.InnerText 
= "1.1";
            xmlElementStyle.AppendChild(xmlElementScale);

            
//创建Icon
            xmlElementIcon = xmlDoc.CreateElement("Icon");
            xmlElementStyle.AppendChild(xmlElementIcon);

            
//添加href
            xmlElementHref = xmlDoc.CreateElement("href");
            xmlElementHref.InnerText 
= "http://192.168.0.4/fm/images/text.png";
            xmlElementIcon.AppendChild(xmlElementHref);

            
//创建StyleMap
            xmlElementStyleMap = xmlDoc.CreateElement("StyleMap");
            xmlElementDocument.AppendChild(xmlElementStyleMap);

            
//添加Pair
            xmlElementPair = xmlDoc.CreateElement("Pair");
            xmlElementStyleMap.AppendChild(xmlElementPair);

            
//添加key
            xmlElementKey = xmlDoc.CreateElement("key");
            xmlElementKey.InnerText 
= "normal";
            xmlElementPair.AppendChild(xmlElementKey);

            
//添加styleurl
            xmlElementStyleURL = xmlDoc.CreateElement("styleUrl");
            xmlElementStyleURL.InnerText 
= "styleid1";
            xmlElementPair.AppendChild(xmlElementStyleURL);

            
//添加Pair
            xmlElementPair = xmlDoc.CreateElement("Pair");
            xmlElementStyleMap.AppendChild(xmlElementPair);

            
//添加key
            xmlElementKey = xmlDoc.CreateElement("key");
            xmlElementKey.InnerText 
= "highlight";
            xmlElementPair.AppendChild(xmlElementKey);

            
//添加styleurl
            xmlElementStyleURL = xmlDoc.CreateElement("styleUrl");
            xmlElementStyleURL.InnerText 
= "styleid1";
            xmlElementPair.AppendChild(xmlElementStyleURL);

            
//创建Folder
            xmlElementFolder = xmlDoc.CreateElement("Folder");
            
//xmlElementFolder.InnerText = "Folder";
            xmlElementDocument.AppendChild(xmlElementFolder);

            
//创建Placemark
            xmlElementPlaceMark = xmlDoc.CreateElement("Placemark");
            xmlElementFolder.AppendChild(xmlElementPlaceMark);

            
//创建Name
            xmlElementName = xmlDoc.CreateElement("name");
            xmlElementName.InnerText 
= "Point Name";
            xmlElementPlaceMark.AppendChild(xmlElementName);

            
//创建LookAt
            xmlElementLookAt = xmlDoc.CreateElement("LookAt");
            xmlElementPlaceMark.AppendChild(xmlElementLookAt);

            
//经度
            xmlElementLongitude = xmlDoc.CreateElement("longitude");
            xmlElementLongitude.InnerText 
= "117.00000000";
            xmlElementLookAt.AppendChild(xmlElementLongitude);

            
//纬度
            xmlElementLatitude = xmlDoc.CreateElement("latitude");
            xmlElementLatitude.InnerText 
= "39.00000000";
            xmlElementLookAt.AppendChild(xmlElementLatitude);

            
//高度
            xmlElementAltitude = xmlDoc.CreateElement("altitude");
            xmlElementAltitude.InnerText 
= "0";
            xmlElementLookAt.AppendChild(xmlElementAltitude);

            
//range
            xmlElementRange = xmlDoc.CreateElement("range");
            xmlElementRange.InnerText 
= "0";
            xmlElementLookAt.AppendChild(xmlElementRange);

            
//tilt
            xmlElementTilt = xmlDoc.CreateElement("tilt");
            xmlElementTilt.InnerText 
= "0";
            xmlElementLookAt.AppendChild(xmlElementTilt);

            
//heading
            xmlElementHeading = xmlDoc.CreateElement("heading");
            xmlElementHeading.InnerText 
= "0";
            xmlElementLookAt.AppendChild(xmlElementHeading);

            
//创建Address
            xmlElementAddress = xmlDoc.CreateElement("Address");
            xmlElementAddress.InnerText 
= "Point Address";
            xmlElementPlaceMark.AppendChild(xmlElementAddress);

            
//创建styleUrl
            xmlElementStyleURL = xmlDoc.CreateElement("styleUrl");
            xmlElementStyleURL.InnerText 
= "Point Style";
            xmlElementPlaceMark.AppendChild(xmlElementStyleURL);

            
//创建Point
            xmlElementPoint = xmlDoc.CreateElement("Point");
            xmlElementPlaceMark.AppendChild(xmlElementPoint);

            
//创建coordinates
            xmlElementCoordinates = xmlDoc.CreateElement("coordinates");
            xmlElementCoordinates.InnerText 
= "117.1456505702926,38.63631914232371,0";
            xmlElementPoint.AppendChild(xmlElementCoordinates);

            
//创建Placemark
            xmlElementPlaceMark = xmlDoc.CreateElement("Placemark");
            xmlElementFolder.AppendChild(xmlElementPlaceMark);

            
//创建Name
            xmlElementName = xmlDoc.CreateElement("name");
            xmlElementName.InnerText 
= "Line String Name";
            xmlElementPlaceMark.AppendChild(xmlElementName);

            
//创建Description
            xmlElementDescription = xmlDoc.CreateElement("description");
            xmlElementDescription.InnerText 
= "Line String Description";
            xmlElementPlaceMark.AppendChild(xmlElementDescription);

            
//创建styleUrl
            xmlElementStyleURL = xmlDoc.CreateElement("styleUrl");
            xmlElementStyleURL.InnerText 
= "Line String Style URL";
            xmlElementPlaceMark.AppendChild(xmlElementStyleURL);

            
//创建LineString
            xmlElementLineString = xmlDoc.CreateElement("LineString");
            xmlElementPlaceMark.AppendChild(xmlElementLineString);

            
//创建Tessellate
            xmlElementTessellate = xmlDoc.CreateElement("tessellate");
            xmlElementTessellate.InnerText 
= "1";
            xmlElementLineString.AppendChild(xmlElementTessellate);

            
//创建coordinates
            xmlElementCoordinates = xmlDoc.CreateElement("coordinates");
            xmlElementCoordinates.InnerText 
= "117.1456505702926,38.63631914232371,0 117.1456606471506,38.63592706733432,0";
            xmlElementLineString.AppendChild(xmlElementCoordinates);

//            xmlElement = xmlDoc.CreateElement("kml");
//
//            xmlDoc.AppendChild(xmlElement);

//            ele = doc.CreateElement("Book");
//
////            ele.Value = "C#";
//
//            element.AppendChild(ele);
//
//            xmlAttribute = doc.CreateAttribute("UserName");
//
//            attribute.Value = "Jihui";
//
//            ele.Attributes.Append(attribute);

            
try
            
{
                xmlDoc.Save(
"d:/doc.kml");

                C1ZipFile c1Zip;
//Component one 控件自带的压缩控件
                c1Zip = new C1ZipFile();

                c1Zip.Create(
"d:/MyGE.kmz");

                c1Zip.Entries.Add(
"d:/doc.kml");
            }

            
catch(Exception ex)
            
{
                
string strMessage;

                strMessage 
= ex.Message;
            }

            
finally
            
{
                xmlElementKML 
= null;
                xmlElementDocument 
= null;
                xmlElementFolder 
= null;
                xmlElementPlaceMark 
= null;
                xmlElementPoint 
= null;
                xmlElementName 
= null;
                xmlElementDescription 
= null;
                xmlElementLineString 
= null;
            }

        }
 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值