C#'da GPX'i KMZ'ye Dönüştürme

Bu adım adım öğreticide, C# ile GPX’i KMZ’ye nasıl dönüştüreceğinizi göstereceğiz. Bu, GPX biçimini KML biçimine dönüştürerek ve ardından C# kodunu kullanarak KML’yi KMZ biçimine dönüştürerek elde edilecektir.

C# ile GPX’i KMZ’ye Dönüştürme Adımları

  1. NuGet.org’dan Aspose.GIS for .NET ve Aspose.Zip for .NET paketlerini yükleyin
  2. Aspose.Gis ve Aspose.Zip ad alanlarını dahil et
  3. SetLicense yöntemini kullanarak her iki API için lisans ayarlayın
  4. GPX biçimini KML dosya türüne dönüştürmek için VectorLayer class kullanın
  5. Zip dosyası oluşturmak için bir Archive class örneği oluşturun
  6. Çıktı KML’sini ve diğer ilgili dosyaları Zip girişleri olarak ekleyin
  7. KML’yi ve diğer dosyaları tek bir Zip dosyası olarak kaydedin
  8. Son dosyayı KMZ (KML Zipped formatı) olarak yeniden adlandırın

KMZ dosya formatı, yalnızca KML harita dosyasını değil aynı zamanda resimler, ses ve diğer formatlar gibi ilgili dosyaları da içeren sıkıştırılmış formattır. Bu yüzden önce GPX file to KML‘i dönüştürmemiz ve ardından KML’yi KMZ harita dosya biçimine dönüştürmemiz gerekiyor.

C#‘da GPX’i KMZ’ye Dönüştürme Kodu

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");
}
}
}

Bu kod parçacığında, GPX’i KM formatına dönüştürdükten sonra, bir resim dosyasıyla birlikte KML dosyasının bir Zip arşivini oluşturuyoruz. Bu sadece örnek amaçlıdır, ilgili KML dosyanızla ilgili herhangi bir dosyayı bir KMZ paketine ekleyebilirsiniz.

 Türkçe