2016-08-13 245 views
0

我確定這是我正在做的一些愚蠢的事情,但我無法弄清楚。我正在嘗試從頭開始編寫KML。它將位於KMZ內部,帶有一堆地理參考圖片,我不會將它們顯示爲照片疊加層。雖然我無法編寫KML,但我發現文檔太基本,無法合併文件夾。當我暫停程序並調試時,它顯示Kml kml沒有孩子,但功能'文件夾'有42個。然後命名空間沒有顯示出來,也沒有寫入Kml文件。請,任何幫助,你可以給我!使用SharpKml創建KML文件

public void WriteKML_sharp() 
    { 

     Kml kml = new Kml(); 

     kml.AddNamespacePrefix(KmlNamespaces.GX22Prefix, KmlNamespaces.GX22Namespace); 

     Folder folder = new Folder(); 
     kml.Feature = folder; 
     foreach (Picture picture in _process.pictures) 
     { 
      PhotoOverlay photooverlay = new PhotoOverlay(); 

      photooverlay.Name = picture.name + picture.extension; 
      photooverlay.Open = true; 
      photooverlay.Shape = Shape.Rectangle; 

      Icon icon = new Icon(); 
      Uri uri = new Uri(Path.Combine("files", picture.name + picture.extension), UriKind.Relative); 
      icon.Href = uri; 
      photooverlay.Icon = icon; 

      Point point = new Point(); 
      point.Coordinate = new Vector(picture.gpslat, picture.gpslong); 
      //point.Coordinate = new Vector(picture.gpslat, picture.gpslong, picture.gpsalt); 
      point.AltitudeMode = AltitudeMode.RelativeToGround; 
      photooverlay.Location = point; 

      ViewVolume viewvolume = new ViewVolume(); 
      viewvolume.Top = 25; 
      viewvolume.Bottom = -25; 
      viewvolume.Left = 20; 
      viewvolume.Right = -20; 
      photooverlay.View = viewvolume; 

      folder.AddFeature(photooverlay); 
     } 

     KmlFile kmlfile = KmlFile.Create(kml, false); 
     using (var stream = System.IO.File.OpenWrite(_filename)) 
     { 
      kmlfile.Save(stream); 
     } 

    } 

回答

0

我不知道這是否會是原因但你可以嘗試在KML文件中添加文件並指定該文件作爲kml.Feature並添加功能,使用.AddFeature(文件夾),該文件; 它對我來說很有效