Այս քայլ առ քայլ ձեռնարկում մենք ձեզ ցույց կտանք, թե ինչպես փոխարկել GPX-ը KMZ-ի C#-ով: Դրան կհաջողվի փոխարկել GPX-ը KML ձևաչափի և այնուհետև փոխարկելով KML-ը KMZ ձևաչափի` օգտագործելով C# կոդը:
C#-ով GPX-ը KMZ-ին փոխարկելու քայլեր
- Տեղադրեք Aspose.GIS for .NET և Aspose.Zip for .NET փաթեթները NuGet.org-ից
- Ներառեք Aspose.Gis և Aspose.Zip անունների տարածքները
- Սահմանեք լիցենզիա երկու API-ների համար՝ օգտագործելով SetLicense մեթոդը
- Օգտագործեք VectorLayer class՝ GPX ձևաչափը KML ֆայլի տեսակի փոխարկելու համար
- Ստեղծեք Archive class-ի օրինակ Zip ֆայլ ստեղծելու համար
- Ավելացնել ելքային KML և այլ հարակից ֆայլեր որպես Zip գրառումներ
- Պահպանեք KML և այլ ֆայլեր որպես մեկ Zip ֆայլ
- Վերանվանել վերջնական ֆայլը որպես KMZ (KML Zipped ձևաչափ)
KMZ ֆայլի ձևաչափը սեղմված ձևաչափն է, որը պարունակում է ոչ միայն KML քարտեզի ֆայլ, այլև հարակից ֆայլեր, ինչպիսիք են պատկերները, աուդիո և այլ ձևաչափեր: Այսպիսով, մենք նախ պետք է փոխարկենք GPX file to KML-ը, այնուհետև փոխարկենք KML-ը KMZ քարտեզի ֆայլի ձևաչափի:
Կոդ՝ GPX-ը KMZ-ի C#-ով փոխարկելու համար
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"); | |
} | |
} | |
} |
Այս կոդի հատվածում GPX-ը KM ձևաչափի փոխարկելուց հետո մենք ստեղծում ենք KML ֆայլի Zip արխիվ՝ պատկերային ֆայլի հետ միասին: Սա պարզապես նմուշի նպատակով է, դուք կարող եք ավելացնել ցանկացած ֆայլ, որը կապված է ձեր KML ֆայլի հետ կապված KMZ փաթեթի մեջ: