[英]Using SharpKml to create a KML file
我確定這是我做的愚蠢的事情,但我無法弄清楚。 我正在嘗試從頭開始編寫KML。 它將位於KMZ中,其中包含一堆地理參考圖片,這些圖片不會顯示為照片疊加層。 雖然我無法編寫KML,但我發現文檔太基礎了,無法合並Folder。 當我暫停程序並調試時,它顯示Kml kml沒有子級,但是功能“文件夾”有42個。然后,名稱空間沒有顯示出來,也沒有在寫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);
}
}
我不確定這是否是原因,但是您可以嘗試在KML文件中添加文檔,並將該文檔分配為kml.Feature,然后使用.AddFeature(folder);將功能添加到此文檔中。 這樣對我有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.