我已成功创建名为kml
的{{1}}文件,现在,当您使用gis.kml
将KML转换为KMZ时,我看到了一个边际尺寸更改。所以我在想如何转换{ {1}}到{#1}}在c#.I中有代码将任何文件转换为.zip,但这不起作用
答案 0 :(得分:2)
您可以阅读文件' gis.kml'并将其内容添加到KMZ文件,或者您可以以编程方式创建KML元素并转换为字节数组以写入KMZ流。此解决方案使用CSharpZipLib创建KMZ文件。
以下是创建KMZ文件的C#代码片段:
using (FileStream fileStream = File.Create(ZipFilePath)) // Zip File Path (String Type)
{
using (ZipOutputStream zipOutputStream = new ZipOutputStream(fileStream))
{
// following line must be present for KMZ file to work in Google Earth
zipOutputStream.UseZip64 = UseZip64.Off;
// now normally create the zip file as you normally would
// add root KML as first entry
ZipEntry zipEntry = new ZipEntry("doc.kml");
zipOutputStream.PutNextEntry(zipEntry);
//build you binary array from FileSystem or from memory...
zipOutputStream.write(System.IO.File.ReadAllBytes("gis.kml"));
zipOutputStream.CloseEntry();
// next add referenced file entries (e.g. icons, etc.)
// ...
//don't forget to clean your resources and finish the outputStream
zipOutputStream.Finish();
zipOutputStream.Close();
}
}
还可以使用ZipArchive类创建KMZ文件。
答案 1 :(得分:0)
压缩文件,然后将扩展名更改为KMZ