{{< figure align=center src=“images/Create-Edit-KML-file.png” alt=“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
- Create KML File Programmatically using C#
- Read Features from KML files Programmatically using C#
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. 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, plan trips, or track routes. Follow these steps to create KML files programmatically with C#:
- Create a layer
- Initialize feature for geometry and attributes
- Set values for the attributes
- Add the feature to the layer
The code snippet below demonstrates a basic way to create KML files in C#:
{{< gist aspose-com-gists 1b3c7212ef9fdf07d196eec8c1395f47 “Create-KML-file.cs” >}}
Read Features from KML files Programmatically using C#
A KML file can contain Placemarks, Descriptions, Paths, and more. Using the KML file created above, you can read its features with these steps:
- Load the KML file with the OpenLayer method
- Get the feature count
- Access a feature at a specific index
- Read the feature details
The following snippet shows how to read KML features in C#:
{{< gist aspose-com-gists 1b3c7212ef9fdf07d196eec8c1395f47 “Read-KML-Features.cs” >}}
Conclusion
In this article, we explored how to work with KML files. We learned how to create a KML file and read its features programmatically using C#. You can also apply similar techniques to other GIS file formats. Visit the Product Documentation or post in the Free Support Forum for further assistance.