How to Convert KML to GPX in C#

This short article guides on how to convert KML to GPX in C#. It provides the details about setting the development environment to perform the conversion, a list of minimal tasks to be done in the program, and a runnable sample code for understanding the KML to GPX file conversion in C#. You will also learn different options to customize the output GPX file.

Steps to Convert KML to GPX File in C#

  1. Set the IDE to use Aspose.GIS for .NET to convert KML to GPS
  2. Instantiate the ConversionOptions object for setting the spatial reference
  3. Check the support for the Wgs84 spatial reference in the destination layer
  4. Set the spatial reference if support is available
  5. Call the Convert() method to transform GPX to KML

These steps describe the process to develop a KML to GPX file converter in C#. The process is initiated by declaring an object of ConversionOptions from the Aspose.Gis namespace followed by testing the support for the target spatial reference. If support is available, set the destination SpatialReferenceSystem value to Wgs84 and call the Convert() method to transform the format.

Code to Convert KML File to GPX in C#

The above code demonstrates the process to convert KML to GPX in C#. The ConversionOptions class object is used for setting the destination spatial reference system by using the SpatialReferenceSystem enumerator. The Convert() method in the VectorLayer class is used to convert the source KML file to GPX with the specified settings, however, you may set a custom converter for the attributes, the DestinationDriverOptions value for the destination layer, and also the SourceDriverOptions for the source layer if required.

This article has taught us to change the source KML file to a GPX file. If you want to learn the process to create a shapefile, refer to the article on how to create a shapefile in C#.

 English