We may have Geographic data available in many formats supported by various systems. In certain cases, we may need to export geographic data from ESRI Shapefile (SHP) format to Keyhole Markup Language (KML) format. The Shapefile format is ESRI’s one of the most common geospatial vector data formats used to display geographical information. The KML is an XML-based format, used to share geographic data with non-GIS users. The KML format is used to display geographic data in Google Earth or Google Maps. In this article, we will learn how to convert a shapefile to KML in C#.
This article shall cover the following topics:
C# Shapefile to KML Converter API - Free Download
To convert a shapefile to KML, we will be using the Aspose.GIS for .NET API. It allows exporting shapefile to KML without needing software like ArcGIS, ArcMap, QGIS or Google Earth. The API also allows the rendering of maps, creating, reading, and converting geographic data available in the supported file formats.
The ConversionOptions class of the API provides options for converting data between formats. The SpatialReferenceSystem class provides a list of different spatial reference systems to use in mapping coordinates to places on Earth. We have the VectorLayer class that represents a vector layer in the API. The Convert(string, FileDriver, string, FileDriver, ConversionOptions) method of this class converts a layer to a different format.
PM> Install-Package Aspose.GIS
How to Convert Shapefile to KML in C#
We can easily convert a shapefile to KML using Aspose.GIS for .NET by following the steps given below:
- Assign the Wgs84 spatial reference to the destination layer.
- Load and convert file format from SHP to KML.
Now, let’s see how to perform these steps in C# to convert a shapefile file to a KML format.
Export ShapeFile to KML in C#
Please follow the steps given below to export data from a shapefile to KML:
- Initialize an instance of the ConversionOptions class.
- Set the DestinationSpatialReferenceSystem as Wgs84.
- Finally, call the VectorLayer.Convert() method to convert source shapefile to KML.
The following code sample shows how to convert a shapefile to KML using C#.
Get a Free License
You can get a free temporary license to try the library without evaluation limitations.
In this article, we have learned how to convert a shapefile to KML in C#. We have also seen how to define conversion options programmatically. Besides, you can explore how to work with several other GIS file formats and learn more about Aspose.GIS for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on our forum.