This project has moved. For the latest updates, please go here.

great tool. How would i extract the kml data out of a kmz file and write the data to a kml file.

Aug 18, 2011 at 9:02 AM

this is what i have so far

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using SharpKml.Base;
using SharpKml.Dom;
using SharpKml.Engine;
using Ionic.Zip;
using Ionic.Zlib;

namespace ParseKMLFile
{
    class Program
    {
        static void Main(string[] args)
        {

            String path = "..//NAWAPA.kmz";;       
            String data = "";
     
            kmz = KmzFile.Open(path);

            data = kmz.ReadKml();

        }
    }
}

 

the string data contains the kml data but Im unsure of how to write this to a kml file

Coordinator
Aug 18, 2011 at 3:43 PM

There are a couple of ways you can save the file. If you have a string containing the Kml then you can use the existing .NET framework methods to save the file or, if you want to work with the Kml data as well, you can do something like the following:

using SharpKml.Engine;

class Program
{
    static void Main(string[] args)
    {
        string path = "..//NAWAPA.kmz";
        KmlFile kml;

        // We must close the kmz archive after we've finished with it so wrap it
        // in a using statement so the compiler will call Dispose for us.
        using (var kmz = KmzFile.Open(path))
        {
            kml = KmlFile.LoadFromKmz(kmz);
        }

        // The kml object now contains all the data from the default Kml file
        // in the kmz archive. This could be null if no kml was found in the
        // archive so you might want to check for that here.
        kml.Save("the destination path");
    }
}
Aug 19, 2011 at 2:20 AM

Awesome thanks for the help and the great tool.

 

-Mark