How to Convert GPX to KMZ in C#

In this step by step tutorial, we’ll show you how to convert GPX to KMZ in C#. This will be achieved by converting GPX to KML format and then converting KML to KMZ format using C# code.

Steps to Convert GPX to KMZ in C#

  1. Install Aspose.GIS for .NET and Aspose.Zip for .NET packages from NuGet.org
  2. Include Aspose.Gis and Aspose.Zip namespaces
  3. Set license for both APIs using SetLicense method
  4. Use VectorLayer class to convert GPX format to KML file type
  5. Create an instance of Archive class to create a Zip file
  6. Add output KML and other related files as Zip entries
  7. Save KML and other files as a single Zip file
  8. Rename the final file as KMZ (KML Zipped format)

The KMZ file format is the zipped format containing not only KML map file but also related files like images, audio, and other formats. So we first need to convert the GPX file to KML and then convert the KML to KMZ map file format.

Code to Convert GPX to KMZ in C#

In this code snippet, after converting GPX to KM format, we’re creating a Zip archive of the KML file along with an image file. This is just for sample purpose, you can add any files which are related to your concerned KML file into a KMZ package.

 English