Create Edit KML File

KML is abbreviated for Keyhole Markup Language which is extended from XML notation. It is a GIS file format and is used to display geographical information. You can create KML files programmatically, as well as read information from them using C# language. Let us explore the following sections related to KML file format:

Creating or Reading KML Files – API Installation

Aspose.GIS for .NET API supports working with KML files along with several other supported file formats. Let us install the API to manipulate the vector files in .NET based applications. You need to download the API from New Releases section, or from NuGet gallery with the following installation command:

PM> Install-Package Aspose.GIS

After configuring the API, you are all set to create or manipulate KML files. Now you do not need to worry about minor details because you only need to make simple API calls. Let us move on to further details:

Create KML File Programmatically using C#

KML files follow the tag-based structure like the XML files. You can use KML files to pinpoint locations, planning or tracking your trips and many other important scenarios. You can create KML files programmatically using C# with below steps:

  1. Create a layer
  2. Initialize feature for geometry and attributes
  3. Set value of different attributes
  4. Add the feature to a specific Layer

The following code snippet is a basic and simple demonstration as how to create KML files programmatically in C#:

Read Features from KML files Programmatically using C#

The basic features of a KML file may include Placemarks, Descriptions, Paths, etc. Let us proceed with the KML file that we have created in above example. You can read any feature of a KML file with below steps:

  1. Load input KML file with OpenLayer method
  2. Get features’ count
  3. Access a feature at a specific index
  4. Read features of the KML file

The code snippet below shows how to read features from a KML file programmatically in C#:

Conclusion

In this article, we have explored how to work with KML files. We have learned how to create a KML file or read its features programmatically with the help of C# sample code. Likewise, you can explore how to work with several other GIS file formats. You may visit Product Documentation or write to us at Free Support Forum to discuss any of your concerns. We would love to assist you!

See Also