翻譯|使用教程|編輯:李顯亮|2021-01-22 09:50:47.127|閱讀 399 次
概述:KML是Keyhole標記語言的縮寫,它是XML表示法的擴展。它是GIS文件格式,用于顯示地理信息。可以以編程方式創建KML文件,也可以使用C#語言從其中讀取信息。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
KML是Keyhole標記語言的縮寫,它是XML表示法的擴展。它是GIS文件格式,用于顯示地理信息。可以以編程方式創建KML文件,也可以使用C#語言從其中讀取信息。
讓我們探索以下與KML文件格式有關的部分:
Aspose.GIS for .NET API支持使用KML文件以及其他幾種受支持的文件格式。讓我們安裝API來處理基于.NET的應用程序中的矢量文件。
>>你可以點擊這里下載Aspose.GIS最新版測試體驗。
KML文件像XML文件一樣遵循基于標記的結構。您可以使用KML文件來精確定位位置,計劃或跟蹤行程以及許多其他重要情況。您可以使用C#通過以下步驟以編程方式創建KML文件:
以下代碼段是有關如何在C#中以編程方式創建KML文件的基本且簡單的演示:
// Create a layer using (var layer = Drivers.Kml.CreateLayer(dataDir + "Kml_File_out.kml")) { // Initialize feature for geometry and attributes layer.Attributes.Add(new FeatureAttribute("string_data", AttributeDataType.String)); layer.Attributes.Add(new FeatureAttribute("int_data", AttributeDataType.Integer)); layer.Attributes.Add(new FeatureAttribute("bool_data", AttributeDataType.Boolean)); layer.Attributes.Add(new FeatureAttribute("float_data", AttributeDataType.Double)); // Set value of different attributes Feature feature = layer.ConstructFeature(); feature.SetValue("string_data", "string value"); feature.SetValue("int_data", 10); feature.SetValue("bool_data", true); feature.SetValue("float_data", 3.14); feature.Geometry = new LineString(new[] { new Point(0, 0), new Point(1, 1) }); // Add the feature to a specific Layer layer.Add(feature); Feature feature2 = layer.ConstructFeature(); feature2.SetValue("string_data", "string value2"); feature2.SetValue("int_data", 100); feature2.SetValue("bool_data", false); feature2.SetValue("float_data", 3.1415); feature2.Geometry = Geometry.Null; layer.Add(feature2); }
KML文件的基本功能可能包括地標,描述,路徑等。讓我們繼續上面示例中創建的KML文件。您可以按照以下步驟閱讀KML文件的任何功能:
以下代碼段顯示了如何在C#中以編程方式從KML文件中讀取功能:
// Load input KML file with OpenLayer method using (var layer = Drivers.Kml.OpenLayer(dataDir + "Kml_File.kml")) { // Get features’ count int count = layer.Count; // Access a feature at a specific index Feature featureAtIndex1 = layer[0]; Console.WriteLine(featureAtIndex1.GetValue("string_data")); Feature featureAtIndex2 = layer[1]; Console.WriteLine(featureAtIndex2.GetValue("string_data")); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn