Last active
July 29, 2021 13:35
Convert GPX File to KMZ File Format in C#. To better understand this code, checkout our how to tutorial: https://kb.aspose.com/gis/net/how-to-convert-gpx-to-kmz-in-c-sharp/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
//Add reference to Aspose.GIS for .NET & Aspose.Zip for .NET APIs | |
//Use following namespaces to convert GPX file format to KMZ format | |
using Aspose.Gis; | |
using Aspose.Zip; | |
namespace ConvertGPXToKMZFileFormat | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//Set Aspose license before converting GPX file to KMZ format | |
//using Aspose.GIS for .NET | |
Aspose.Gis.License AsposeGISLicense = new Aspose.Gis.License(); | |
AsposeGISLicense.SetLicense(@"c:\asposelicense\license.lic"); | |
//Set Aspose license to use Aspose.Zip to zip KML file | |
Aspose.Zip.License AsposeZipLicense = new Aspose.Zip.License(); | |
AsposeZipLicense.SetLicense(@"c:\asposelicense\license.lic"); | |
//Convert GPX file to KML File | |
VectorLayer.Convert("InputGPXFile.gpx", Drivers.Gpx, "OutputKMLFile.kml", Drivers.Kml); | |
//Create Archive class instance | |
Archive ZipArchive = new Archive(); | |
//Create entry for each file in the zip archive | |
ZipArchive.CreateEntry("OutputKMLFile.kml", "OutputKMLFile.kml"); | |
ZipArchive.CreateEntry("ImageRelatedToKMLFile.png", "ImageRelatedToKMLFile.png"); | |
//Save output Zip file | |
ZipArchive.Save("KMLandImageFilesCombined.zip"); | |
//Rename Zip file to KMZ | |
System.IO.File.Move("KMLandImageFilesCombined.zip", "FinalOutputKMZFile.kmz"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment