2016-08-17 1 views
1

디렉토리에 생성중인 kml 파일이 있습니다.KML 파일에서 KMZ 파일 만들기 C에서 프로그래밍 방식으로

C#에서 프로그래밍 방식으로 모든 파일을 kmz 파일로 그룹화하는 방법이 있는지 궁금합니다. Google 어스에 이름과 설명이 표시됩니다.

감사와 안부,

private static void combineAllKMLFilesULHR(String dirPath) 
{ 
    string kmzPath = "outputULHR.kmz"; 

    string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 
    string rootKml = appPath + @"\" + dirPath + @"\doc.kml"; 
    Console.WriteLine(appPath + @"\"+ dirPath); 
    String[] filepaths = Directory.GetFiles(appPath + @"\" + dirPath); 

    using (ZipArchive archive = ZipFile.Open(kmzPath, ZipArchiveMode.Create)) 
    { 
     archive.CreateEntryFromFile(rootKml, "doc.kml"); 
     foreach (String file in filepaths) 
     { 
      Console.WriteLine(file); 
      if(!file.Equals(rootKml)) 
       archive.CreateEntryFromFile(file, Path.GetFileName(file)); 
     } 
    } 
} 

답변

1

KMZ는 우편 아카이브 파일이기 때문에, 당신은 그것을 생성하는 ZipArchive 클래스를 사용할 수 있습니다.

string kmzPath = "output.kmz"; 
string rootKml = "doc.kml"; 
string referencedKml = "someother.kml"; 

using (ZipArchive archive = ZipFile.Open(kmzPath, ZipArchiveMode.Create)) 
{ 
    archive.CreateEntryFromFile(rootKml, "doc.kml"); 
    archive.CreateEntryFromFile(referencedKml, "someother.kml"); 
} 

단지 documentation에서,으로 doc.kml 같은 기본 KML 이름을 기억

넣어 기본 KML 파일 (으로 doc.kml, 또는 에게 그것을주고 원하는 이름을)를이 폴더 내의 최상위 레벨에 배치하십시오. 하나의 .kml 파일 만 포함하십시오. (Google 어스가 KMZ 파일을 열면이 목록의 첫 번째 .kml 파일 인 을 찾고 파일을 검색합니다. 이후의 모든 .kml 파일은 아카이브에서 무시됩니다. 아카이브에 .kml이 여러 개 포함되어있는 경우 파일, 당신은 하나가 먼저 발견 될 확신 할 수 없다, 그래서 당신은 하나의 포함 이 필요합니다.) 알베르토

+0

감사합니다. kmz 파일이 생성되는 동안 doc.kml 파일의 내용 만 표시됩니다. 또한 보관하려는 많은 kml 파일이있을 때도 작동합니다. 내가 사용하고있는 방법으로 원본 게시물을 업데이트했습니다. – nader

관련 문제